From c56530a71256cf8e7e9a894d525094999409af78 Mon Sep 17 00:00:00 2001 From: Penny Wood Date: Thu, 12 Mar 2020 00:26:16 +0800 Subject: [PATCH] Connect to more recent versions of IZone (#32552) * Update to new version of python-izone * Improve disconnection handling. * Update requirements-all * Lint fix --- homeassistant/components/izone/climate.py | 36 ++++++++++++++++---- homeassistant/components/izone/const.py | 2 +- homeassistant/components/izone/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/izone/climate.py b/homeassistant/components/izone/climate.py index 20673312fa7..dde71d14a9c 100644 --- a/homeassistant/components/izone/climate.py +++ b/homeassistant/components/izone/climate.py @@ -85,6 +85,21 @@ async def async_setup_entry( return True +def _return_on_connection_error(ret=None): + def wrap(func): + def wrapped_f(*args, **kwargs): + if not args[0].available: + return ret + try: + return func(*args, **kwargs) + except ConnectionError: + return ret + + return wrapped_f + + return wrap + + class ControllerDevice(ClimateDevice): """Representation of iZone Controller.""" @@ -161,6 +176,8 @@ class ControllerDevice(ClimateDevice): if ctrl is not self._controller: return self.async_schedule_update_ha_state() + for zone in self.zones.values(): + zone.async_schedule_update_ha_state() self.async_on_remove( async_dispatcher_connect( @@ -259,12 +276,15 @@ class ControllerDevice(ClimateDevice): if not self._controller.is_on: return HVAC_MODE_OFF mode = self._controller.mode + if mode == Controller.Mode.FREE_AIR: + return HVAC_MODE_FAN_ONLY for (key, value) in self._state_to_pizone.items(): if value == mode: return key assert False, "Should be unreachable" @property + @_return_on_connection_error([]) def hvac_modes(self) -> List[str]: """Return the list of available operation modes.""" if self._controller.free_air: @@ -272,11 +292,13 @@ class ControllerDevice(ClimateDevice): return [HVAC_MODE_OFF, *self._state_to_pizone] @property + @_return_on_connection_error(PRESET_NONE) def preset_mode(self): """Eco mode is external air.""" return PRESET_ECO if self._controller.free_air else PRESET_NONE @property + @_return_on_connection_error([PRESET_NONE]) def preset_modes(self): """Available preset modes, normal or eco.""" if self._controller.free_air_enabled: @@ -284,6 +306,7 @@ class ControllerDevice(ClimateDevice): return [PRESET_NONE] @property + @_return_on_connection_error() def current_temperature(self) -> Optional[float]: """Return the current temperature.""" if self._controller.mode == Controller.Mode.FREE_AIR: @@ -291,6 +314,7 @@ class ControllerDevice(ClimateDevice): return self._controller.temp_return @property + @_return_on_connection_error() def target_temperature(self) -> Optional[float]: """Return the temperature we try to reach.""" if not self._supported_features & SUPPORT_TARGET_TEMPERATURE: @@ -318,11 +342,13 @@ class ControllerDevice(ClimateDevice): return list(self._fan_to_pizone) @property + @_return_on_connection_error(0.0) def min_temp(self) -> float: """Return the minimum temperature.""" return self._controller.temp_min @property + @_return_on_connection_error(50.0) def max_temp(self) -> float: """Return the maximum temperature.""" return self._controller.temp_max @@ -453,14 +479,12 @@ class ZoneDevice(ClimateDevice): return False @property + @_return_on_connection_error(0) def supported_features(self): """Return the list of supported features.""" - try: - if self._zone.mode == Zone.Mode.AUTO: - return self._supported_features - return self._supported_features & ~SUPPORT_TARGET_TEMPERATURE - except ConnectionError: - return None + if self._zone.mode == Zone.Mode.AUTO: + return self._supported_features + return self._supported_features & ~SUPPORT_TARGET_TEMPERATURE @property def temperature_unit(self): diff --git a/homeassistant/components/izone/const.py b/homeassistant/components/izone/const.py index 4da7bc9e4af..fdee8dc7228 100644 --- a/homeassistant/components/izone/const.py +++ b/homeassistant/components/izone/const.py @@ -7,7 +7,7 @@ DATA_CONFIG = "izone_config" DISPATCH_CONTROLLER_DISCOVERED = "izone_controller_discovered" DISPATCH_CONTROLLER_DISCONNECTED = "izone_controller_disconnected" -DISPATCH_CONTROLLER_RECONNECTED = "izone_controller_disconnected" +DISPATCH_CONTROLLER_RECONNECTED = "izone_controller_reconnected" DISPATCH_CONTROLLER_UPDATE = "izone_controller_update" DISPATCH_ZONE_UPDATE = "izone_zone_update" diff --git a/homeassistant/components/izone/manifest.json b/homeassistant/components/izone/manifest.json index b8bb5b55b79..9e982b19cf8 100644 --- a/homeassistant/components/izone/manifest.json +++ b/homeassistant/components/izone/manifest.json @@ -2,7 +2,7 @@ "domain": "izone", "name": "iZone", "documentation": "https://www.home-assistant.io/integrations/izone", - "requirements": ["python-izone==1.1.1"], + "requirements": ["python-izone==1.1.2"], "dependencies": [], "codeowners": ["@Swamp-Ig"], "config_flow": true diff --git a/requirements_all.txt b/requirements_all.txt index 2a0b30032c4..07635c17435 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1611,7 +1611,7 @@ python-gitlab==1.6.0 python-hpilo==4.3 # homeassistant.components.izone -python-izone==1.1.1 +python-izone==1.1.2 # homeassistant.components.joaoapps_join python-join-api==0.0.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 81fed9172d2..90c8acb9df0 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -575,7 +575,7 @@ python-ecobee-api==0.2.2 python-forecastio==1.4.0 # homeassistant.components.izone -python-izone==1.1.1 +python-izone==1.1.2 # homeassistant.components.xiaomi_miio python-miio==0.4.8