Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c92107b

Browse files
authored
Inherit MatterEntityDescription in Matter entities (home-assistant#154083)
1 parent b25622f commit c92107b

File tree

12 files changed

+106
-36
lines changed

12 files changed

+106
-36
lines changed

‎homeassistant/components/matter/climate.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
from enum import IntEnum
67
from typing import Any
78

@@ -26,7 +27,7 @@
2627
from homeassistant.core import HomeAssistant, callback
2728
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2829

29-
from .entity import MatterEntity
30+
from .entity import MatterEntity, MatterEntityDescription
3031
from .helpers import get_matter
3132
from .models import MatterDiscoverySchema
3233

@@ -182,6 +183,11 @@ async def async_setup_entry(
182183
matter.register_platform_handler(Platform.CLIMATE, async_add_entities)
183184

184185

186+
@dataclass(frozen=True)
187+
class MatterClimateEntityDescription(ClimateEntityDescription, MatterEntityDescription):
188+
"""Describe Matter Climate entities."""
189+
190+
185191
class MatterClimate(MatterEntity, ClimateEntity):
186192
"""Representation of a Matter climate entity."""
187193

@@ -423,7 +429,7 @@ def _get_temperature_in_degrees(
423429
DISCOVERY_SCHEMAS = [
424430
MatterDiscoverySchema(
425431
platform=Platform.CLIMATE,
426-
entity_description=ClimateEntityDescription(
432+
entity_description=MatterClimateEntityDescription(
427433
key="MatterThermostat",
428434
name=None,
429435
),

‎homeassistant/components/matter/cover.py‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
from enum import IntEnum
67
from math import floor
78
from typing import Any
@@ -22,7 +23,7 @@
2223
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2324

2425
from .const import LOGGER
25-
from .entity import MatterEntity
26+
from .entity import MatterEntity, MatterEntityDescription
2627
from .helpers import get_matter
2728
from .models import MatterDiscoverySchema
2829

@@ -61,10 +62,15 @@ async def async_setup_entry(
6162
matter.register_platform_handler(Platform.COVER, async_add_entities)
6263

6364

65+
@dataclass(frozen=True)
66+
class MatterCoverEntityDescription(CoverEntityDescription, MatterEntityDescription):
67+
"""Describe Matter Cover entities."""
68+
69+
6470
class MatterCover(MatterEntity, CoverEntity):
6571
"""Representation of a Matter Cover."""
6672

67-
entity_description: CoverEntityDescription
73+
entity_description: MatterCoverEntityDescription
6874

6975
@property
7076
def is_closed(self) -> bool | None:
@@ -198,7 +204,7 @@ def _update_from_device(self) -> None:
198204
DISCOVERY_SCHEMAS = [
199205
MatterDiscoverySchema(
200206
platform=Platform.COVER,
201-
entity_description=CoverEntityDescription(
207+
entity_description=MatterCoverEntityDescription(
202208
key="MatterCover",
203209
name=None,
204210
),
@@ -214,7 +220,7 @@ def _update_from_device(self) -> None:
214220
),
215221
MatterDiscoverySchema(
216222
platform=Platform.COVER,
217-
entity_description=CoverEntityDescription(
223+
entity_description=MatterCoverEntityDescription(
218224
key="MatterCoverPositionAwareLift", name=None
219225
),
220226
entity_class=MatterCover,
@@ -229,7 +235,7 @@ def _update_from_device(self) -> None:
229235
),
230236
MatterDiscoverySchema(
231237
platform=Platform.COVER,
232-
entity_description=CoverEntityDescription(
238+
entity_description=MatterCoverEntityDescription(
233239
key="MatterCoverPositionAwareTilt", name=None
234240
),
235241
entity_class=MatterCover,
@@ -244,7 +250,7 @@ def _update_from_device(self) -> None:
244250
),
245251
MatterDiscoverySchema(
246252
platform=Platform.COVER,
247-
entity_description=CoverEntityDescription(
253+
entity_description=MatterCoverEntityDescription(
248254
key="MatterCoverPositionAwareLiftAndTilt", name=None
249255
),
250256
entity_class=MatterCover,

‎homeassistant/components/matter/event.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
from typing import Any
67

78
from chip.clusters import Objects as clusters
@@ -18,7 +19,7 @@
1819
from homeassistant.core import HomeAssistant, callback
1920
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2021

21-
from .entity import MatterEntity
22+
from .entity import MatterEntity, MatterEntityDescription
2223
from .helpers import get_matter
2324
from .models import MatterDiscoverySchema
2425

@@ -46,6 +47,11 @@ async def async_setup_entry(
4647
matter.register_platform_handler(Platform.EVENT, async_add_entities)
4748

4849

50+
@dataclass(frozen=True)
51+
class MatterEventEntityDescription(EventEntityDescription, MatterEntityDescription):
52+
"""Describe Matter Event entities."""
53+
54+
4955
class MatterEventEntity(MatterEntity, EventEntity):
5056
"""Representation of a Matter Event entity."""
5157

@@ -132,7 +138,7 @@ def _on_matter_node_event(
132138
DISCOVERY_SCHEMAS = [
133139
MatterDiscoverySchema(
134140
platform=Platform.EVENT,
135-
entity_description=EventEntityDescription(
141+
entity_description=MatterEventEntityDescription(
136142
key="GenericSwitch",
137143
device_class=EventDeviceClass.BUTTON,
138144
translation_key="button",

‎homeassistant/components/matter/fan.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
from typing import TYPE_CHECKING, Any
67

78
from chip.clusters import Objects as clusters
@@ -18,7 +19,7 @@
1819
from homeassistant.core import HomeAssistant, callback
1920
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2021

21-
from .entity import MatterEntity
22+
from .entity import MatterEntity, MatterEntityDescription
2223
from .helpers import get_matter
2324
from .models import MatterDiscoverySchema
2425

@@ -52,6 +53,11 @@ async def async_setup_entry(
5253
matter.register_platform_handler(Platform.FAN, async_add_entities)
5354

5455

56+
@dataclass(frozen=True)
57+
class MatterFanEntityDescription(FanEntityDescription, MatterEntityDescription):
58+
"""Describe Matter Fan entities."""
59+
60+
5561
class MatterFan(MatterEntity, FanEntity):
5662
"""Representation of a Matter fan."""
5763

@@ -308,7 +314,7 @@ def _calculate_features(
308314
DISCOVERY_SCHEMAS = [
309315
MatterDiscoverySchema(
310316
platform=Platform.FAN,
311-
entity_description=FanEntityDescription(
317+
entity_description=MatterFanEntityDescription(
312318
key="MatterFan",
313319
name=None,
314320
),

‎homeassistant/components/matter/light.py‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
from typing import Any
67

78
from chip.clusters import Objects as clusters
@@ -29,7 +30,7 @@
2930
from homeassistant.util import color as color_util
3031

3132
from .const import LOGGER
32-
from .entity import MatterEntity
33+
from .entity import MatterEntity, MatterEntityDescription
3334
from .helpers import get_matter
3435
from .models import MatterDiscoverySchema
3536
from .util import (
@@ -85,10 +86,15 @@ async def async_setup_entry(
8586
matter.register_platform_handler(Platform.LIGHT, async_add_entities)
8687

8788

89+
@dataclass(frozen=True)
90+
class MatterLightEntityDescription(LightEntityDescription, MatterEntityDescription):
91+
"""Describe Matter Light entities."""
92+
93+
8894
class MatterLight(MatterEntity, LightEntity):
8995
"""Representation of a Matter light."""
9096

91-
entity_description: LightEntityDescription
97+
entity_description: MatterLightEntityDescription
9298
_supports_brightness = False
9399
_supports_color = False
94100
_supports_color_temperature = False
@@ -458,7 +464,7 @@ def _check_transition_blocklist(self) -> None:
458464
DISCOVERY_SCHEMAS = [
459465
MatterDiscoverySchema(
460466
platform=Platform.LIGHT,
461-
entity_description=LightEntityDescription(
467+
entity_description=MatterLightEntityDescription(
462468
key="MatterLight",
463469
name=None,
464470
),
@@ -487,7 +493,7 @@ def _check_transition_blocklist(self) -> None:
487493
# Additional schema to match (HS Color) lights with incorrect/missing device type
488494
MatterDiscoverySchema(
489495
platform=Platform.LIGHT,
490-
entity_description=LightEntityDescription(
496+
entity_description=MatterLightEntityDescription(
491497
key="MatterHSColorLightFallback",
492498
name=None,
493499
),
@@ -508,7 +514,7 @@ def _check_transition_blocklist(self) -> None:
508514
# Additional schema to match (XY Color) lights with incorrect/missing device type
509515
MatterDiscoverySchema(
510516
platform=Platform.LIGHT,
511-
entity_description=LightEntityDescription(
517+
entity_description=MatterLightEntityDescription(
512518
key="MatterXYColorLightFallback",
513519
name=None,
514520
),
@@ -529,7 +535,7 @@ def _check_transition_blocklist(self) -> None:
529535
# Additional schema to match (color temperature) lights with incorrect/missing device type
530536
MatterDiscoverySchema(
531537
platform=Platform.LIGHT,
532-
entity_description=LightEntityDescription(
538+
entity_description=MatterLightEntityDescription(
533539
key="MatterColorTemperatureLightFallback",
534540
name=None,
535541
),

‎homeassistant/components/matter/lock.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import asyncio
6+
from dataclasses import dataclass
67
from typing import Any
78

89
from chip.clusters import Objects as clusters
@@ -19,7 +20,7 @@
1920
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2021

2122
from .const import LOGGER
22-
from .entity import MatterEntity
23+
from .entity import MatterEntity, MatterEntityDescription
2324
from .helpers import get_matter
2425
from .models import MatterDiscoverySchema
2526

@@ -52,6 +53,11 @@ async def async_setup_entry(
5253
matter.register_platform_handler(Platform.LOCK, async_add_entities)
5354

5455

56+
@dataclass(frozen=True)
57+
class MatterLockEntityDescription(LockEntityDescription, MatterEntityDescription):
58+
"""Describe Matter Lock entities."""
59+
60+
5561
class MatterLock(MatterEntity, LockEntity):
5662
"""Representation of a Matter lock."""
5763

@@ -254,7 +260,7 @@ def _calculate_features(
254260
DISCOVERY_SCHEMAS = [
255261
MatterDiscoverySchema(
256262
platform=Platform.LOCK,
257-
entity_description=LockEntityDescription(
263+
entity_description=MatterLockEntityDescription(
258264
key="MatterLock",
259265
name=None,
260266
),

‎homeassistant/components/matter/models.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from matter_server.client.models.node import MatterEndpoint
1212

1313
from homeassistant.const import Platform
14-
from homeassistant.helpers.entity import EntityDescription
14+
15+
from .entity import MatterEntityDescription
1516

1617
type SensorValueTypes = type[
1718
clusters.uint | int | clusters.Nullable | clusters.float32 | float
@@ -54,7 +55,7 @@ class MatterEntityInfo:
5455
attributes_to_watch: list[type[ClusterAttributeDescriptor]]
5556

5657
# the entity description to use
57-
entity_description: EntityDescription
58+
entity_description: MatterEntityDescription
5859

5960
# entity class to use to instantiate the entity
6061
entity_class: type
@@ -80,7 +81,7 @@ class MatterDiscoverySchema:
8081
platform: Platform
8182

8283
# platform-specific entity description
83-
entity_description: EntityDescription
84+
entity_description: MatterEntityDescription
8485

8586
# entity class to use to instantiate the entity
8687
entity_class: type

‎homeassistant/components/matter/switch.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ async def async_setup_entry(
4242
matter.register_platform_handler(Platform.SWITCH, async_add_entities)
4343

4444

45+
@dataclass(frozen=True)
46+
class MatterSwitchEntityDescription(SwitchEntityDescription, MatterEntityDescription):
47+
"""Describe Matter Switch entities."""
48+
49+
4550
class MatterSwitch(MatterEntity, SwitchEntity):
4651
"""Representation of a Matter switch."""
4752

@@ -168,7 +173,7 @@ def _update_from_device(self) -> None:
168173
DISCOVERY_SCHEMAS = [
169174
MatterDiscoverySchema(
170175
platform=Platform.SWITCH,
171-
entity_description=SwitchEntityDescription(
176+
entity_description=MatterSwitchEntityDescription(
172177
key="MatterPlug",
173178
device_class=SwitchDeviceClass.OUTLET,
174179
name=None,
@@ -179,7 +184,7 @@ def _update_from_device(self) -> None:
179184
),
180185
MatterDiscoverySchema(
181186
platform=Platform.SWITCH,
182-
entity_description=SwitchEntityDescription(
187+
entity_description=MatterSwitchEntityDescription(
183188
key="MatterPowerToggle",
184189
device_class=SwitchDeviceClass.SWITCH,
185190
translation_key="power",
@@ -207,7 +212,7 @@ def _update_from_device(self) -> None:
207212
),
208213
MatterDiscoverySchema(
209214
platform=Platform.SWITCH,
210-
entity_description=SwitchEntityDescription(
215+
entity_description=MatterSwitchEntityDescription(
211216
key="MatterSwitch",
212217
device_class=SwitchDeviceClass.OUTLET,
213218
name=None,

‎homeassistant/components/matter/update.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from homeassistant.helpers.event import async_call_later
2626
from homeassistant.helpers.restore_state import ExtraStoredData
2727

28-
from .entity import MatterEntity
28+
from .entity import MatterEntity, MatterEntityDescription
2929
from .helpers import get_matter
3030
from .models import MatterDiscoverySchema
3131

@@ -67,6 +67,11 @@ async def async_setup_entry(
6767
matter.register_platform_handler(Platform.UPDATE, async_add_entities)
6868

6969

70+
@dataclass(frozen=True)
71+
class MatterUpdateEntityDescription(UpdateEntityDescription, MatterEntityDescription):
72+
"""Describe Matter Update entities."""
73+
74+
7075
class MatterUpdate(MatterEntity, UpdateEntity):
7176
"""Representation of a Matter node capable of updating."""
7277

@@ -250,7 +255,7 @@ async def async_will_remove_from_hass(self) -> None:
250255
DISCOVERY_SCHEMAS = [
251256
MatterDiscoverySchema(
252257
platform=Platform.UPDATE,
253-
entity_description=UpdateEntityDescription(
258+
entity_description=MatterUpdateEntityDescription(
254259
key="MatterUpdate", device_class=UpdateDeviceClass.FIRMWARE
255260
),
256261
entity_class=MatterUpdate,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /