From 72cf5163537793a1d7f76dfe354f003d9bba88d2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 28 Jan 2021 12:17:38 +0300 Subject: [PATCH] fix mqtt sensor --- custom_components/mega/entities.py | 9 +++++++-- custom_components/mega/hub.py | 4 +++- custom_components/mega/switch.py | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/custom_components/mega/entities.py b/custom_components/mega/entities.py index 134ccf2..df92ec1 100644 --- a/custom_components/mega/entities.py +++ b/custom_components/mega/entities.py @@ -6,7 +6,7 @@ from homeassistant.const import CONF_NAME from homeassistant.core import State from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.restore_state import RestoreEntity -from .hub import MegaD +from . import hub as h from .const import DOMAIN, CONF_CUSTOM, CONF_INVERT, EVENT_BINARY_SENSOR, LONG, \ LONG_RELEASE, RELEASE, PRESS, SINGLE_CLICK, DOUBLE_CLICK, EVENT_BINARY @@ -19,6 +19,11 @@ async def _set_events_on(): _LOGGER.debug('events on') _events_on = True + +def set_events_off(): + global _events_on + _events_on = False + _task_set_ev_on = None @@ -30,7 +35,7 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity): """ def __init__( self, - mega: MegaD, + mega: 'h.MegaD', port: int, config_entry: ConfigEntry = None, id_suffix=None, diff --git a/custom_components/mega/hub.py b/custom_components/mega/hub.py index ed80441..347f847 100644 --- a/custom_components/mega/hub.py +++ b/custom_components/mega/hub.py @@ -15,6 +15,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import Entity from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from .const import TEMP, HUM, PATT_SPLIT, DOMAIN, CONF_HTTP, EVENT_BINARY_SENSOR +from .entities import set_events_off from .exceptions import CannotConnect from .tools import make_ints @@ -109,6 +110,7 @@ class MegaD: async def start(self): self.loop = asyncio.get_event_loop() if self.mqtt is not None: + set_events_off() self.subs = await self.mqtt.async_subscribe( topic=f"{self.mqtt_id}/+", msg_callback=self._process_msg, @@ -232,7 +234,7 @@ class MegaD: self.lg.debug('parsed: %s', ret) if http_cmd == 'list' and isinstance(ret, dict) and 'value' in ret: await asyncio.sleep(1) - ret = await self.request(pt=port, http_cmd=http_cmd) + ret = await self.request(pt=port, cmd=http_cmd) ret = self.parse_response(ret) self.values[port] = ret return ret diff --git a/custom_components/mega/switch.py b/custom_components/mega/switch.py index 1462e63..1178874 100644 --- a/custom_components/mega/switch.py +++ b/custom_components/mega/switch.py @@ -15,7 +15,7 @@ from homeassistant.const import ( CONF_DOMAIN, ) from homeassistant.core import HomeAssistant -from .entities import MegaD +from . import hub as h from .entities import MegaOutPort from .const import CONF_DIMMER, CONF_SWITCH, DOMAIN, CONF_CUSTOM, CONF_SKIP @@ -45,7 +45,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None): async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_devices): mid = config_entry.data[CONF_ID] - hub: MegaD = hass.data['mega'][mid] + hub: 'h.MegaD' = hass.data['mega'][mid] devices = [] customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})