diff --git a/custom_components/meross_cloud/climate.py b/custom_components/meross_cloud/climate.py index 4ecf2b18c4..4d2fd63536 100644 --- a/custom_components/meross_cloud/climate.py +++ b/custom_components/meross_cloud/climate.py @@ -21,7 +21,7 @@ ThermostatModeChange, ThermostatTemperatureChange) -from .common import (DOMAIN, HA_CLIMATE, MANAGER, ConnectionWatchDog, cloud_io, MerossEntityWrapper) +from .common import (DOMAIN, HA_CLIMATE, MANAGER, ConnectionWatchDog, MerossEntityWrapper) _LOGGER = logging.getLogger(__name__) @@ -51,7 +51,6 @@ def __init__(self, device: ValveSubDevice): self._first_update_done = False self._target_temperature = None - @cloud_io() def update(self): if self._device.online: self._device.get_status(force_status_refresh=True) @@ -76,7 +75,10 @@ def notify_client_state(self, status: ClientStatus): self.schedule_update_ha_state(False) @property - @cloud_io(default_return_value=None) + def assumed_state(self) -> bool: + return not self._first_update_done + + @property def current_temperature(self) -> float: if not self._first_update_done: # Schedule update and return @@ -86,7 +88,6 @@ def current_temperature(self) -> float: return float(self._device.get_status().get('temperature').get('room'))/10 @property - @cloud_io(default_return_value=None) def hvac_action(self) -> str: if not self._first_update_done: # Schedule update and return @@ -104,7 +105,6 @@ def hvac_action(self) -> str: return CURRENT_HVAC_IDLE @property - @cloud_io(default_return_value=HVAC_MODE_OFF) def hvac_mode(self) -> str: if not self._first_update_done: # Schedule update and return @@ -160,14 +160,12 @@ def temperature_unit(self) -> str: def hvac_modes(self) -> List[str]: return [HVAC_MODE_OFF, HVAC_MODE_AUTO, HVAC_MODE_HEAT] - @cloud_io() def set_temperature(self, **kwargs) -> None: target = kwargs.get('temperature') self._device.set_target_temperature(target, callback=none_callback, timeout=THERMOSTAT_TIMEOUT) # Assume update will work, thus update local state immediately self._target_temperature = target - @cloud_io() def set_hvac_mode(self, hvac_mode: str) -> None: # NOTE: this method will also update the local state as the thermostat will take too much time to get the # command ACK.turn_on @@ -223,7 +221,6 @@ def action(error, response): else: _LOGGER.warning("Unsupported mode for this device") - @cloud_io() def set_preset_mode(self, preset_mode: str) -> None: if self._device.type == "mts100v3": self._device_mode = ThermostatV3Mode[preset_mode] # Update local state diff --git a/custom_components/meross_cloud/common.py b/custom_components/meross_cloud/common.py index d1a4aca9eb..c4222c1f30 100644 --- a/custom_components/meross_cloud/common.py +++ b/custom_components/meross_cloud/common.py @@ -75,22 +75,6 @@ def notify_client_state(self, status: ClientStatus): pass -def cloud_io(default_return_value=None): - def cloud_io_inner(func): - @functools.wraps(func) - def func_wrapper(*args, **kwargs): - try: - return func(*args, **kwargs) - except CommandTimeoutException as e: - log_exception("A command timeout occurred while handling cloud_io function.", logger=_LOGGER) - if default_return_value is not None: - return default_return_value - else: - return None - return func_wrapper - return cloud_io_inner - - def log_exception(message: str = None, logger: logging = None): if logger is None: logger = logging.getLogger(__name__) diff --git a/custom_components/meross_cloud/cover.py b/custom_components/meross_cloud/cover.py index 82372328fe..992d0ff243 100644 --- a/custom_components/meross_cloud/cover.py +++ b/custom_components/meross_cloud/cover.py @@ -9,7 +9,7 @@ from meross_iot.meross_event import (DeviceDoorStatusEvent, DeviceOnlineStatusEvent) -from .common import (DOMAIN, HA_COVER, MANAGER, ConnectionWatchDog, cloud_io, MerossEntityWrapper) +from .common import (DOMAIN, HA_COVER, MANAGER, ConnectionWatchDog, MerossEntityWrapper) _LOGGER = logging.getLogger(__name__) @@ -35,7 +35,6 @@ def __init__(self, device: GenericGarageDoorOpener): self._opening = False self._closing = False - @cloud_io() def update(self): if self._device.online: self._device.get_status(force_status_refresh=True) @@ -68,6 +67,10 @@ def notify_client_state(self, status: ClientStatus): self._available = False self.schedule_update_ha_state(False) + @property + def assumed_state(self) -> bool: + return not self._first_update_done + @property def name(self) -> str: """Return the name of the cover.""" @@ -80,7 +83,6 @@ def available(self) -> bool: return self._available and self._device.online @property - @cloud_io(default_return_value=True) def is_closed(self): if not self._first_update_done: # Schedule update and return @@ -91,7 +93,6 @@ def is_closed(self): return not self._device.get_status(False).get(self._channel) @property - @cloud_io(default_return_value=False) def is_open(self): if not self._first_update_done: # Schedule update and return @@ -102,7 +103,6 @@ def is_open(self): return self._device.get_status(False).get(self._channel) @property - @cloud_io(default_return_value=False) def is_opening(self): if not self._first_update_done: # Schedule update and return @@ -113,7 +113,6 @@ def is_opening(self): return self._opening @property - @cloud_io(default_return_value=False) def is_closing(self): if not self._first_update_done: # Schedule update and return @@ -121,7 +120,6 @@ def is_closing(self): return None return self._closing - @cloud_io() def close_cover(self, **kwargs): """Close the cover.""" is_closed = not self._device.get_status(False).get(self._channel) @@ -133,7 +131,6 @@ def close_cover(self, **kwargs): if self.enabled: self.schedule_update_ha_state(False) - @cloud_io() def open_cover(self, **kwargs): """Open the cover.""" is_open = self._device.get_status(False).get(self._channel) diff --git a/custom_components/meross_cloud/fan.py b/custom_components/meross_cloud/fan.py index 006b71a527..30244baf1a 100644 --- a/custom_components/meross_cloud/fan.py +++ b/custom_components/meross_cloud/fan.py @@ -8,7 +8,7 @@ from meross_iot.meross_event import (DeviceOnlineStatusEvent, HumidifierSpryEvent) -from .common import (DOMAIN, HA_FAN, MANAGER, ConnectionWatchDog, cloud_io, MerossEntityWrapper) +from .common import (DOMAIN, HA_FAN, MANAGER, ConnectionWatchDog, MerossEntityWrapper) _LOGGER = logging.getLogger(__name__) @@ -27,7 +27,6 @@ def __init__(self, device: GenericHumidifier): self._available = True # Assume the mqtt client is connected self._first_update_done = False - @cloud_io() def update(self): if self._device.online: self._device.get_status(force_status_refresh=True) @@ -54,6 +53,10 @@ async def async_added_to_hass(self) -> None: async def async_will_remove_from_hass(self) -> None: self._device.unregister_event_callback(self.device_event_handler) + @property + def assumed_state(self) -> bool: + return not self._first_update_done + @property def available(self) -> bool: # A device is available if the client library is connected to the MQTT broker and if the @@ -72,7 +75,6 @@ def is_on(self) -> bool: return spry_mode != SprayMode.OFF @property - @cloud_io(default_return_value=None) def speed(self) -> Optional[str]: if not self._first_update_done: # Schedule update and return @@ -90,17 +92,14 @@ def speed_list(self) -> list: """Get the list of available speeds.""" return [e.name for e in SprayMode] - @cloud_io() def set_speed(self, speed: str) -> None: mode = SprayMode[speed] self._device.set_spray_mode(mode) - @cloud_io() def set_direction(self, direction: str) -> None: # Not supported pass - @cloud_io() def turn_on(self, speed: Optional[str] = None, **kwargs) -> None: if speed is None: mode = SprayMode.CONTINUOUS @@ -109,7 +108,6 @@ def turn_on(self, speed: Optional[str] = None, **kwargs) -> None: self._device.set_spray_mode(mode) - @cloud_io() def turn_off(self, **kwargs: Any) -> None: self._device.set_spray_mode(SprayMode.OFF) diff --git a/custom_components/meross_cloud/light.py b/custom_components/meross_cloud/light.py index ef5f456071..a33d574ef8 100644 --- a/custom_components/meross_cloud/light.py +++ b/custom_components/meross_cloud/light.py @@ -11,7 +11,7 @@ from meross_iot.meross_event import (BulbLightStateChangeEvent, BulbSwitchStateChangeEvent, DeviceOnlineStatusEvent) -from .common import (DOMAIN, HA_LIGHT, MANAGER, ConnectionWatchDog, cloud_io, log_exception) +from .common import (DOMAIN, HA_LIGHT, MANAGER, ConnectionWatchDog, log_exception) _LOGGER = logging.getLogger(__name__) @@ -48,7 +48,6 @@ def __init__(self, device: GenericBulb, channel: int): self._flags |= SUPPORT_COLOR self._flags |= SUPPORT_COLOR_TEMP - @cloud_io() def update(self): if self._device.online: self._device.get_status(force_status_refresh=True) @@ -99,6 +98,10 @@ def notify_client_state(self, status: ClientStatus): self._available = False self.schedule_update_ha_state(False) + @property + def assumed_state(self) -> bool: + return not self._first_update_done + @property def should_poll(self) -> bool: return False @@ -109,7 +112,6 @@ def available(self) -> bool: return self._available and self._device.online @property - @cloud_io(default_return_value=False) def is_on(self) -> bool: if not self._first_update_done: # Schedule update and return @@ -119,7 +121,6 @@ def is_on(self) -> bool: return self._device.get_channel_status(channel=self._channel_id).get('onoff') @property - @cloud_io(default_return_value=0) def brightness(self): if not self._first_update_done: # Schedule update and return @@ -134,7 +135,6 @@ def brightness(self): return float(luminance) / 100 * 255 @property - @cloud_io(default_return_value=0) def hs_color(self): if not self._first_update_done: # Schedule update and return @@ -148,7 +148,6 @@ def hs_color(self): return None @property - @cloud_io(default_return_value=0) def color_temp(self): if not self._first_update_done: # Schedule update and return @@ -184,11 +183,9 @@ def device_info(self): 'sw_version': self._device.fwversion } - @cloud_io() def turn_off(self, **kwargs) -> None: self._device.turn_off(channel=self._channel_id) - @cloud_io() def turn_on(self, **kwargs) -> None: if not self.is_on: self._device.turn_on(channel=self._channel_id) diff --git a/custom_components/meross_cloud/manifest.json b/custom_components/meross_cloud/manifest.json index 7f8687f43b..f8fda66dd9 100644 --- a/custom_components/meross_cloud/manifest.json +++ b/custom_components/meross_cloud/manifest.json @@ -6,6 +6,6 @@ "codeowners": ["@albertogeniola"], "requirements": ["meross-iot==0.3.4.4"], "config_flow": true, - "meross_cloud_version": "0.3.4.4", + "meross_cloud_version": "0.3.4.4-2", "quality_scale": "gold" } diff --git a/custom_components/meross_cloud/sensor.py b/custom_components/meross_cloud/sensor.py index b959af38db..d73a864f68 100644 --- a/custom_components/meross_cloud/sensor.py +++ b/custom_components/meross_cloud/sensor.py @@ -6,7 +6,7 @@ from meross_iot.cloud.devices.power_plugs import GenericPlug from meross_iot.meross_event import DeviceOnlineStatusEvent -from .common import (DOMAIN, HA_SENSOR, MANAGER, calculate_sensor_id, ConnectionWatchDog, cloud_io, MerossEntityWrapper) +from .common import (DOMAIN, HA_SENSOR, MANAGER, calculate_sensor_id, ConnectionWatchDog, MerossEntityWrapper) _LOGGER = logging.getLogger(__name__) @@ -22,7 +22,6 @@ def __init__(self, device: GenericPlug): self._sensor_info = None self._available = True # Assume the mqtt client is connected - @cloud_io() def update(self): # Given that the device is online, we force a full state refresh. # This is necessary as this device is handled with HA should_poll=True @@ -54,6 +53,10 @@ def notify_client_state(self, status: ClientStatus): self._available = False self.schedule_update_ha_state(False) + @property + def assumed_state(self) -> bool: + return not self._first_update_done + @property def available(self) -> bool: return self._available and self._device.online diff --git a/custom_components/meross_cloud/switch.py b/custom_components/meross_cloud/switch.py index 54471b1ee1..2fa477cc11 100644 --- a/custom_components/meross_cloud/switch.py +++ b/custom_components/meross_cloud/switch.py @@ -4,7 +4,7 @@ from meross_iot.cloud.client_status import ClientStatus from meross_iot.cloud.devices.power_plugs import GenericPlug from meross_iot.manager import MerossManager -from .common import (DOMAIN, HA_SWITCH, MANAGER, calculate_switch_id, ConnectionWatchDog, cloud_io, MerossEntityWrapper) +from .common import (DOMAIN, HA_SWITCH, MANAGER, calculate_switch_id, ConnectionWatchDog, MerossEntityWrapper) _LOGGER = logging.getLogger(__name__) @@ -29,7 +29,6 @@ def __init__(self, device: GenericPlug, channel: int): self._available = True # Assume the mqtt client is connected self._first_update_done = False - @cloud_io() def update(self): if self._device.online: self._device.get_status(force_status_refresh=True) @@ -83,7 +82,6 @@ def should_poll(self) -> bool: return False @property - @cloud_io(default_return_value=False) def is_on(self) -> bool: if not self._first_update_done: # Schedule update and return @@ -96,11 +94,9 @@ def is_on(self) -> bool: def assumed_state(self) -> bool: return not self._first_update_done - @cloud_io() def turn_off(self, **kwargs) -> None: self._device.turn_off_channel(self._channel_id) - @cloud_io() def turn_on(self, **kwargs) -> None: self._device.turn_on_channel(self._channel_id)