Skip to content

Commit 62ec158

Browse files
Bump zigpy from 0.66.0 to 0.67.0 (#212)
* Bump zigpy from 0.66.0 to 0.67.0 Bumps [zigpy](https://github.com/zigpy/zigpy) from 0.66.0 to 0.67.0. - [Release notes](https://github.com/zigpy/zigpy/releases) - [Commits](zigpy/zigpy@0.66.0...0.67.0) --- updated-dependencies: - dependency-name: zigpy dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Fix discovery tests * Support `fallback_name` * Add a unit test for `fallback_name` --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: puddly <[email protected]>
1 parent 65b22a0 commit 62ec158

File tree

3 files changed

+46
-75
lines changed

3 files changed

+46
-75
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ readme = "README.md"
1414
license = {text = "Apache-2.0"}
1515
requires-python = ">=3.12"
1616
dependencies = [
17-
"zigpy==0.66.0",
17+
"zigpy==0.67.0",
1818
"bellows==0.40.6",
1919
"zigpy-znp==0.12.4",
2020
"zigpy-deconz==0.23.3",

tests/test_discover.py

Lines changed: 41 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ async def test_quirks_v2_entity_discovery(
521521
step=1,
522522
unit=UnitOfTime.SECONDS,
523523
multiplier=1,
524+
translation_key="off_wait_time",
525+
fallback_name="Off wait time",
524526
)
525527
.add_to_registry()
526528
)
@@ -580,15 +582,24 @@ class FakeXiaomiAqaraDriverE1(XiaomiAqaraDriverE1):
580582
BasicCluster.cluster_id,
581583
entity_platform=Platform.SENSOR,
582584
entity_type=EntityType.DIAGNOSTIC,
585+
translation_key="power_source",
586+
fallback_name="Power source",
583587
)
584588
.enum(
585589
"hooks_state",
586590
AqaraE1HookState,
587591
FakeXiaomiAqaraDriverE1.cluster_id,
588592
entity_platform=Platform.SENSOR,
589593
entity_type=EntityType.DIAGNOSTIC,
594+
translation_key="hooks_state",
595+
fallback_name="Hooks state",
596+
)
597+
.binary_sensor(
598+
"error_detected",
599+
FakeXiaomiAqaraDriverE1.cluster_id,
600+
translation_key="error_detected",
601+
fallback_name="Error detected",
590602
)
591-
.binary_sensor("error_detected", FakeXiaomiAqaraDriverE1.cluster_id)
592603
.add_to_registry()
593604
)
594605

