mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 17:44:28 +05:00
Compare commits
11 Commits
v1.0.11b0
...
v1.0.10b14
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
633d5e67bd | ||
|
|
79e3f33345 | ||
|
|
74235a39ad | ||
|
|
61bcbbd103 | ||
|
|
6411e6e5f9 | ||
|
|
2020a840a8 | ||
|
|
f6c2cd025e | ||
|
|
ab599cd59d | ||
|
|
a349cbd4a4 | ||
|
|
bd1ba0379f | ||
|
|
70016dd69d |
@@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 1.0.11b0
|
current_version = 1.0.10b14
|
||||||
parse = (?P<major>\d+)(\.(?P<minor>\d+))(\.(?P<patch>\d+))(?P<release>[bf]*)(?P<build>\d*)
|
parse = (?P<major>\d+)(\.(?P<minor>\d+))(\.(?P<patch>\d+))(?P<release>[bf]*)(?P<build>\d*)
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
|
|||||||
@@ -104,10 +104,11 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
{
|
{
|
||||||
DOMAIN: {
|
DOMAIN: {
|
||||||
vol.Optional(CONF_ALLOW_HOSTS): [str],
|
vol.Optional(CONF_ALLOW_HOSTS): [str],
|
||||||
vol.Optional('entities'): vol.Any(
|
vol.Optional('entities'): {
|
||||||
|
vol.Optional(str): vol.Any(
|
||||||
CUSTOMIZE_PORT,
|
CUSTOMIZE_PORT,
|
||||||
CUSTOMIZE_DS2413
|
CUSTOMIZE_DS2413
|
||||||
),
|
)},
|
||||||
vol.Optional(vol.Any(str, int), description='id меги из веб-интерфейса'): {
|
vol.Optional(vol.Any(str, int), description='id меги из веб-интерфейса'): {
|
||||||
vol.Optional(CONF_FORCE_D, description='Принудительно слать d после срабатывания входа', default=False): bool,
|
vol.Optional(CONF_FORCE_D, description='Принудительно слать d после срабатывания входа', default=False): bool,
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
|||||||
smooth=None,
|
smooth=None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
super().__init__(mega.updater)
|
|
||||||
self._smooth = smooth
|
self._smooth = smooth
|
||||||
self.http_cmd = http_cmd
|
self.http_cmd = http_cmd
|
||||||
self._state: State = None
|
self._state: State = None
|
||||||
@@ -85,6 +84,8 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
|||||||
self._can_smooth_hard = None
|
self._can_smooth_hard = None
|
||||||
if self.http_cmd == 'ds2413':
|
if self.http_cmd == 'ds2413':
|
||||||
self.mega.ds2413_ports |= {self.port}
|
self.mega.ds2413_ports |= {self.port}
|
||||||
|
super().__init__(coordinator=mega.updater)
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_ws(self):
|
def is_ws(self):
|
||||||
@@ -126,10 +127,14 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
|||||||
def customize(self):
|
def customize(self):
|
||||||
if self._customize is not None:
|
if self._customize is not None:
|
||||||
return self._customize
|
return self._customize
|
||||||
if self.hass is None:
|
if self.hass is None or self.entity_id is None:
|
||||||
return {}
|
return {}
|
||||||
if self._customize is None:
|
if self._customize is None:
|
||||||
c_entity_id = self.hass.data.get(DOMAIN, {}).get(self.entity_id, {})
|
|
||||||
|
c_entity_id = self.hass.data.get(DOMAIN, {}).get(CONF_CUSTOM).get('entities', {}).get(self.entity_id, {})
|
||||||
|
self.lg.debug(
|
||||||
|
'customize %s with %s', self.entity_id, c_entity_id
|
||||||
|
)
|
||||||
c = self.hass.data.get(DOMAIN, {}).get(CONF_CUSTOM) or {}
|
c = self.hass.data.get(DOMAIN, {}).get(CONF_CUSTOM) or {}
|
||||||
c = c.get(self._mega_id) or {}
|
c = c.get(self._mega_id) or {}
|
||||||
c = c.get(self.port) or {}
|
c = c.get(self.port) or {}
|
||||||
@@ -168,9 +173,9 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def lg(self) -> logging.Logger:
|
def lg(self) -> logging.Logger:
|
||||||
if self._lg is None:
|
# if self._lg is None:
|
||||||
self._lg = self.mega.lg.getChild(self._name or self.unique_id)
|
# self._lg = self.mega.lg.getChild(self._name or self.unique_id)
|
||||||
return self._lg
|
return _LOGGER
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
|||||||
@@ -310,8 +310,8 @@ class MegaD:
|
|||||||
return ret
|
return ret
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
self.lg.warning(f'timeout while requesting {url}')
|
self.lg.warning(f'timeout while requesting {url}')
|
||||||
raise
|
# raise
|
||||||
# await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
raise asyncio.TimeoutError('after 3 tries')
|
raise asyncio.TimeoutError('after 3 tries')
|
||||||
|
|
||||||
async def save(self):
|
async def save(self):
|
||||||
@@ -427,7 +427,7 @@ class MegaD:
|
|||||||
def subscribe(self, port, callback):
|
def subscribe(self, port, callback):
|
||||||
port = int_ignore(port)
|
port = int_ignore(port)
|
||||||
self.lg.debug(
|
self.lg.debug(
|
||||||
f'subscribe %s %s', port, callback
|
f'subscribe %s %s', port, str(callback)
|
||||||
)
|
)
|
||||||
self.http.callbacks[self.id][port].append(callback)
|
self.http.callbacks[self.id][port].append(callback)
|
||||||
|
|
||||||
|
|||||||
@@ -15,5 +15,5 @@
|
|||||||
"@andvikt"
|
"@andvikt"
|
||||||
],
|
],
|
||||||
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
|
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
|
||||||
"version": "v1.0.11b0"
|
"version": "v1.0.10b14"
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
hub.skip_ports |= {port}
|
hub.skip_ports |= {port}
|
||||||
continue
|
continue
|
||||||
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, constructor: %s', port, data, _constructors[tp])
|
||||||
sensor = _constructors[tp](
|
sensor = _constructors[tp](
|
||||||
mega=hub,
|
mega=hub,
|
||||||
port=port,
|
port=port,
|
||||||
@@ -111,11 +111,17 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
class FilterBadValues(MegaPushEntity):
|
class FilterBadValues(MegaPushEntity):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self._prev_value = None
|
self._prev_value = None
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def filter_value(self, value):
|
def filter_value(self, value):
|
||||||
if value in self.filter_values \
|
self.lg.debug(
|
||||||
|
'value=%s filter_low=%s filter_high=%s filter_scale=%s prev_value=%s filter_values=%s',
|
||||||
|
value, self.filter_low, self.filter_high, self.filter_scale, self._prev_value, self.filter_values
|
||||||
|
)
|
||||||
|
self.lg.debug(f'{self.customize} {self.entity_id}')
|
||||||
|
if value \
|
||||||
|
in self.filter_values \
|
||||||
or (self.filter_low is not None and value < self.filter_low) \
|
or (self.filter_low is not None and value < self.filter_low) \
|
||||||
or (self.filter_high is not None and value > self.filter_high) \
|
or (self.filter_high is not None and value > self.filter_high) \
|
||||||
or (
|
or (
|
||||||
@@ -223,8 +229,9 @@ class Mega1WSensor(FilterBadValues):
|
|||||||
:param patt: pattern to extract value, must have at least one group that will contain parsed value
|
:param patt: pattern to extract value, must have at least one group that will contain parsed value
|
||||||
"""
|
"""
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self._value = None
|
|
||||||
self.key = key
|
self.key = key
|
||||||
|
lg.debug(f'my key: {key}')
|
||||||
|
self._value = None
|
||||||
self._device_class = device_class
|
self._device_class = device_class
|
||||||
self._unit_of_measurement = unit_of_measurement
|
self._unit_of_measurement = unit_of_measurement
|
||||||
self.mega.sensors.append(self)
|
self.mega.sensors.append(self)
|
||||||
@@ -247,7 +254,7 @@ class Mega1WSensor(FilterBadValues):
|
|||||||
if self.key:
|
if self.key:
|
||||||
return super().unique_id + f'_{self.key}'
|
return super().unique_id + f'_{self.key}'
|
||||||
else:
|
else:
|
||||||
return super(Mega1WSensor, self).unique_id
|
return super().unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
@@ -264,6 +271,8 @@ class Mega1WSensor(FilterBadValues):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
ret = None
|
ret = None
|
||||||
|
if not hasattr(self, 'key'):
|
||||||
|
return None
|
||||||
if self.key:
|
if self.key:
|
||||||
try:
|
try:
|
||||||
ret = self.mega.values.get(self.port, {})
|
ret = self.mega.values.get(self.port, {})
|
||||||
@@ -306,7 +315,10 @@ class Mega1WSensor(FilterBadValues):
|
|||||||
n = super().name
|
n = super().name
|
||||||
c = self.customize.get(CONF_NAME, {})
|
c = self.customize.get(CONF_NAME, {})
|
||||||
if isinstance(c, dict):
|
if isinstance(c, dict):
|
||||||
c = c.get(self.key)
|
try:
|
||||||
|
c = c.get(self.key)
|
||||||
|
except AttributeError:
|
||||||
|
lg.debug(dir(self))
|
||||||
return c or n
|
return c or n
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user