Compare commits

...

5 Commits

Author SHA1 Message Date
Andrey
e0eaafd0fa fix bugs 2021-02-18 10:40:09 +03:00
Andrey
51f3eb3b19 fix bugs 2021-02-18 10:23:27 +03:00
Andrey
1716651497 fix bugs 2021-02-18 10:12:01 +03:00
Andrey
a87e8139a7 fix bugs 2021-02-18 09:53:30 +03:00
Andrey
358d29f8fd fix bugs 2021-02-18 09:27:40 +03:00
3 changed files with 28 additions and 20 deletions

View File

@@ -48,6 +48,9 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
index=None, index=None,
): ):
super().__init__(mega.updater) super().__init__(mega.updater)
self.http_cmd = http_cmd
self._state: State = None self._state: State = None
self.port = port self.port = port
self.config_entry = config_entry self.config_entry = config_entry
@@ -60,9 +63,10 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
self._name = name or f"{mega.id}_{port}" + \ self._name = name or f"{mega.id}_{port}" + \
(f"_{id_suffix}" if id_suffix else "") (f"_{id_suffix}" if id_suffix else "")
self._customize: dict = None self._customize: dict = None
self.http_cmd = http_cmd
self.index = index self.index = index
self.addr = addr self.addr = addr
if self.http_cmd == 'ds2413':
self.mega.ds2413_ports |= {self.port}
@property @property
def customize(self): def customize(self):
@@ -251,17 +255,17 @@ class MegaOutPort(MegaPushEntity):
val = val.get("value") val = val.get("value")
if self.index and self.addr: if self.index and self.addr:
if not isinstance(val, dict): if not isinstance(val, dict):
self.mega.lg.warning(f'{self.entity_id} has wrong state: {val}') self.mega.lg.warning(f'{self.entity_id}: {val} is not a dict')
return return
_val = val.get(self.addr) _val = val.get(self.addr)
if not isinstance(val, str): if not isinstance(val, str):
self.mega.lg.warning(f'{self.entity_id} has wrong state: {val}') self.mega.lg.warning(f'{self.entity_id}: can not get {self.addr} from {val}')
return return
_val = _val.split('/') _val = _val.split('/')
if len(_val) >= 2: if len(_val) >= 2:
val = val[self.index] val = _val[self.index]
else: else:
self.mega.lg.warning(f'{self.entity_id} has wrong state: {val}') self.mega.lg.warning(f'{self.entity_id}: {_val} has wrong length')
return return
elif self.index and self.addr is None: elif self.index and self.addr is None:
self.mega.lg.warning(f'{self.entity_id} does not has addr') self.mega.lg.warning(f'{self.entity_id} does not has addr')

View File

@@ -101,6 +101,7 @@ class MegaD:
self.cnd = asyncio.Condition() self.cnd = asyncio.Condition()
self.online = True self.online = True
self.entities: typing.List[BaseMegaEntity] = [] self.entities: typing.List[BaseMegaEntity] = []
self.ds2413_ports = set()
self.poll_interval = scan_interval self.poll_interval = scan_interval
self.subs = None self.subs = None
self.lg: logging.Logger = lg.getChild(self.id) self.lg: logging.Logger = lg.getChild(self.id)
@@ -191,25 +192,25 @@ class MegaD:
) )
self.online = True self.online = True
async def _get_ds2413(self):
"""
обновление ds2413 устройств
:return:
"""
for x in self.ds2413_ports:
self.lg.debug(f'poll ds2413 for %s', x)
await self.get_port(
port=x,
force_http=True,
http_cmd='list',
conv=False
)
async def poll(self): async def poll(self):
""" """
Polling ports Polling ports
""" """
self.lg.debug('poll') self.lg.debug('poll')
ds2413_polled = []
for x in self.entities:
# обновление ds2413 устройств
if x.http_cmd == 'ds2413':
self.lg.debug(f'poll ds2413 for {x.entity_id}')
if x.port in ds2413_polled:
continue
await self.get_port(
port=x.port,
force_http=True,
http_cmd='list',
conv=False
)
ds2413_polled.append(x.port)
if self.mqtt is None: if self.mqtt is None:
await self.get_all_ports() await self.get_all_ports()
await self.get_sensors(only_list=True) await self.get_sensors(only_list=True)
@@ -219,6 +220,7 @@ class MegaD:
await self.get_sensors() await self.get_sensors()
else: else:
await self.get_port(self.port_to_scan) await self.get_port(self.port_to_scan)
await self._get_ds2413()
return self.values return self.values
async def get_mqtt_id(self): async def get_mqtt_id(self):
@@ -313,6 +315,8 @@ class MegaD:
if not self.mqtt_inputs: if not self.mqtt_inputs:
ret = await self.request(cmd='all') ret = await self.request(cmd='all')
for port, x in enumerate(ret.split(';')): for port, x in enumerate(ret.split(';')):
if port in self.ds2413_ports:
continue
if check_skip and not port in self.ports: if check_skip and not port in self.ports:
continue continue
ret = self.parse_response(x) ret = self.parse_response(x)

View File

@@ -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": "v0.4.1b3" "version": "v0.4.1b7"
} }