Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matter TemperatureLevel feature from TemperatureControl cluster #134532

Merged
merged 23 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions homeassistant/components/matter/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
}
}
},
"select": {
"temperature_level": {
"default": "mdi:thermometer"
}
},
"sensor": {
"contamination_state": {
"default": "mdi:air-filter"
Expand Down
41 changes: 41 additions & 0 deletions homeassistant/components/matter/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,35 @@ def _update_from_device(self) -> None:
self._attr_name = desc


class MatterLevelSelectEntity(MatterSelectEntity):
marcelveldt marked this conversation as resolved.
Show resolved Hide resolved
"""Representation of a select entity from Matter (TemperatureControl) Cluster attribute(s)."""

async def async_select_option(self, option: str) -> None:
"""Change the selected level."""
# select the level ID from the label string
level_id = self._attr_options.index(option)

await self.matter_client.send_device_command(
node_id=self._endpoint.node.node_id,
endpoint_id=self._endpoint.endpoint_id,
command=clusters.TemperatureControl.Commands.SetTemperature(
targetTemperatureLevel=level_id
),
)

@callback
def _update_from_device(self) -> None:
"""Update from device."""
temperature_level_list = self.get_matter_attribute_value(
clusters.TemperatureControl.Attributes.SupportedTemperatureLevels
)
selected_level = self.get_matter_attribute_value(
clusters.TemperatureControl.Attributes.SelectedTemperatureLevel
)
self._attr_options = list(temperature_level_list)
self._attr_current_option = temperature_level_list[selected_level]


# Discovery schema(s) to map Matter Attributes to HA entities
DISCOVERY_SCHEMAS = [
MatterDiscoverySchema(
Expand Down Expand Up @@ -254,4 +283,16 @@ def _update_from_device(self) -> None:
entity_class=MatterSelectEntity,
required_attributes=(clusters.SmokeCoAlarm.Attributes.SmokeSensitivityLevel,),
),
MatterDiscoverySchema(
platform=Platform.SELECT,
entity_description=MatterSelectEntityDescription(
key="TemperatureControlSelectedTemperatureLevel",
translation_key="temperature_level",
),
entity_class=MatterLevelSelectEntity,
required_attributes=(
clusters.TemperatureControl.Attributes.SelectedTemperatureLevel,
clusters.TemperatureControl.Attributes.SupportedTemperatureLevels,
),
),
]
3 changes: 3 additions & 0 deletions homeassistant/components/matter/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
"toggle": "[%key:common::action::toggle%]",
"previous": "Previous"
}
},
"temperature_level": {
"name": "Temperature level"
}
},
"sensor": {
Expand Down
1 change: 1 addition & 0 deletions tests/components/matter/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async def integration_fixture(
"pressure_sensor",
"room_airconditioner",
"silabs_dishwasher",
"silabs_laundrywasher",
"smoke_detector",
"switch_unit",
"temperature_sensor",
Expand Down
Loading
Loading