diff --git a/custom_components/meross_cloud/__init__.py b/custom_components/meross_cloud/__init__.py index 84b5c7cbf8..341dacdbcd 100644 --- a/custom_components/meross_cloud/__init__.py +++ b/custom_components/meross_cloud/__init__.py @@ -1,26 +1,22 @@ """Meross devices platform loader""" import logging -from datetime import timedelta import homeassistant.helpers.config_validation as cv import voluptuous as vol from homeassistant import config_entries from homeassistant.const import CONF_PASSWORD, CONF_USERNAME -from homeassistant.helpers import discovery -from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.typing import HomeAssistantType from meross_iot.api import UnauthorizedException -from meross_iot.cloud.client_status import ClientStatus -from meross_iot.cloud.devices.door_openers import GenericGarageDoorOpener -from meross_iot.cloud.devices.light_bulbs import GenericBulb -from meross_iot.cloud.devices.power_plugs import GenericPlug +from meross_iot.logger import h, ROOT_MEROSS_LOGGER from meross_iot.manager import MerossManager -from meross_iot.meross_event import MerossEventType -from .common import (DOMAIN, ATTR_CONFIG, MEROSS_PLATFORMS, ENROLLED_DEVICES, HA_COVER, HA_LIGHT, HA_SENSOR, +from .common import (DOMAIN, ATTR_CONFIG, MEROSS_PLATFORMS, HA_COVER, HA_LIGHT, HA_SENSOR, HA_SWITCH, MANAGER, SENSORS, dismiss_notification, notify_error) +# Unset the default stream handler for logger of the meross_iot library +ROOT_MEROSS_LOGGER.removeHandler(h) + _LOGGER = logging.getLogger(__name__) @@ -49,9 +45,6 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry): hass.data[DOMAIN][MANAGER] = manager hass.data[DOMAIN][SENSORS] = {} - # Setup a set for keeping track of enrolled devices - hass.data[DOMAIN][ENROLLED_DEVICES] = set() - _LOGGER.info("Starting meross manager") manager.start() diff --git a/custom_components/meross_cloud/climate.py b/custom_components/meross_cloud/climate.py index 72de66e3ec..bf2edade4f 100644 --- a/custom_components/meross_cloud/climate.py +++ b/custom_components/meross_cloud/climate.py @@ -216,8 +216,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(thermostat_devices) - # hass.data[DOMAIN][ENROLLED_DEVICES].add(device.uuid) - async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): pass diff --git a/custom_components/meross_cloud/common.py b/custom_components/meross_cloud/common.py index 4b8dc1d478..b266ea470f 100644 --- a/custom_components/meross_cloud/common.py +++ b/custom_components/meross_cloud/common.py @@ -2,7 +2,6 @@ DOMAIN = 'meross_cloud' ATTR_CONFIG = "config" MANAGER = 'manager' -ENROLLED_DEVICES = 'enrolled_devices' MEROSS_MANAGER = "%s.%s" % (DOMAIN, MANAGER) SENSORS = 'sensors' HA_SWITCH = 'switch' diff --git a/custom_components/meross_cloud/cover.py b/custom_components/meross_cloud/cover.py index 1e3208e856..102cab1b04 100644 --- a/custom_components/meross_cloud/cover.py +++ b/custom_components/meross_cloud/cover.py @@ -1,12 +1,13 @@ +import logging + from homeassistant.components.cover import (SUPPORT_CLOSE, SUPPORT_OPEN, CoverDevice) from homeassistant.const import (STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING, STATE_UNKNOWN) from meross_iot.cloud.devices.door_openers import GenericGarageDoorOpener -from .common import (DOMAIN, ENROLLED_DEVICES, MANAGER) -import logging from meross_iot.meross_event import MerossEventType +from .common import (DOMAIN, MANAGER) _LOGGER = logging.getLogger(__name__) @@ -40,7 +41,7 @@ def __init__(self, device: GenericGarageDoorOpener): self._state = STATE_CLOSED def handler(self, evt) -> None: - if evt.type == MerossEventType.GARAGE_DOOR_STATUS: + if evt.event_type == MerossEventType.GARAGE_DOOR_STATUS: if evt.channel == self._channel: # The underlying library only exposes "open" and "closed" statuses if evt.door_state == 'open': @@ -154,8 +155,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(cover_entities) - # hass.data[DOMAIN][ENROLLED_DEVICES].add(device.uuid) - async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): pass diff --git a/custom_components/meross_cloud/light.py b/custom_components/meross_cloud/light.py index 35e3622bf4..842ac900df 100644 --- a/custom_components/meross_cloud/light.py +++ b/custom_components/meross_cloud/light.py @@ -150,8 +150,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(bulb_devices) - # hass.data[DOMAIN][ENROLLED_DEVICES].add(device.uuid) - async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): pass diff --git a/custom_components/meross_cloud/manifest.json b/custom_components/meross_cloud/manifest.json index d7b8df3bee..080a4a1d95 100644 --- a/custom_components/meross_cloud/manifest.json +++ b/custom_components/meross_cloud/manifest.json @@ -4,6 +4,6 @@ "documentation": "https://www.home-assistant.io/components/meross_cloud", "dependencies": ["persistent_notification"], "codeowners": ["@albertogeniola"], - "requirements": ["meross_iot==0.3.2.3"], + "requirements": ["meross_iot==0.3.2.4"], "config_flow": true } diff --git a/custom_components/meross_cloud/sensor.py b/custom_components/meross_cloud/sensor.py index a002c2105c..591c38dffb 100644 --- a/custom_components/meross_cloud/sensor.py +++ b/custom_components/meross_cloud/sensor.py @@ -1,3 +1,5 @@ +import logging + from homeassistant.const import ATTR_VOLTAGE from homeassistant.helpers.entity import Entity from meross_iot.cloud.devices.power_plugs import GenericPlug @@ -5,6 +7,8 @@ from .common import (DOMAIN, MANAGER, SENSORS, calculate_sensor_id) +_LOGGER = logging.getLogger(__name__) + class PowerSensorWrapper(Entity): """Wrapper class to adapt the Meross power sensors into the Homeassistant platform""" @@ -121,14 +125,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # First, parse power sensors that are embedded into power plugs for plug in plugs: # type: GenericPlug - if plug.supports_consumption_reading(): + if not plug.online: + _LOGGER.warning("The plug %s is offline; it's impossible to determine if it supports any ability" + % plug.name) + elif plug.supports_consumption_reading(): w = PowerSensorWrapper(device=plug) sensor_entities.append(w) # TODO: Then parse thermostat sensors? async_add_entities(sensor_entities) - # hass.data[DOMAIN][ENROLLED_DEVICES].add(device.uuid) async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): diff --git a/custom_components/meross_cloud/switch.py b/custom_components/meross_cloud/switch.py index 928d67e4e6..3a99f1c3e1 100644 --- a/custom_components/meross_cloud/switch.py +++ b/custom_components/meross_cloud/switch.py @@ -98,9 +98,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(switch_entities) - # hass.data[DOMAIN][ENROLLED_DEVICES].add(device.uuid) - - async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): pass