From b73c9a0e042b7bb7ea7386d6dac0a9d228643176 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Tue, 2 Jul 2024 13:10:36 +0200 Subject: [PATCH 1/6] Only use separate temperature setpoints if the device supports that --- homeassistant/components/matter/climate.py | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/matter/climate.py b/homeassistant/components/matter/climate.py index c97124f4305705..91cc6ac4e75b4a 100644 --- a/homeassistant/components/matter/climate.py +++ b/homeassistant/components/matter/climate.py @@ -267,19 +267,16 @@ def _update_from_device(self) -> None: self._attr_hvac_action = HVACAction.FAN case _: self._attr_hvac_action = HVACAction.OFF - # update target_temperature - if self._attr_hvac_mode == HVACMode.HEAT_COOL: - self._attr_target_temperature = None - elif self._attr_hvac_mode == HVACMode.COOL: - self._attr_target_temperature = self._get_temperature_in_degrees( - clusters.Thermostat.Attributes.OccupiedCoolingSetpoint - ) - else: - self._attr_target_temperature = self._get_temperature_in_degrees( - clusters.Thermostat.Attributes.OccupiedHeatingSetpoint - ) # update target temperature high/low - if self._attr_hvac_mode == HVACMode.HEAT_COOL: + supports_range = ( + self._attr_supported_features + & ClimateEntityFeature.TARGET_TEMPERATURE_RANGE + ) + if supports_range and self._attr_hvac_mode in ( + HVACMode.HEAT_COOL, + HVACMode.AUTO, + ): + self._attr_target_temperature = None self._attr_target_temperature_high = self._get_temperature_in_degrees( clusters.Thermostat.Attributes.OccupiedCoolingSetpoint ) @@ -289,6 +286,16 @@ def _update_from_device(self) -> None: else: self._attr_target_temperature_high = None self._attr_target_temperature_low = None + # update target_temperature + if self._attr_hvac_mode == HVACMode.COOL: + self._attr_target_temperature = self._get_temperature_in_degrees( + clusters.Thermostat.Attributes.OccupiedCoolingSetpoint + ) + else: + self._attr_target_temperature = self._get_temperature_in_degrees( + clusters.Thermostat.Attributes.OccupiedHeatingSetpoint + ) + # update min_temp if self._attr_hvac_mode == HVACMode.COOL: attribute = clusters.Thermostat.Attributes.AbsMinCoolSetpointLimit From 22fa520a5cfd52282239979a4f1acd7a91fc1dc4 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Tue, 2 Jul 2024 13:33:38 +0200 Subject: [PATCH 2/6] map matter auto to HA auto mode --- homeassistant/components/matter/climate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/matter/climate.py b/homeassistant/components/matter/climate.py index 91cc6ac4e75b4a..6fb5b3bb5f8a3d 100644 --- a/homeassistant/components/matter/climate.py +++ b/homeassistant/components/matter/climate.py @@ -39,7 +39,7 @@ TEMPERATURE_SCALING_FACTOR = 100 HVAC_SYSTEM_MODE_MAP = { HVACMode.OFF: 0, - HVACMode.HEAT_COOL: 1, + HVACMode.AUTO: 1, HVACMode.COOL: 3, HVACMode.HEAT: 4, HVACMode.DRY: 8, @@ -135,7 +135,7 @@ def __init__( if (vendor_id, product_id) in SUPPORT_FAN_MODE_DEVICES: self._attr_hvac_modes.append(HVACMode.FAN_ONLY) if feature_map & ThermostatFeature.kAutoMode: - self._attr_hvac_modes.append(HVACMode.HEAT_COOL) + self._attr_hvac_modes.append(HVACMode.AUTO) # only enable temperature_range feature if the device actually supports that if (vendor_id, product_id) not in SINGLE_SETPOINT_DEVICES: @@ -233,7 +233,7 @@ def _update_from_device(self) -> None: ) match system_mode_value: case SystemModeEnum.kAuto: - self._attr_hvac_mode = HVACMode.HEAT_COOL + self._attr_hvac_mode = HVACMode.AUTO case SystemModeEnum.kDry: self._attr_hvac_mode = HVACMode.DRY case SystemModeEnum.kFanOnly: From 179b0b356a6046cc2291afae7f21353917e0e4b7 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Tue, 2 Jul 2024 13:40:06 +0200 Subject: [PATCH 3/6] fix test --- tests/components/matter/test_climate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/components/matter/test_climate.py b/tests/components/matter/test_climate.py index 6a4cf34a640774..9e43057c4be940 100644 --- a/tests/components/matter/test_climate.py +++ b/tests/components/matter/test_climate.py @@ -74,7 +74,7 @@ async def test_thermostat_base( HVACMode.OFF, HVACMode.HEAT, HVACMode.COOL, - HVACMode.HEAT_COOL, + HVACMode.AUTO, ] # test system mode update from device @@ -221,12 +221,12 @@ async def test_thermostat_service_calls( ) matter_client.write_attribute.reset_mock() - # test dual setpoint temperature adjustments when heat_cool mode is active + # test dual setpoint temperature adjustments when AUTO mode is active set_node_attribute(thermostat, 1, 513, 28, 1) await trigger_subscription_callback(hass, matter_client) state = hass.states.get("climate.longan_link_hvac_thermostat") assert state - assert state.state == HVACMode.HEAT_COOL + assert state.state == HVACMode.AUTO await hass.services.async_call( "climate", @@ -330,7 +330,7 @@ async def test_room_airconditioner( HVACMode.COOL, HVACMode.DRY, HVACMode.FAN_ONLY, - HVACMode.HEAT_COOL, + HVACMode.AUTO, ] # test fan-only hvac mode set_node_attribute(room_airconditioner, 1, 513, 28, 7) From 33140c754f3f429a2b221635c91f3b7702157a2d Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Tue, 2 Jul 2024 14:40:04 +0200 Subject: [PATCH 4/6] revert to HEAT_COOL --- homeassistant/components/matter/climate.py | 8 ++++---- tests/components/matter/test_climate.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/matter/climate.py b/homeassistant/components/matter/climate.py index 6fb5b3bb5f8a3d..8f711160822ef5 100644 --- a/homeassistant/components/matter/climate.py +++ b/homeassistant/components/matter/climate.py @@ -39,7 +39,7 @@ TEMPERATURE_SCALING_FACTOR = 100 HVAC_SYSTEM_MODE_MAP = { HVACMode.OFF: 0, - HVACMode.AUTO: 1, + HVACMode.HEAT_COOL: 1, HVACMode.COOL: 3, HVACMode.HEAT: 4, HVACMode.DRY: 8, @@ -135,7 +135,7 @@ def __init__( if (vendor_id, product_id) in SUPPORT_FAN_MODE_DEVICES: self._attr_hvac_modes.append(HVACMode.FAN_ONLY) if feature_map & ThermostatFeature.kAutoMode: - self._attr_hvac_modes.append(HVACMode.AUTO) + self._attr_hvac_modes.append(HVACMode.HEAT_COOL) # only enable temperature_range feature if the device actually supports that if (vendor_id, product_id) not in SINGLE_SETPOINT_DEVICES: @@ -233,7 +233,7 @@ def _update_from_device(self) -> None: ) match system_mode_value: case SystemModeEnum.kAuto: - self._attr_hvac_mode = HVACMode.AUTO + self._attr_hvac_mode = HVACMode.HEAT_COOL case SystemModeEnum.kDry: self._attr_hvac_mode = HVACMode.DRY case SystemModeEnum.kFanOnly: @@ -274,7 +274,7 @@ def _update_from_device(self) -> None: ) if supports_range and self._attr_hvac_mode in ( HVACMode.HEAT_COOL, - HVACMode.AUTO, + HVACMode.HEAT_COOL, ): self._attr_target_temperature = None self._attr_target_temperature_high = self._get_temperature_in_degrees( diff --git a/tests/components/matter/test_climate.py b/tests/components/matter/test_climate.py index 9e43057c4be940..6d09e48ed8d9cb 100644 --- a/tests/components/matter/test_climate.py +++ b/tests/components/matter/test_climate.py @@ -74,7 +74,7 @@ async def test_thermostat_base( HVACMode.OFF, HVACMode.HEAT, HVACMode.COOL, - HVACMode.AUTO, + HVACMode.HEAT_COOL, ] # test system mode update from device @@ -221,12 +221,12 @@ async def test_thermostat_service_calls( ) matter_client.write_attribute.reset_mock() - # test dual setpoint temperature adjustments when AUTO mode is active + # test dual setpoint temperature adjustments when HEAT_COOL mode is active set_node_attribute(thermostat, 1, 513, 28, 1) await trigger_subscription_callback(hass, matter_client) state = hass.states.get("climate.longan_link_hvac_thermostat") assert state - assert state.state == HVACMode.AUTO + assert state.state == HVACMode.HEAT_COOL await hass.services.async_call( "climate", @@ -330,7 +330,7 @@ async def test_room_airconditioner( HVACMode.COOL, HVACMode.DRY, HVACMode.FAN_ONLY, - HVACMode.AUTO, + HVACMode.HEAT_COOL, ] # test fan-only hvac mode set_node_attribute(room_airconditioner, 1, 513, 28, 7) From 05d93fe74e4cdeac5f7420e136a501beed8d57eb Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Tue, 2 Jul 2024 14:44:13 +0200 Subject: [PATCH 5/6] cleanup --- homeassistant/components/matter/climate.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/homeassistant/components/matter/climate.py b/homeassistant/components/matter/climate.py index 8f711160822ef5..2c05fd3373ee4c 100644 --- a/homeassistant/components/matter/climate.py +++ b/homeassistant/components/matter/climate.py @@ -272,10 +272,7 @@ def _update_from_device(self) -> None: self._attr_supported_features & ClimateEntityFeature.TARGET_TEMPERATURE_RANGE ) - if supports_range and self._attr_hvac_mode in ( - HVACMode.HEAT_COOL, - HVACMode.HEAT_COOL, - ): + if supports_range and self._attr_hvac_mode == HVACMode.HEAT_COOL: self._attr_target_temperature = None self._attr_target_temperature_high = self._get_temperature_in_degrees( clusters.Thermostat.Attributes.OccupiedCoolingSetpoint From 2c92e67994d6dbbd5bf77e0dc7fff587703eb34c Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Tue, 2 Jul 2024 14:46:02 +0200 Subject: [PATCH 6/6] more cleanup --- tests/components/matter/test_climate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/matter/test_climate.py b/tests/components/matter/test_climate.py index 6d09e48ed8d9cb..6a4cf34a640774 100644 --- a/tests/components/matter/test_climate.py +++ b/tests/components/matter/test_climate.py @@ -221,7 +221,7 @@ async def test_thermostat_service_calls( ) matter_client.write_attribute.reset_mock() - # test dual setpoint temperature adjustments when HEAT_COOL mode is active + # test dual setpoint temperature adjustments when heat_cool mode is active set_node_attribute(thermostat, 1, 513, 28, 1) await trigger_subscription_callback(hass, matter_client) state = hass.states.get("climate.longan_link_hvac_thermostat")