From 4f8f38fde6c00717fe63e5e45d3f0b304697dec1 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Feb 2021 12:07:55 +0300 Subject: [PATCH] fix http response and ds2413 bugs --- custom_components/mega/entities.py | 2 +- custom_components/mega/http.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/custom_components/mega/entities.py b/custom_components/mega/entities.py index 425fee4..d4ab7cf 100644 --- a/custom_components/mega/entities.py +++ b/custom_components/mega/entities.py @@ -253,7 +253,7 @@ class MegaOutPort(MegaPushEntity): return self._state == 'ON' elif val is not None: val = val.get("value") - if self.index is not None and self.addr is not None: + if not isinstance(val, str) and self.index is not None and self.addr is not None: if not isinstance(val, dict): self.mega.lg.warning(f'{self.entity_id}: {val} is not a dict') return diff --git a/custom_components/mega/http.py b/custom_components/mega/http.py index fdd241a..08b490d 100644 --- a/custom_components/mega/http.py +++ b/custom_components/mega/http.py @@ -66,7 +66,7 @@ class MegaView(HomeAssistantView): update_all = False data['value'] = data.pop('v') data['mega_id'] = hub.id - ret = 'd' + ret = 'd' if hub.force_d else '' if port is not None: hub.values[port] = data for cb in self.callbacks[hub.id][port]: @@ -79,7 +79,8 @@ class MegaView(HomeAssistantView): ret = template.async_render(data) _LOGGER.debug('response %s', ret) Response(body='', content_type='text/plain', headers={'Server': 's', 'Date': 'n'}) - await hub.request(cmd=ret) + if ret: + await hub.request(cmd=ret) return ret async def later_update(self, hub):