diff --git a/custom_components/echonetlite/__init__.py b/custom_components/echonetlite/__init__.py index f9ad02d..78f1fce 100644 --- a/custom_components/echonetlite/__init__.py +++ b/custom_components/echonetlite/__init__.py @@ -210,27 +210,26 @@ def __init__(self, instance, api, entry): # Detect HVAC - eventually we will use factory here. self._update_flags_full_list = [] + flags = [] if self._eojgc == 1 and self._eojcc == 48: - _LOGGER.debug(f"Create new HomeAirConditioner instance for: {self._eojgc}-{self._eojcc}-{self._eojci}") - for value in HVAC_API_CONNECTOR_DEFAULT_FLAGS: - if value in self._getPropertyMap: - self._update_flags_full_list.append(value) - self._instance = echonet.HomeAirConditioner(self._host, self._api) + _LOGGER.debug(f"Create new HomeAirConditioner instance at: {self._host}") + flags = HVAC_API_CONNECTOR_DEFAULT_FLAGS elif self._eojgc == 2 and self._eojcc == 144: - _LOGGER.debug(f"Create new GeneralLighting instance for: {self._eojgc}-{self._eojcc}-{self._eojci}") - for value in LIGHT_API_CONNECTOR_DEFAULT_FLAGS: - if value in self._getPropertyMap: - self._update_flags_full_list.append(value) - self._instance = echonet.GeneralLighting(self._host, self._api, self._eojci) + _LOGGER.debug(f"Create new GeneralLighting instance at: {self._host}") + flags = LIGHT_API_CONNECTOR_DEFAULT_FLAGS else: - _LOGGER.debug(f"Create new default instance for: {self._eojgc}-{self._eojcc}-{self._eojci}") - self._update_flags_full_list = [ENL_STATUS] + _LOGGER.debug(f"Create new Generic instance for {self._eojgc}-{self._eojcc}-{self._eojci} at {self._host}") + flags = [ENL_STATUS] for item in self._getPropertyMap: if item not in list(EPC_SUPER.keys()): if item in list(EPC_CODE[self._eojgc][self._eojcc].keys()): - self._update_flags_full_list.append(item) + flags.append(item) - self._instance = echonet.Factory(self._host, self._api, self._eojgc, self._eojcc, self._eojci) + for value in flags: + if value in self._getPropertyMap: + self._update_flags_full_list.append(value) + self._update_data[value] = None + self._instance = echonet.Factory(self._host, self._api, self._eojgc, self._eojcc, self._eojci) # Split list of codes into batches of 10 start_index = 0 diff --git a/custom_components/echonetlite/climate.py b/custom_components/echonetlite/climate.py index bcb5816..86bfd9e 100644 --- a/custom_components/echonetlite/climate.py +++ b/custom_components/echonetlite/climate.py @@ -151,7 +151,12 @@ def target_temperature_step(self): @property def hvac_mode(self): """Return current operation ie. heat, cool, idle.""" - return self._connector._update_data[ENL_HVAC_MODE] if self._connector._update_data[ENL_STATUS] == "On" else "off" + if self._connector._update_data[ENL_STATUS] == "On": + if self._connector._update_data[ENL_HVAC_MODE] == 'auto': + return HVAC_MODE_HEAT_COOL + else: + return self._connector._update_data[ENL_HVAC_MODE] + return "off" @property def hvac_action(self): diff --git a/custom_components/echonetlite/sensor.py b/custom_components/echonetlite/sensor.py index 62b9504..e68780f 100644 --- a/custom_components/echonetlite/sensor.py +++ b/custom_components/echonetlite/sensor.py @@ -138,9 +138,11 @@ def device_info(self): @property def native_value(self) -> StateType: """Return the state of the sensor.""" - if self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_TEMPERATURE: + if self._instance._update_data[self._op_code] is None: + return STATE_UNAVAILABLE + elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_TEMPERATURE: if self._op_code in self._instance._update_data: - if self._instance._update_data[self._op_code] == 126 or self._instance._update_data[self._op_code] is None: + if self._instance._update_data[self._op_code] == 126: return STATE_UNAVAILABLE else: return self._instance._update_data[self._op_code]