mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 01:24:29 +05:00
fix mqtt sensor
This commit is contained in:
@@ -6,7 +6,7 @@ from homeassistant.const import CONF_NAME
|
|||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
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, \
|
from .const import DOMAIN, CONF_CUSTOM, CONF_INVERT, EVENT_BINARY_SENSOR, LONG, \
|
||||||
LONG_RELEASE, RELEASE, PRESS, SINGLE_CLICK, DOUBLE_CLICK, EVENT_BINARY
|
LONG_RELEASE, RELEASE, PRESS, SINGLE_CLICK, DOUBLE_CLICK, EVENT_BINARY
|
||||||
|
|
||||||
@@ -19,6 +19,11 @@ async def _set_events_on():
|
|||||||
_LOGGER.debug('events on')
|
_LOGGER.debug('events on')
|
||||||
_events_on = True
|
_events_on = True
|
||||||
|
|
||||||
|
|
||||||
|
def set_events_off():
|
||||||
|
global _events_on
|
||||||
|
_events_on = False
|
||||||
|
|
||||||
_task_set_ev_on = None
|
_task_set_ev_on = None
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +35,7 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
|||||||
"""
|
"""
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
mega: MegaD,
|
mega: 'h.MegaD',
|
||||||
port: int,
|
port: int,
|
||||||
config_entry: ConfigEntry = None,
|
config_entry: ConfigEntry = None,
|
||||||
id_suffix=None,
|
id_suffix=None,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
from .const import TEMP, HUM, PATT_SPLIT, DOMAIN, CONF_HTTP, EVENT_BINARY_SENSOR
|
from .const import TEMP, HUM, PATT_SPLIT, DOMAIN, CONF_HTTP, EVENT_BINARY_SENSOR
|
||||||
|
from .entities import set_events_off
|
||||||
from .exceptions import CannotConnect
|
from .exceptions import CannotConnect
|
||||||
from .tools import make_ints
|
from .tools import make_ints
|
||||||
|
|
||||||
@@ -109,6 +110,7 @@ class MegaD:
|
|||||||
async def start(self):
|
async def start(self):
|
||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
if self.mqtt is not None:
|
if self.mqtt is not None:
|
||||||
|
set_events_off()
|
||||||
self.subs = await self.mqtt.async_subscribe(
|
self.subs = await self.mqtt.async_subscribe(
|
||||||
topic=f"{self.mqtt_id}/+",
|
topic=f"{self.mqtt_id}/+",
|
||||||
msg_callback=self._process_msg,
|
msg_callback=self._process_msg,
|
||||||
@@ -232,7 +234,7 @@ class MegaD:
|
|||||||
self.lg.debug('parsed: %s', ret)
|
self.lg.debug('parsed: %s', ret)
|
||||||
if http_cmd == 'list' and isinstance(ret, dict) and 'value' in ret:
|
if http_cmd == 'list' and isinstance(ret, dict) and 'value' in ret:
|
||||||
await asyncio.sleep(1)
|
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)
|
ret = self.parse_response(ret)
|
||||||
self.values[port] = ret
|
self.values[port] = ret
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from homeassistant.const import (
|
|||||||
CONF_DOMAIN,
|
CONF_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from .entities import MegaD
|
from . import hub as h
|
||||||
from .entities import MegaOutPort
|
from .entities import MegaOutPort
|
||||||
from .const import CONF_DIMMER, CONF_SWITCH, DOMAIN, CONF_CUSTOM, CONF_SKIP
|
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):
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_devices):
|
||||||
mid = config_entry.data[CONF_ID]
|
mid = config_entry.data[CONF_ID]
|
||||||
hub: MegaD = hass.data['mega'][mid]
|
hub: 'h.MegaD' = hass.data['mega'][mid]
|
||||||
devices = []
|
devices = []
|
||||||
|
|
||||||
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
||||||
|
|||||||
Reference in New Issue
Block a user