From 62ec15899fed6bd8ae1f984a547ea9d7310d13d8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:42:33 -0400 Subject: [PATCH] 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](https://github.com/zigpy/zigpy/compare/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] * Fix discovery tests * Support `fallback_name` * Add a unit test for `fallback_name` --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: puddly <32534428+puddly@users.noreply.github.com> --- pyproject.toml | 2 +- tests/test_discover.py | 115 +++++++++----------------- zha/application/platforms/__init__.py | 4 + 3 files changed, 46 insertions(+), 75 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bb5f9800..5a30bdb7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ readme = "README.md" license = {text = "Apache-2.0"} requires-python = ">=3.12" dependencies = [ - "zigpy==0.66.0", + "zigpy==0.67.0", "bellows==0.40.6", "zigpy-znp==0.12.4", "zigpy-deconz==0.23.3", diff --git a/tests/test_discover.py b/tests/test_discover.py index 5d2e5fd3..6771d387 100644 --- a/tests/test_discover.py +++ b/tests/test_discover.py @@ -521,6 +521,8 @@ async def test_quirks_v2_entity_discovery( step=1, unit=UnitOfTime.SECONDS, multiplier=1, + translation_key="off_wait_time", + fallback_name="Off wait time", ) .add_to_registry() ) @@ -580,6 +582,8 @@ class FakeXiaomiAqaraDriverE1(XiaomiAqaraDriverE1): BasicCluster.cluster_id, entity_platform=Platform.SENSOR, entity_type=EntityType.DIAGNOSTIC, + translation_key="power_source", + fallback_name="Power source", ) .enum( "hooks_state", @@ -587,8 +591,15 @@ class FakeXiaomiAqaraDriverE1(XiaomiAqaraDriverE1): FakeXiaomiAqaraDriverE1.cluster_id, entity_platform=Platform.SENSOR, entity_type=EntityType.DIAGNOSTIC, + translation_key="hooks_state", + fallback_name="Hooks state", + ) + .binary_sensor( + "error_detected", + FakeXiaomiAqaraDriverE1.cluster_id, + translation_key="error_detected", + fallback_name="Error detected", ) - .binary_sensor("error_detected", FakeXiaomiAqaraDriverE1.cluster_id) .add_to_registry() ) @@ -800,7 +811,7 @@ async def test_quirks_v2_entity_discovery_errors( "entity_type=, cluster_id=6, endpoint_id=1, " "cluster_type=, initially_disabled=False, " "attribute_initialized_from_cache=True, translation_key='analog_input', " - "attribute_name='off_wait_time', divisor=1, multiplier=1, " + "fallback_name=None, attribute_name='off_wait_time', divisor=1, multiplier=1, " "unit=None, device_class=None, state_class=None)}" ) # fmt: on @@ -877,33 +888,6 @@ def validate_translation_keys_device_class( raise ValueError(f"{m1}{m2}{quirk}") -def bad_device_class_unit_combination( - quirk_builder: QuirkBuilder, -) -> QuirkBuilder: - """Introduce a bad device class and unit combination.""" - return quirk_builder.sensor( - zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name, - zigpy.zcl.clusters.general.OnOff.cluster_id, - entity_type=EntityType.CONFIG, - unit="invalid", - device_class="invalid", - translation_key="analog_input", - ) - - -def bad_device_class_translation_key_usage( - quirk_builder: QuirkBuilder, -) -> QuirkBuilder: - """Introduce a bad device class and translation key combination.""" - return quirk_builder.sensor( - zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name, - zigpy.zcl.clusters.general.OnOff.cluster_id, - entity_type=EntityType.CONFIG, - translation_key="invalid", - device_class="invalid", - ) - - def validate_metadata(validator: Callable) -> None: """Ensure v2 quirks metadata does not violate HA rules.""" all_v2_quirks = itertools.chain.from_iterable( @@ -916,51 +900,6 @@ def validate_metadata(validator: Callable) -> None: validator(quirk, entity_metadata, platform, translations) -@pytest.mark.parametrize( - ("augment_method", "validate_method", "expected_exception_string"), - [ - ( - bad_device_class_unit_combination, - validate_device_class_unit, - "cannot have both unit and device_class", - ), - ( - bad_device_class_translation_key_usage, - validate_translation_keys_device_class, - "cannot have both a translation_key and a device_class", - ), - ], -) -async def test_quirks_v2_metadata_errors( - zha_gateway: Gateway, # pylint: disable=unused-argument - zigpy_device_mock, - device_joined: Callable[[zigpy.device.Device], Awaitable[Device]], - augment_method: Callable[[QuirkBuilder], QuirkBuilder], - validate_method: Callable, - expected_exception_string: str, -) -> None: - """Ensure all v2 quirks translation keys exist.""" - - # no error yet - validate_metadata(validate_method) - - # ensure the error is caught and raised - with pytest.raises(ValueError, match=expected_exception_string): - # introduce an error - zigpy_device = _get_test_device( - zigpy_device_mock, - "Ikea of Sweden4", - "TRADFRI remote control4", - augment_method=augment_method, - ) - await device_joined(zigpy_device) - - validate_metadata(validate_method) - # if the device was created we remove it - # so we don't pollute the rest of the tests - zigpy.quirks._DEVICE_REGISTRY.remove(zigpy_device) - - class BadDeviceClass(enum.Enum): """Bad device class.""" @@ -1048,6 +987,34 @@ async def test_quirks_v2_metadata_bad_device_classes( zigpy.quirks._DEVICE_REGISTRY.remove(zigpy_device) +async def test_quirks_v2_fallback_name( + zha_gateway: Gateway, # pylint: disable=unused-argument + zigpy_device_mock, + device_joined: Callable[[zigpy.device.Device], Awaitable[Device]], +) -> None: + """Test quirks v2 fallback name.""" + + zigpy_device = _get_test_device( + zigpy_device_mock, + "Ikea of Sweden6", + "TRADFRI remote control6", + augment_method=lambda builder: builder.sensor( + attribute_name=zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name, + cluster_id=zigpy.zcl.clusters.general.OnOff.cluster_id, + translation_key="some_sensor", + fallback_name="Fallback name", + ), + ) + zha_device = await device_joined(zigpy_device) + + entity = get_entity( + zha_device, + platform=Platform.SENSOR, + qualifier_func=lambda e: e.fallback_name == "Fallback name", + ) + assert entity.fallback_name == "Fallback name" + + def pytest_generate_tests(metafunc): """Generate tests for all device files.""" if "file_path" in metafunc.fixturenames: diff --git a/zha/application/platforms/__init__.py b/zha/application/platforms/__init__.py index 7bbe0f4b..a2b36156 100644 --- a/zha/application/platforms/__init__.py +++ b/zha/application/platforms/__init__.py @@ -343,8 +343,12 @@ def _init_from_quirks_metadata(self, entity_metadata: EntityMetadata) -> None: has_device_class = hasattr(entity_metadata, "device_class") has_attribute_name = hasattr(entity_metadata, "attribute_name") has_command_name = hasattr(entity_metadata, "command_name") + has_fallback_name = hasattr(entity_metadata, "fallback_name") if not has_device_class or entity_metadata.device_class is None: + if has_fallback_name: + self._attr_fallback_name = entity_metadata.fallback_name + if entity_metadata.translation_key: self._attr_translation_key = entity_metadata.translation_key elif has_attribute_name: