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 14 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
5 changes: 5 additions & 0 deletions homeassistant/components/matter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def primary_attribute(self) -> type[ClusterAttributeDescriptor]:
"""Return Primary Attribute belonging to the entity."""
return self.attributes_to_watch[0]

@property
def secondary_attribute(self) -> type[ClusterAttributeDescriptor]:
"""Return Secondary Attribute belonging to the entity."""
return self.attributes_to_watch[1]

marcelveldt marked this conversation as resolved.
Show resolved Hide resolved

@dataclass
class MatterDiscoverySchema:
Expand Down
51 changes: 50 additions & 1 deletion homeassistant/components/matter/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any

from chip.clusters import Objects as clusters
from chip.clusters.Types import Nullable
Expand Down Expand Up @@ -46,6 +47,9 @@ async def async_setup_entry(
class MatterSelectEntityDescription(SelectEntityDescription, MatterEntityDescription):
"""Describe Matter select entities."""

command: Callable[[], Any] | None = None
field: str | None = None
marcelveldt marked this conversation as resolved.
Show resolved Hide resolved


class MatterSelectEntity(MatterEntity, SelectEntity):
"""Representation of a select entity from Matter Attribute read/write."""
Expand Down Expand Up @@ -111,6 +115,37 @@ def _update_from_device(self) -> None:
self._attr_name = desc


class MatterListSelectEntity(MatterSelectEntity):
"""Representation of a select entity from Matter list and selected item Cluster attribute(s)."""

async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
# select the ID from the label string
option_id = self._attr_options.index(option)
# field = self.entity_description.field
marcelveldt marked this conversation as resolved.
Show resolved Hide resolved

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

@callback
def _update_from_device(self) -> None:
"""Update from device."""
select_list = self.get_matter_attribute_value(
self._entity_info.secondary_attribute
)
marcelveldt marked this conversation as resolved.
Show resolved Hide resolved
current_option = self.get_matter_attribute_value(
self._entity_info.primary_attribute
)
self._attr_options = list(select_list)
self._attr_current_option = select_list[current_option]


# Discovery schema(s) to map Matter Attributes to HA entities
DISCOVERY_SCHEMAS = [
MatterDiscoverySchema(
Expand Down Expand Up @@ -254,4 +289,18 @@ 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",
command=clusters.TemperatureControl.Commands.SetTemperature,
# field=clusters.TemperatureControl.Commands.SetTemperature.targetTemperatureLevel,
marcelveldt marked this conversation as resolved.
Show resolved Hide resolved
),
entity_class=MatterListSelectEntity,
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