Skip to content

Commit a2de928

Browse files
authored
Remove EntityType from quirks v2 entity metadata handling (#443)
* Remove `EntityType` from quirks v2 entity metadata handling * Fix unit tests
1 parent cadf77d commit a2de928

File tree

2 files changed

+20
-111
lines changed

2 files changed

+20
-111
lines changed

tests/test_discover.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,15 @@ async def test_quirks_v2_entity_discovery_errors(
614614
zigpy_device = _get_test_device(
615615
zha_gateway, "Ikea of Sweden3", "TRADFRI remote control3"
616616
)
617+
618+
# Inject unknown quirks v2 entity metadata
619+
class UnknownEntityMetadata:
620+
entity_platform = Platform.UPDATE
621+
622+
zigpy_device._exposes_metadata[
623+
(1, zigpy.zcl.clusters.general.OnOff.cluster_id, ClusterType.Server)
624+
].append(UnknownEntityMetadata())
625+
617626
zha_device = await join_zigpy_device(zha_gateway, zigpy_device)
618627

619628
assert (
@@ -732,17 +741,15 @@ async def test_quirks_v2_metadata_bad_device_classes(
732741
zigpy.quirks._DEVICE_REGISTRY.remove(zigpy_device)
733742

734743

735-
async def test_quirks_v2_fallback_name(
736-
zha_gateway: Gateway, # pylint: disable=unused-argument
737-
) -> None:
744+
async def test_quirks_v2_fallback_name(zha_gateway: Gateway) -> None:
738745
"""Test quirks v2 fallback name."""
739746

740747
zigpy_device = _get_test_device(
741748
zha_gateway,
742749
"Ikea of Sweden6",
743750
"TRADFRI remote control6",
744751
augment_method=lambda builder: builder.sensor(
745-
attribute_name=zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name,
752+
attribute_name=zigpy.zcl.clusters.general.OnOff.AttributeDefs.global_scene_control.name,
746753
cluster_id=zigpy.zcl.clusters.general.OnOff.cluster_id,
747754
translation_key="some_sensor",
748755
fallback_name="Fallback name",

zha/application/discovery.py

Lines changed: 9 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from zigpy.quirks.v2 import (
1313
BinarySensorMetadata,
1414
CustomDeviceV2,
15-
EntityType,
1615
NumberMetadata,
1716
SwitchMetadata,
1817
WriteAttributeButtonMetadata,
@@ -107,111 +106,14 @@
107106
)
108107

109108
QUIRKS_ENTITY_META_TO_ENTITY_CLASS = {
110-
(
111-
Platform.BUTTON,
112-
WriteAttributeButtonMetadata,
113-
EntityType.CONFIG,
114-
): button.WriteAttributeButton,
115-
(
116-
Platform.BUTTON,
117-
WriteAttributeButtonMetadata,
118-
EntityType.STANDARD,
119-
): button.WriteAttributeButton,
120-
(
121-
Platform.BUTTON,
122-
WriteAttributeButtonMetadata,
123-
EntityType.DIAGNOSTIC,
124-
): button.WriteAttributeButton,
125-
(
126-
Platform.BUTTON,
127-
ZCLCommandButtonMetadata,
128-
EntityType.CONFIG,
129-
): button.Button,
130-
(
131-
Platform.BUTTON,
132-
ZCLCommandButtonMetadata,
133-
EntityType.DIAGNOSTIC,
134-
): button.Button,
135-
(
136-
Platform.BUTTON,
137-
ZCLCommandButtonMetadata,
138-
EntityType.STANDARD,
139-
): button.Button,
140-
(
141-
Platform.BINARY_SENSOR,
142-
BinarySensorMetadata,
143-
EntityType.CONFIG,
144-
): binary_sensor.BinarySensor,
145-
(
146-
Platform.BINARY_SENSOR,
147-
BinarySensorMetadata,
148-
EntityType.DIAGNOSTIC,
149-
): binary_sensor.BinarySensor,
150-
(
151-
Platform.BINARY_SENSOR,
152-
BinarySensorMetadata,
153-
EntityType.STANDARD,
154-
): binary_sensor.BinarySensor,
155-
(
156-
Platform.SENSOR,
157-
ZCLEnumMetadata,
158-
EntityType.DIAGNOSTIC,
159-
): sensor.EnumSensor,
160-
(
161-
Platform.SENSOR,
162-
ZCLEnumMetadata,
163-
EntityType.STANDARD,
164-
): sensor.EnumSensor,
165-
(
166-
Platform.SENSOR,
167-
ZCLSensorMetadata,
168-
EntityType.DIAGNOSTIC,
169-
): sensor.Sensor,
170-
(
171-
Platform.SENSOR,
172-
ZCLSensorMetadata,
173-
EntityType.STANDARD,
174-
): sensor.Sensor,
175-
(
176-
Platform.SELECT,
177-
ZCLEnumMetadata,
178-
EntityType.CONFIG,
179-
): select.ZCLEnumSelectEntity,
180-
(
181-
Platform.SELECT,
182-
ZCLEnumMetadata,
183-
EntityType.STANDARD,
184-
): select.ZCLEnumSelectEntity,
185-
(
186-
Platform.SELECT,
187-
ZCLEnumMetadata,
188-
EntityType.DIAGNOSTIC,
189-
): select.ZCLEnumSelectEntity,
190-
(
191-
Platform.NUMBER,
192-
NumberMetadata,
193-
EntityType.CONFIG,
194-
): number.NumberConfigurationEntity,
195-
(
196-
Platform.NUMBER,
197-
NumberMetadata,
198-
EntityType.DIAGNOSTIC,
199-
): number.NumberConfigurationEntity,
200-
(
201-
Platform.NUMBER,
202-
NumberMetadata,
203-
EntityType.STANDARD,
204-
): number.NumberConfigurationEntity,
205-
(
206-
Platform.SWITCH,
207-
SwitchMetadata,
208-
EntityType.CONFIG,
209-
): switch.ConfigurableAttributeSwitch,
210-
(
211-
Platform.SWITCH,
212-
SwitchMetadata,
213-
EntityType.STANDARD,
214-
): switch.ConfigurableAttributeSwitch,
109+
(Platform.BUTTON, WriteAttributeButtonMetadata): button.WriteAttributeButton,
110+
(Platform.BUTTON, ZCLCommandButtonMetadata): button.Button,
111+
(Platform.BINARY_SENSOR, BinarySensorMetadata): binary_sensor.BinarySensor,
112+
(Platform.SENSOR, ZCLEnumMetadata): sensor.EnumSensor,
113+
(Platform.SENSOR, ZCLSensorMetadata): sensor.Sensor,
114+
(Platform.SELECT, ZCLEnumMetadata): select.ZCLEnumSelectEntity,
115+
(Platform.NUMBER, NumberMetadata): number.NumberConfigurationEntity,
116+
(Platform.SWITCH, SwitchMetadata): switch.ConfigurableAttributeSwitch,
215117
}
216118

217119

@@ -338,7 +240,7 @@ def discover_quirks_v2_entities(self, device: Device) -> Iterator[PlatformEntity
338240
platform = Platform(entity_metadata.entity_platform.value)
339241
metadata_type = type(entity_metadata)
340242
entity_class = QUIRKS_ENTITY_META_TO_ENTITY_CLASS.get(
341-
(platform, metadata_type, entity_metadata.entity_type)
243+
(platform, metadata_type)
342244
)
343245

344246
if entity_class is None:

0 commit comments

Comments
 (0)