From 137eb8b6baed412b185097eba3b798ef36f4f60d Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Feb 2021 21:15:48 +0300 Subject: [PATCH] fix errors --- custom_components/mega/binary_sensor.py | 4 ++++ custom_components/mega/config_flow.py | 2 +- custom_components/mega/const.py | 2 ++ custom_components/mega/http.py | 13 +++++++------ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/custom_components/mega/binary_sensor.py b/custom_components/mega/binary_sensor.py index 722c78d..e8f7bbb 100644 --- a/custom_components/mega/binary_sensor.py +++ b/custom_components/mega/binary_sensor.py @@ -67,6 +67,10 @@ class MegaBinarySensor(BinarySensorEntity, MegaPushEntity): super().__init__(*args, **kwargs) self._is_on = None self._attrs = None + self._click_task = None + + async def _click(self): + await self.customize.get @property def state_attributes(self): diff --git a/custom_components/mega/config_flow.py b/custom_components/mega/config_flow.py index 6286dff..3f89dfd 100644 --- a/custom_components/mega/config_flow.py +++ b/custom_components/mega/config_flow.py @@ -118,7 +118,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow): reload = user_input.pop(CONF_RELOAD) cfg = dict(self.config_entry.data) cfg.update(user_input) - hub = await get_hub(self.hass, self.config_entry.data) + hub = await get_hub(self.hass, cfg) if reload: await hub.start() new = await hub.get_config(nports=user_input.get(CONF_NPORTS, 37)) diff --git a/custom_components/mega/const.py b/custom_components/mega/const.py index 317660c..c209a8e 100644 --- a/custom_components/mega/const.py +++ b/custom_components/mega/const.py @@ -32,6 +32,8 @@ CONF_POLL_OUTS = 'poll_outs' CONF_FORCE_D = 'force_d' CONF_DEF_RESPONSE = 'def_response' CONF_RESTORE_ON_RESTART = 'restore_on_restart' +CONF_CLICK_TIME = 'click_time' +CONF_LONG_TIME = 'long_time' PLATFORMS = [ "light", "switch", diff --git a/custom_components/mega/http.py b/custom_components/mega/http.py index 67dc8d7..005c41f 100644 --- a/custom_components/mega/http.py +++ b/custom_components/mega/http.py @@ -110,20 +110,21 @@ class MegaView(HomeAssistantView): f'have ext_int: {hub.ext_in}, ext: {hub.extenders}') return Response(status=200) for e, v in data.items(): + _data = data.copy() if e.startswith('ext'): idx = e[3:] pt = f'{pt_orig}e{idx}' - data['pt_orig'] = pt_orig - data['value'] = 'ON' if v == '1' else 'OFF' - data['m'] = 1 if data[e] == '0' else 0 # имитация поведения обычного входа, чтобы события обрабатывались аналогично - hub.values[pt] = data + _data['pt_orig'] = pt_orig + _data['value'] = 'ON' if v == '1' else 'OFF' + _data['m'] = 1 if _data[e] == '0' else 0 # имитация поведения обычного входа, чтобы события обрабатывались аналогично + hub.values[pt] = _data for cb in self.callbacks[hub.id][pt]: - cb(data) + cb(_data) act = hub.ext_act.get(pt) template: Template = self.templates.get(hub.id, {}).get(port, hub.def_response) if template is not None: template.hass = hass - ret = template.async_render(data) + ret = template.async_render(_data) if ret == 'd' and act: await hub.request(cmd=act) ret = 'd' if hub.force_d else ''