From cf9692e645ee6acc1635b543d23aa08f199e2c5c Mon Sep 17 00:00:00 2001 From: scottyphillips Date: Mon, 21 Feb 2022 17:47:36 +1100 Subject: [PATCH] Bug fixes --- custom_components/echonetlite/__init__.py | 2 +- custom_components/echonetlite/climate.py | 9 ++-- custom_components/echonetlite/manifest.json | 2 +- custom_components/echonetlite/sensor.py | 49 +++++++++++---------- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/custom_components/echonetlite/__init__.py b/custom_components/echonetlite/__init__.py index 78f1fce..d7824c6 100644 --- a/custom_components/echonetlite/__init__.py +++ b/custom_components/echonetlite/__init__.py @@ -286,7 +286,7 @@ async def async_update(self, **kwargs): # polling succeded. if retry > 1: _LOGGER.debug(f"polling ECHONET Instance host {self._host} succeeded - Retry {retry} of 3") - self._update_data = update_data + self._update_data.update(update_data) return self._update_data else: _LOGGER.debug(f"polling ECHONET Instance host {self._host} timed out - Retry {retry} of 3") diff --git a/custom_components/echonetlite/climate.py b/custom_components/echonetlite/climate.py index 333ef70..af2dc12 100644 --- a/custom_components/echonetlite/climate.py +++ b/custom_components/echonetlite/climate.py @@ -174,10 +174,11 @@ def hvac_action(self): elif (self._connector._update_data[ENL_HVAC_MODE] == HVAC_MODE_HEAT_COOL or self._connector._update_data[ENL_HVAC_MODE] == "auto"): if ENL_HVAC_ROOM_TEMP in self._connector._update_data: - if self._connector._update_data[ENL_HVAC_SET_TEMP] < self._connector._update_data[ENL_HVAC_ROOM_TEMP]: - return CURRENT_HVAC_COOL - elif self._connector._update_data[ENL_HVAC_SET_TEMP] > self._connector._update_data[ENL_HVAC_ROOM_TEMP]: - return CURRENT_HVAC_HEAT + if ENL_HVAC_ROOM_TEMP is not None: + if self._connector._update_data[ENL_HVAC_SET_TEMP] < self._connector._update_data[ENL_HVAC_ROOM_TEMP]: + return CURRENT_HVAC_COOL + elif self._connector._update_data[ENL_HVAC_SET_TEMP] > self._connector._update_data[ENL_HVAC_ROOM_TEMP]: + return CURRENT_HVAC_HEAT return CURRENT_HVAC_IDLE else: _LOGGER.warning(f"Unknown HVAC mode {self._connector._update_data[ENL_HVAC_MODE]}") diff --git a/custom_components/echonetlite/manifest.json b/custom_components/echonetlite/manifest.json index 236b081..08945df 100644 --- a/custom_components/echonetlite/manifest.json +++ b/custom_components/echonetlite/manifest.json @@ -12,6 +12,6 @@ "codeowners": [ "@scottyphillips" ], - "version": "3.3.0", + "version": "3.3.1", "iot_class": "local_polling" } diff --git a/custom_components/echonetlite/sensor.py b/custom_components/echonetlite/sensor.py index 1215b31..e06540a 100644 --- a/custom_components/echonetlite/sensor.py +++ b/custom_components/echonetlite/sensor.py @@ -142,34 +142,35 @@ def device_info(self): @property def native_value(self) -> StateType: """Return the state of the sensor.""" - if self._instance._update_data[self._op_code] is None: - return STATE_UNAVAILABLE - elif self._sensor_attributes[CONF_TYPE] in [ - DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY - ]: - if self._op_code in self._instance._update_data: - if self._instance._update_data[self._op_code] in [126, 253]: + if self._op_code in self._instance._update_data: + if self._instance._update_data[self._op_code] is None: + return STATE_UNAVAILABLE + elif self._sensor_attributes[CONF_TYPE] in [ + DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY + ]: + if self._op_code in self._instance._update_data: + if self._instance._update_data[self._op_code] in [126, 253]: + return STATE_UNAVAILABLE + else: + return self._instance._update_data[self._op_code] + else: return STATE_UNAVAILABLE + elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_POWER: + if self._op_code in self._instance._update_data: + # Underflow (less than 1 W) + if self._instance._update_data[self._op_code] == 65534: + return 1 + else: + return self._instance._update_data[self._op_code] else: + return STATE_UNAVAILABLE + elif self._op_code in self._instance._update_data: + if isinstance(self._instance._update_data[self._op_code], (int, float)): return self._instance._update_data[self._op_code] - else: - return STATE_UNAVAILABLE - elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_POWER: - if self._op_code in self._instance._update_data: - # Underflow (less than 1 W) - if self._instance._update_data[self._op_code] == 65534: - return 1 - else: + if len(self._instance._update_data[self._op_code]) < 255: return self._instance._update_data[self._op_code] - else: - return STATE_UNAVAILABLE - elif self._op_code in self._instance._update_data: - if isinstance(self._instance._update_data[self._op_code], (int, float)): - return self._instance._update_data[self._op_code] - if len(self._instance._update_data[self._op_code]) < 255: - return self._instance._update_data[self._op_code] - else: - return STATE_UNAVAILABLE + else: + return STATE_UNAVAILABLE return None @property