Compare commits

..

8 Commits

Author SHA1 Message Date
Andrey
0c43e61c59 make fake http response 2021-02-18 11:11:30 +03:00
Andrey
0a71be693e fix bugs 2021-02-18 11:00:41 +03:00
Andrey
8146148d0c fix bugs 2021-02-18 10:46:17 +03:00
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
4 changed files with 32 additions and 23 deletions

View File

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

View File

@@ -78,7 +78,8 @@ class MegaView(HomeAssistantView):
template.hass = hass
ret = template.async_render(data)
_LOGGER.debug('response %s', ret)
ret = Response(body=ret or 'd', content_type='text/plain', headers={'Server': 's', 'Date': 'n'})
ret = Response(body='', content_type='text/plain', headers={'Server': 's', 'Date': 'n'})
await hub.request(cmd=ret)
return ret
async def later_update(self, hub):

View File

@@ -101,6 +101,7 @@ class MegaD:
self.cnd = asyncio.Condition()
self.online = True
self.entities: typing.List[BaseMegaEntity] = []
self.ds2413_ports = set()
self.poll_interval = scan_interval
self.subs = None
self.lg: logging.Logger = lg.getChild(self.id)
@@ -191,25 +192,25 @@ class MegaD:
)
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):
"""
Polling ports
"""
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:
await self.get_all_ports()
await self.get_sensors(only_list=True)
@@ -219,6 +220,7 @@ class MegaD:
await self.get_sensors()
else:
await self.get_port(self.port_to_scan)
await self._get_ds2413()
return self.values
async def get_mqtt_id(self):
@@ -313,6 +315,8 @@ class MegaD:
if not self.mqtt_inputs:
ret = await self.request(cmd='all')
for port, x in enumerate(ret.split(';')):
if port in self.ds2413_ports:
continue
if check_skip and not port in self.ports:
continue
ret = self.parse_response(x)

View File

@@ -15,5 +15,5 @@
"@andvikt"
],
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
"version": "v0.4.1b3"
"version": "v0.4.1b7"
}