Add Matter Thermostat OutdoorTemperature sensor (#152632)

This commit is contained in:
Ludovic BOUÉ
2025-09-23 21:28:24 +02:00
committed by GitHub
parent 2ab051b716
commit ca186925af
5 changed files with 99 additions and 0 deletions

View File

@@ -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(

View File

@@ -485,6 +485,9 @@
"apparent_current": {
"name": "Apparent current"
},
"outdoor_temperature": {
"name": "Outdoor temperature"
},
"reactive_current": {
"name": "Reactive current"
},

View File

@@ -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,

View File

@@ -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': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'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': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 1,
}),
}),
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>,
'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': <UnitOfTemperature.CELSIUS: '°C'>,
})
# ---
# 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': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
}),
'context': <ANY>,
'entity_id': 'sensor.longan_link_hvac_outdoor_temperature',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '12.5',
})
# ---
# name: test_sensors[thermostat][sensor.longan_link_hvac_temperature-entry]
EntityRegistryEntrySnapshot({
'aliases': set({

View File

@@ -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,