@@ -800,7 +811,7 @@ async def test_quirks_v2_entity_discovery_errors(
800811
"entity_type=<EntityType.CONFIG: 'config'>, cluster_id=6, endpoint_id=1, "
801812
"cluster_type=<ClusterType.Server: 0>, initially_disabled=False, "
802813
"attribute_initialized_from_cache=True, translation_key='analog_input', "
803-
"attribute_name='off_wait_time', divisor=1, multiplier=1, "
814+
"fallback_name=None, attribute_name='off_wait_time', divisor=1, multiplier=1, "
804815
"unit=None, device_class=None, state_class=None)}"
805816
)
806817
# fmt: on
@@ -877,33 +888,6 @@ def validate_translation_keys_device_class(
877888
raise ValueError(f"{m1}{m2}{quirk}")
878889

879890

880-
def bad_device_class_unit_combination(
881-
quirk_builder: QuirkBuilder,
882-
) -> QuirkBuilder:
883-
"""Introduce a bad device class and unit combination."""
884-
return quirk_builder.sensor(
885-
zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name,
886-
zigpy.zcl.clusters.general.OnOff.cluster_id,
887-
entity_type=EntityType.CONFIG,
888-
unit="invalid",
889-
device_class="invalid",
890-
translation_key="analog_input",
891-
)
892-
893-
894-
def bad_device_class_translation_key_usage(
895-
quirk_builder: QuirkBuilder,
896-
) -> QuirkBuilder:
897-
"""Introduce a bad device class and translation key combination."""
898-
return quirk_builder.sensor(
899-
zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name,
900-
zigpy.zcl.clusters.general.OnOff.cluster_id,
901-
entity_type=EntityType.CONFIG,
902-
translation_key="invalid",
903-
device_class="invalid",
904-
)
905-
906-
907891
def validate_metadata(validator: Callable) -> None:
908892
"""Ensure v2 quirks metadata does not violate HA rules."""
909893
all_v2_quirks = itertools.chain.from_iterable(
@@ -916,51 +900,6 @@ def validate_metadata(validator: Callable) -> None:
916900
validator(quirk, entity_metadata, platform, translations)
917901

918902

919-
@pytest.mark.parametrize(
920-
("augment_method", "validate_method", "expected_exception_string"),
921-
[
922-
(
923-
bad_device_class_unit_combination,
924-
validate_device_class_unit,
925-
"cannot have both unit and device_class",
926-
),
927-
(
928-
bad_device_class_translation_key_usage,
929-
validate_translation_keys_device_class,
930-
"cannot have both a translation_key and a device_class",
931-
),
932-
],
933-
)
934-
async def test_quirks_v2_metadata_errors(
935-
zha_gateway: Gateway, # pylint: disable=unused-argument
936-
zigpy_device_mock,
937-
device_joined: Callable[[zigpy.device.Device], Awaitable[Device]],
938-
augment_method: Callable[[QuirkBuilder], QuirkBuilder],
939-
validate_method: Callable,
940-
expected_exception_string: str,
941-
) -> None:
942-
"""Ensure all v2 quirks translation keys exist."""
943-
944-
# no error yet
945-
validate_metadata(validate_method)
946-
947-
# ensure the error is caught and raised
948-
with pytest.raises(ValueError, match=expected_exception_string):
949-
# introduce an error
950-
zigpy_device = _get_test_device(
951-
zigpy_device_mock,
952-
"Ikea of Sweden4",
953-
"TRADFRI remote control4",
954-
augment_method=augment_method,
955-
)
956-
await device_joined(zigpy_device)
957-
958-
validate_metadata(validate_method)
959-
# if the device was created we remove it
960-
# so we don't pollute the rest of the tests
961-
zigpy.quirks._DEVICE_REGISTRY.remove(zigpy_device)
962-
963-
964903
class BadDeviceClass(enum.Enum):
965904
"""Bad device class."""
966905

@@ -1048,6 +987,34 @@ async def test_quirks_v2_metadata_bad_device_classes(
1048987
zigpy.quirks._DEVICE_REGISTRY.remove(zigpy_device)
1049988

1050989

990+
async def test_quirks_v2_fallback_name(
991+
zha_gateway: Gateway, # pylint: disable=unused-argument
992+
zigpy_device_mock,
993+
device_joined: Callable[[zigpy.device.Device], Awaitable[Device]],
994+
) -> None:
995+
"""Test quirks v2 fallback name."""
996+
997+
zigpy_device = _get_test_device(
998+
zigpy_device_mock,
999+
"Ikea of Sweden6",
1000+
"TRADFRI remote control6",
1001+
augment_method=lambda builder: builder.sensor(
1002+
attribute_name=zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name,
1003+
cluster_id=zigpy.zcl.clusters.general.OnOff.cluster_id,
1004+
translation_key="some_sensor",
1005+
fallback_name="Fallback name",
1006+
),
1007+
)
1008+
zha_device = await device_joined(zigpy_device)
1009+
1010+
entity = get_entity(
1011+
zha_device,
1012+
platform=Platform.SENSOR,
1013+
qualifier_func=lambda e: e.fallback_name == "Fallback name",
1014+
)
1015+
assert entity.fallback_name == "Fallback name"
1016+
1017+
10511018
def pytest_generate_tests(metafunc):
10521019
"""Generate tests for all device files."""
10531020
if "file_path" in metafunc.fixturenames:

zha/application/platforms/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,12 @@ def _init_from_quirks_metadata(self, entity_metadata: EntityMetadata) -> None:
343343
has_device_class = hasattr(entity_metadata, "device_class")
344344
has_attribute_name = hasattr(entity_metadata, "attribute_name")
345345
has_command_name = hasattr(entity_metadata, "command_name")
346+
has_fallback_name = hasattr(entity_metadata, "fallback_name")
346347

347348
if not has_device_class or entity_metadata.device_class is None:
349+
if has_fallback_name:
350+
self._attr_fallback_name = entity_metadata.fallback_name
351+
348352
if entity_metadata.translation_key:
349353
self._attr_translation_key = entity_metadata.translation_key
350354
elif has_attribute_name:

0 commit comments

Comments
 (0)