mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-11 17:14:28 +05:00
fix int(port)
This commit is contained in:
@@ -20,7 +20,7 @@ from homeassistant.helpers.template import Template
|
|||||||
from .const import EVENT_BINARY_SENSOR, DOMAIN, CONF_CUSTOM, CONF_SKIP, CONF_INVERT, CONF_RESPONSE_TEMPLATE
|
from .const import EVENT_BINARY_SENSOR, DOMAIN, CONF_CUSTOM, CONF_SKIP, CONF_INVERT, CONF_RESPONSE_TEMPLATE
|
||||||
from .entities import MegaPushEntity
|
from .entities import MegaPushEntity
|
||||||
from .hub import MegaD
|
from .hub import MegaD
|
||||||
|
from .tools import int_ignore
|
||||||
|
|
||||||
lg = logging.getLogger(__name__)
|
lg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
devices = []
|
devices = []
|
||||||
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
||||||
for port, cfg in config_entry.data.get('binary_sensor', {}).items():
|
for port, cfg in config_entry.data.get('binary_sensor', {}).items():
|
||||||
port = int(port)
|
port = int_ignore(port)
|
||||||
c = customize.get(mid, {}).get(port, {})
|
c = customize.get(mid, {}).get(port, {})
|
||||||
if c.get(CONF_SKIP, False):
|
if c.get(CONF_SKIP, False):
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .entities import set_events_off, BaseMegaEntity, MegaOutPort
|
from .entities import set_events_off, BaseMegaEntity, MegaOutPort
|
||||||
from .exceptions import CannotConnect, NoPort
|
from .exceptions import CannotConnect, NoPort
|
||||||
from .tools import make_ints
|
from .tools import make_ints, int_ignore
|
||||||
|
|
||||||
TEMP_PATT = re.compile(r'temp:([01234567890\.]+)')
|
TEMP_PATT = re.compile(r'temp:([01234567890\.]+)')
|
||||||
HUM_PATT = re.compile(r'hum:([01234567890\.]+)')
|
HUM_PATT = re.compile(r'hum:([01234567890\.]+)')
|
||||||
@@ -394,7 +394,7 @@ class MegaD:
|
|||||||
if port == 'cmd':
|
if port == 'cmd':
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
port = int(port)
|
port = int_ignore(port)
|
||||||
except:
|
except:
|
||||||
self.lg.warning('can not process %s', msg)
|
self.lg.warning('can not process %s', msg)
|
||||||
return
|
return
|
||||||
@@ -423,7 +423,7 @@ class MegaD:
|
|||||||
asyncio.run_coroutine_threadsafe(self._notify(port, value), self.loop)
|
asyncio.run_coroutine_threadsafe(self._notify(port, value), self.loop)
|
||||||
|
|
||||||
def subscribe(self, port, callback):
|
def subscribe(self, port, callback):
|
||||||
port = int(port)
|
port = int_ignore(port)
|
||||||
self.lg.debug(
|
self.lg.debug(
|
||||||
f'subscribe %s %s', port, callback
|
f'subscribe %s %s', port, callback
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ from .const import (
|
|||||||
CONF_CUSTOM,
|
CONF_CUSTOM,
|
||||||
CONF_SKIP,
|
CONF_SKIP,
|
||||||
)
|
)
|
||||||
|
from .tools import int_ignore
|
||||||
|
|
||||||
lg = logging.getLogger(__name__)
|
lg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
devices = []
|
devices = []
|
||||||
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
||||||
for port, cfg in config_entry.data.get('light', {}).items():
|
for port, cfg in config_entry.data.get('light', {}).items():
|
||||||
port = int(port)
|
port = int_ignore(port)
|
||||||
c = customize.get(mid, {}).get(port, {})
|
c = customize.get(mid, {}).get(port, {})
|
||||||
if c.get(CONF_SKIP, False) or c.get(CONF_DOMAIN, 'light') != 'light':
|
if c.get(CONF_SKIP, False) or c.get(CONF_DOMAIN, 'light') != 'light':
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ from .const import CONF_KEY, TEMP, HUM, W1, W1BUS, CONF_CONV_TEMPLATE
|
|||||||
from .hub import MegaD
|
from .hub import MegaD
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from .tools import int_ignore
|
||||||
|
|
||||||
lg = logging.getLogger(__name__)
|
lg = logging.getLogger(__name__)
|
||||||
TEMP_PATT = re.compile(r'temp:([01234567890\.]+)')
|
TEMP_PATT = re.compile(r'temp:([01234567890\.]+)')
|
||||||
HUM_PATT = re.compile(r'hum:([01234567890\.]+)')
|
HUM_PATT = re.compile(r'hum:([01234567890\.]+)')
|
||||||
@@ -81,7 +83,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
hub: MegaD = hass.data['mega'][mid]
|
hub: MegaD = hass.data['mega'][mid]
|
||||||
devices = []
|
devices = []
|
||||||
for port, cfg in config_entry.data.get('sensor', {}).items():
|
for port, cfg in config_entry.data.get('sensor', {}).items():
|
||||||
port = int(port)
|
port = int_ignore(port)
|
||||||
for data in cfg:
|
for data in cfg:
|
||||||
hub.lg.debug(f'add sensor on port %s with data %s', port, data)
|
hub.lg.debug(f'add sensor on port %s with data %s', port, data)
|
||||||
sensor = Mega1WSensor(
|
sensor = Mega1WSensor(
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from . import hub as h
|
from . import hub as h
|
||||||
from .entities import MegaOutPort
|
from .entities import MegaOutPort
|
||||||
from .const import CONF_DIMMER, CONF_SWITCH, DOMAIN, CONF_CUSTOM, CONF_SKIP
|
from .const import CONF_DIMMER, CONF_SWITCH, DOMAIN, CONF_CUSTOM, CONF_SKIP
|
||||||
|
from .tools import int_ignore
|
||||||
|
|
||||||
_LOGGER = lg = logging.getLogger(__name__)
|
_LOGGER = lg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
|
|
||||||
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
||||||
for port, cfg in config_entry.data.get('light', {}).items():
|
for port, cfg in config_entry.data.get('light', {}).items():
|
||||||
port = int(port)
|
port = int_ignore(port)
|
||||||
c = customize.get(mid, {}).get(port, {})
|
c = customize.get(mid, {}).get(port, {})
|
||||||
if c.get(CONF_SKIP, False) or c.get(CONF_DOMAIN, 'light') != 'switch':
|
if c.get(CONF_SKIP, False) or c.get(CONF_DOMAIN, 'light') != 'switch':
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -10,4 +10,11 @@ def make_ints(d: dict):
|
|||||||
if 'm' not in d:
|
if 'm' not in d:
|
||||||
d['m'] = 0
|
d['m'] = 0
|
||||||
if 'click' not in d:
|
if 'click' not in d:
|
||||||
d['click'] = 0
|
d['click'] = 0
|
||||||
|
|
||||||
|
|
||||||
|
def int_ignore(x):
|
||||||
|
try:
|
||||||
|
return int(x)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return x
|
||||||
Reference in New Issue
Block a user