From 76e6ce496dd8d60ae4f0712539acab393e40d399 Mon Sep 17 00:00:00 2001 From: SukramJ Date: Fri, 26 Jul 2024 11:48:39 +0200 Subject: [PATCH] Bump hahomematic to 2024.7.0 (#687) --- .pre-commit-config.yaml | 2 +- changelog.md | 3 ++ .../homematicip_local/entity_helpers.py | 51 +++++++++++++++---- .../homematicip_local/generic_entity.py | 12 ++++- .../homematicip_local/manifest.json | 2 +- .../homematicip_local/strings.json | 5 ++ .../homematicip_local/translations/de.json | 5 ++ .../homematicip_local/translations/en.json | 5 ++ requirements_test.txt | 12 ++--- requirements_test_pre_commit.txt | 2 +- 10 files changed, 80 insertions(+), 19 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 169bca33..82dd37ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.5.2 + rev: v0.5.5 hooks: - id: ruff args: diff --git a/changelog.md b/changelog.md index 62db2b28..99939113 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,10 @@ # Version 1.64.0 (2024-07-02) +- Bump hahomematic to 2024.7.0 + - Add button lock CE - Remove service delete_device. Use delete on the device entry instead - Fix triggers and action when using meta integrations +- Add translation to button lock # Version 1.63.1 (2024-06-22) diff --git a/custom_components/homematicip_local/entity_helpers.py b/custom_components/homematicip_local/entity_helpers.py index a43049b0..c6b6d917 100644 --- a/custom_components/homematicip_local/entity_helpers.py +++ b/custom_components/homematicip_local/entity_helpers.py @@ -15,6 +15,7 @@ from homeassistant.components.binary_sensor import BinarySensorDeviceClass from homeassistant.components.cover import CoverDeviceClass, CoverEntityDescription +from homeassistant.components.lock import LockEntityDescription from homeassistant.components.number import NumberDeviceClass from homeassistant.components.select import SelectEntityDescription from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass @@ -181,7 +182,6 @@ "GAS_POWER": HmSensorEntityDescription( key="GAS_POWER", native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, - state_class=SensorStateClass.MEASUREMENT, ), "GAS_VOLUME": HmSensorEntityDescription( key="GAS_VOLUME", @@ -711,6 +711,15 @@ ), } +_LOCK_DESCRIPTIONS_BY_POSTFIX: Mapping[str | tuple[str, ...], EntityDescription] = { + "BUTTON_LOCK": LockEntityDescription( + key="BUTTON_LOCK", + entity_category=EntityCategory.CONFIG, + entity_registry_enabled_default=False, + translation_key="button_lock", + ), +} + _ENTITY_DESCRIPTION_BY_DEVICE: Mapping[ HmPlatform, Mapping[str | tuple[str, ...], EntityDescription] ] = { @@ -729,6 +738,12 @@ HmPlatform.SWITCH: _SWITCH_DESCRIPTIONS_BY_PARAM, } +_ENTITY_DESCRIPTION_BY_POSTFIX: Mapping[ + HmPlatform, Mapping[str | tuple[str, ...], EntityDescription] +] = { + HmPlatform.LOCK: _LOCK_DESCRIPTIONS_BY_POSTFIX, +} + _ENTITY_DESCRIPTION_BY_DEVICE_AND_PARAM: Mapping[ HmPlatform, Mapping[tuple[str | tuple[str, ...], str], EntityDescription] ] = { @@ -764,7 +779,7 @@ def get_entity_description( - hm_entity: HmGenericEntity | GenericHubEntity, + hm_entity: HmGenericEntity | GenericHubEntity | CustomEntity, ) -> EntityDescription | None: """Get the entity_description.""" if entity_desc := _find_entity_description(hm_entity=hm_entity): @@ -786,7 +801,7 @@ def get_entity_description( def get_name_and_translation_key( - hm_entity: HmGenericEntity | GenericHubEntity, + hm_entity: HmGenericEntity | GenericHubEntity | CustomEntity, entity_desc: EntityDescription, ) -> tuple[str | UndefinedType | None, str | None]: """Get the name and translation_key.""" @@ -801,13 +816,18 @@ def get_name_and_translation_key( return None, hm_entity.parameter.lower() return None, entity_desc.translation_key + if isinstance(hm_entity, CustomEntity): + if entity_desc.translation_key is None and hm_entity.name_data.parameter_name: + return None, hm_entity.name_data.parameter_name.lower() + return None, entity_desc.translation_key + # custom entities use the customizable name from the CCU WebUI, # that does not need to be translated in HA return hm_entity.name, None def _find_entity_description( - hm_entity: HmGenericEntity | GenericHubEntity, + hm_entity: HmGenericEntity | GenericHubEntity | CustomEntity, ) -> EntityDescription | None: """Find the entity_description for platform.""" if isinstance(hm_entity, GenericEntity): @@ -824,10 +844,12 @@ def _find_entity_description( ): return entity_desc - if isinstance(hm_entity, CustomEntity) and ( - entity_desc := _get_entity_description_by_device_type(hm_entity=hm_entity) - ): - return entity_desc + if isinstance(hm_entity, CustomEntity): + if entity_desc := _get_entity_description_by_device_type(hm_entity=hm_entity): + return entity_desc + + if entity_desc := _get_entity_description_by_postfix(hm_entity=hm_entity): + return entity_desc return _DEFAULT_PLATFORM_DESCRIPTION.get(hm_entity.platform) @@ -856,7 +878,18 @@ def _get_entity_description_by_param( """Get entity_description by device_type and parameter.""" if platform_param_descriptions := _ENTITY_DESCRIPTION_BY_PARAM.get(hm_entity.platform): for params, entity_desc in platform_param_descriptions.items(): - if _param_in_list(params=params, parameter=hm_entity.parameter): + if hm_entity.name and _param_in_list(params=params, parameter=hm_entity.name): + return entity_desc + return None + + +def _get_entity_description_by_postfix( + hm_entity: CustomEntity, +) -> EntityDescription | None: + """Get entity_description by device_type and parameter.""" + if platform_postfix_descriptions := _ENTITY_DESCRIPTION_BY_POSTFIX.get(hm_entity.platform): + for postfix, entity_desc in platform_postfix_descriptions.items(): + if _param_in_list(params=postfix, parameter=hm_entity.entity_name_postfix): return entity_desc return None diff --git a/custom_components/homematicip_local/generic_entity.py b/custom_components/homematicip_local/generic_entity.py index c65f0480..54f378d0 100644 --- a/custom_components/homematicip_local/generic_entity.py +++ b/custom_components/homematicip_local/generic_entity.py @@ -160,6 +160,16 @@ def name(self) -> str | UndefinedType | None: entity_name = entity_name.replace( self._hm_entity.parameter.replace("_", " ").title(), translated_name ) + + if isinstance(self._hm_entity, CustomEntity) and entity_name: + translated_name = super().name + if self._do_remove_name(): + translated_name = "" + if isinstance(translated_name, str) and self._hm_entity.name_data.parameter_name: + entity_name = entity_name.replace( + self._hm_entity.name_data.parameter_name.replace("_", " ").title(), + translated_name, + ) if entity_name == "": return None return entity_name @@ -223,7 +233,7 @@ def _async_entity_updated(self, *args: Any, **kwargs: Any) -> None: # Don't update disabled entities update_type = ( "updated" - if self._hm_entity.last_refreshed == self._hm_entity.last_updated + if self._hm_entity.refreshed_at == self._hm_entity.modified_at else "refreshed" ) if self.enabled: diff --git a/custom_components/homematicip_local/manifest.json b/custom_components/homematicip_local/manifest.json index c04e223a..9d914431 100644 --- a/custom_components/homematicip_local/manifest.json +++ b/custom_components/homematicip_local/manifest.json @@ -10,7 +10,7 @@ "iot_class": "local_push", "issue_tracker": "https://github.com/danielperna84/hahomematic/issues", "loggers": ["hahomematic"], - "requirements": ["hahomematic==2024.6.0"], + "requirements": ["hahomematic==2024.7.0"], "ssdp": [ { "manufacturer": "EQ3", diff --git a/custom_components/homematicip_local/strings.json b/custom_components/homematicip_local/strings.json index d9cc6328..bcdb1d13 100644 --- a/custom_components/homematicip_local/strings.json +++ b/custom_components/homematicip_local/strings.json @@ -219,6 +219,11 @@ } } }, + "lock": { + "button_lock": { + "name": "Button Lock" + } + }, "number": { "frequency": { "name": "Frequency" diff --git a/custom_components/homematicip_local/translations/de.json b/custom_components/homematicip_local/translations/de.json index 51bdb2f5..1d0818b1 100644 --- a/custom_components/homematicip_local/translations/de.json +++ b/custom_components/homematicip_local/translations/de.json @@ -222,6 +222,11 @@ } } }, + "lock": { + "button_lock": { + "name": "Bediensperre" + } + }, "number": { "frequency": { "name": "Frequenz" diff --git a/custom_components/homematicip_local/translations/en.json b/custom_components/homematicip_local/translations/en.json index d9cc6328..bcdb1d13 100644 --- a/custom_components/homematicip_local/translations/en.json +++ b/custom_components/homematicip_local/translations/en.json @@ -219,6 +219,11 @@ } } }, + "lock": { + "button_lock": { + "name": "Button Lock" + } + }, "number": { "frequency": { "name": "Frequency" diff --git a/requirements_test.txt b/requirements_test.txt index 09511bdf..e1963496 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,11 +1,11 @@ -r requirements_test_pre_commit.txt -async-upnp-client==0.39.0 -hahomematic==2024.6.0 -homeassistant==2024.7.2 -mypy==1.10.1 +async-upnp-client==0.40.0 +hahomematic==2024.7.0 +homeassistant==2024.7.3 +mypy==1.11.0 mypy-dev==1.11.0a9 pre-commit==3.7.1 pydevccu==0.1.8 -pylint==3.2.5 -pytest-homeassistant-custom-component==0.13.146 +pylint==3.2.6 +pytest-homeassistant-custom-component==0.13.147 diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index b12e3fd4..c7f6c088 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -1,4 +1,4 @@ bandit==1.7.9 codespell==2.3.0 -ruff==0.5.2 +ruff==0.5.5 yamllint==1.35.1