diff --git a/custom_components/better_thermostat/events/trv.py b/custom_components/better_thermostat/events/trv.py index 2d608129..0a8543f0 100644 --- a/custom_components/better_thermostat/events/trv.py +++ b/custom_components/better_thermostat/events/trv.py @@ -354,34 +354,28 @@ def convert_outbound_states(self, entity_id, hvac_mode) -> dict | None: ) _system_modes = self.real_trvs[entity_id]["hvac_modes"] - _has_system_mode = False - if _system_modes is not None: - _has_system_mode = True + _has_system_mode = _system_modes is not None # Handling different devices with or without system mode reported or contained in the device config hvac_mode = mode_remap(self, entity_id, str(hvac_mode), False) - if _has_system_mode is False: + if not _has_system_mode: _LOGGER.debug( f"better_thermostat {self.device_name}: device config expects no system mode, while the device has one. Device system mode will be ignored" ) if hvac_mode == HVACMode.OFF: _new_heating_setpoint = self.real_trvs[entity_id]["min_temp"] hvac_mode = None - if ( - HVACMode.OFF not in _system_modes - or self.real_trvs[entity_id]["advanced"].get( - "no_off_system_mode", False - ) - is True + if hvac_mode == HVACMode.OFF and ( + HVACMode.OFF not in _system_modes or + self.real_trvs[entity_id]["advanced"].get("no_off_system_mode") ): - if hvac_mode == HVACMode.OFF: - _LOGGER.debug( - f"better_thermostat {self.device_name}: sending 5°C to the TRV because this device has no system mode off and heater should be off" - ) - _new_heating_setpoint = self.real_trvs[entity_id]["min_temp"] - hvac_mode = None + _LOGGER.debug( + f"better_thermostat {self.device_name}: sending 5°C to the TRV because this device has no system mode off and heater should be off" + ) + _new_heating_setpoint = self.real_trvs[entity_id]["min_temp"] + hvac_mode = None return { "temperature": _new_heating_setpoint, diff --git a/custom_components/better_thermostat/utils/helpers.py b/custom_components/better_thermostat/utils/helpers.py index e546a905..f619ecba 100644 --- a/custom_components/better_thermostat/utils/helpers.py +++ b/custom_components/better_thermostat/utils/helpers.py @@ -45,20 +45,27 @@ def mode_remap(self, entity_id, hvac_mode: str, inbound: bool = False) -> str: ) if _heat_auto_swapped: - if hvac_mode == HVACMode.HEAT and inbound is False: + if hvac_mode == HVACMode.HEAT and not inbound: return HVACMode.AUTO - elif hvac_mode == HVACMode.AUTO and inbound is True: + if hvac_mode == HVACMode.AUTO and inbound: return HVACMode.HEAT - else: - return hvac_mode - else: - if hvac_mode != HVACMode.AUTO: - return hvac_mode - else: - _LOGGER.error( - f"better_thermostat {self.device_name}: {entity_id} HVAC mode {hvac_mode} is not supported by this device, is it possible that you forgot to set the heat auto swapped option?" - ) - return HVACMode.OFF + return hvac_mode + + trv_modes = self.real_trvs[entity_id]["hvac_modes"] + if not HVACMode.HEAT in trv_modes and HVACMode.HEAT_COOL in trv_modes: + # entity only supports HEAT_COOL, but not HEAT - need to translate + if not inbound and hvac_mode = HVACMode.HEAT: + return HVACMode.HEAT_COOL + if inbound and hvac_mode = HVACMode.HEAT_COOL: + return HVACMode.HEAT + + if hvac_mode != HVACMode.AUTO: + return hvac_mode + + _LOGGER.error( + f"better_thermostat {self.device_name}: {entity_id} HVAC mode {hvac_mode} is not supported by this device, is it possible that you forgot to set the heat auto swapped option?" + ) + return HVACMode.OFF def heating_power_valve_position(self, entity_id):