Skip to content

Commit

Permalink
Improved subdeivce/hubs/thermostat logic
Browse files Browse the repository at this point in the history
Import optimization
  • Loading branch information
albertogeniola committed Dec 29, 2019
1 parent 22fc3d5 commit d8718ef
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 28 deletions.
17 changes: 5 additions & 12 deletions custom_components/meross_cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand Down Expand Up @@ -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()

Expand Down
2 changes: 0 additions & 2 deletions custom_components/meross_cloud/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion custom_components/meross_cloud/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 4 additions & 5 deletions custom_components/meross_cloud/cover.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions custom_components/meross_cloud/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/meross_cloud/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions custom_components/meross_cloud/sensor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import logging

from homeassistant.const import ATTR_VOLTAGE
from homeassistant.helpers.entity import Entity
from meross_iot.cloud.devices.power_plugs import GenericPlug

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"""
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 0 additions & 3 deletions custom_components/meross_cloud/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d8718ef

Please sign in to comment.