diff --git a/homeassistant/components/matter/sensor.py b/homeassistant/components/matter/sensor.py index f5f1fe0e73e..b8249e9efa3 100644 --- a/homeassistant/components/matter/sensor.py +++ b/homeassistant/components/matter/sensor.py @@ -152,6 +152,8 @@ PUMP_CONTROL_MODE_MAP = { clusters.PumpConfigurationAndControl.Enums.ControlModeEnum.kUnknownEnumValue: None, } +TEMPERATURE_SCALING_FACTOR = 100 + async def async_setup_entry( hass: HomeAssistant, @@ -1141,6 +1143,23 @@ DISCOVERY_SCHEMAS = [ device_type=(device_types.Thermostat,), allow_multi=True, # also used for climate entity ), + MatterDiscoverySchema( + platform=Platform.SENSOR, + entity_description=MatterSensorEntityDescription( + key="ThermostatOutdoorTemperature", + translation_key="outdoor_temperature", + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + suggested_display_precision=1, + device_class=SensorDeviceClass.TEMPERATURE, + device_to_ha=lambda x: ( + None if x is None else x / TEMPERATURE_SCALING_FACTOR + ), + state_class=SensorStateClass.MEASUREMENT, + ), + entity_class=MatterSensor, + required_attributes=(clusters.Thermostat.Attributes.OutdoorTemperature,), + device_type=(device_types.Thermostat, device_types.RoomAirConditioner), + ), MatterDiscoverySchema( platform=Platform.SENSOR, entity_description=MatterOperationalStateSensorEntityDescription( diff --git a/homeassistant/components/matter/strings.json b/homeassistant/components/matter/strings.json index 7dae7638d8d..85ad6527653 100644 --- a/homeassistant/components/matter/strings.json +++ b/homeassistant/components/matter/strings.json @@ -485,6 +485,9 @@ "apparent_current": { "name": "Apparent current" }, + "outdoor_temperature": { + "name": "Outdoor temperature" + }, "reactive_current": { "name": "Reactive current" }, diff --git a/tests/components/matter/fixtures/nodes/thermostat.json b/tests/components/matter/fixtures/nodes/thermostat.json index a7abff41331..bb42b8926b9 100644 --- a/tests/components/matter/fixtures/nodes/thermostat.json +++ b/tests/components/matter/fixtures/nodes/thermostat.json @@ -317,6 +317,7 @@ "1/64/65529": [], "1/64/65531": [0, 65528, 65529, 65531, 65532, 65533], "1/513/0": 2830, + "1/513/1": 1250, "1/513/3": null, "1/513/4": null, "1/513/5": null, diff --git a/tests/components/matter/snapshots/test_sensor.ambr b/tests/components/matter/snapshots/test_sensor.ambr index 2567ce2e936..911ea004995 100644 --- a/tests/components/matter/snapshots/test_sensor.ambr +++ b/tests/components/matter/snapshots/test_sensor.ambr @@ -6847,6 +6847,62 @@ 'state': '21.0', }) # --- +# name: test_sensors[thermostat][sensor.longan_link_hvac_outdoor_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.longan_link_hvac_outdoor_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 1, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Outdoor temperature', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'outdoor_temperature', + 'unique_id': '00000000000004D2-0000000000000004-MatterNodeDevice-1-ThermostatOutdoorTemperature-513-1', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[thermostat][sensor.longan_link_hvac_outdoor_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'Longan link HVAC Outdoor temperature', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.longan_link_hvac_outdoor_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '12.5', + }) +# --- # name: test_sensors[thermostat][sensor.longan_link_hvac_temperature-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/matter/test_sensor.py b/tests/components/matter/test_sensor.py index 2254c021c6a..2414bafc80d 100644 --- a/tests/components/matter/test_sensor.py +++ b/tests/components/matter/test_sensor.py @@ -233,6 +233,26 @@ async def test_eve_thermo_sensor( assert state.state == "18.0" +@pytest.mark.parametrize("node_fixture", ["thermostat"]) +async def test_thermostat_outdoor( + hass: HomeAssistant, + matter_client: MagicMock, + matter_node: MatterNode, +) -> None: + """Test OutdoorTemperature.""" + # OutdoorTemperature + state = hass.states.get("sensor.longan_link_hvac_outdoor_temperature") + assert state + assert state.state == "12.5" + + set_node_attribute(matter_node, 1, 513, 1, -550) + await trigger_subscription_callback(hass, matter_client) + + state = hass.states.get("sensor.longan_link_hvac_outdoor_temperature") + assert state + assert state.state == "-5.5" + + @pytest.mark.parametrize("node_fixture", ["pressure_sensor"]) async def test_pressure_sensor( hass: HomeAssistant,