Skip to content

Commit

Permalink
Bump hahomematic to 2024.7.0 (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ committed Jul 26, 2024
1 parent b94d8d1 commit 76e6ce4
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
51 changes: 42 additions & 9 deletions custom_components/homematicip_local/entity_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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]
] = {
Expand All @@ -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]
] = {
Expand Down Expand Up @@ -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):
Expand All @@ -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."""
Expand All @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion custom_components/homematicip_local/generic_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/homematicip_local/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions custom_components/homematicip_local/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@
}
}
},
"lock": {
"button_lock": {
"name": "Button Lock"
}
},
"number": {
"frequency": {
"name": "Frequency"
Expand Down
5 changes: 5 additions & 0 deletions custom_components/homematicip_local/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@
}
}
},
"lock": {
"button_lock": {
"name": "Bediensperre"
}
},
"number": {
"frequency": {
"name": "Frequenz"
Expand Down
5 changes: 5 additions & 0 deletions custom_components/homematicip_local/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@
}
}
},
"lock": {
"button_lock": {
"name": "Button Lock"
}
},
"number": {
"frequency": {
"name": "Frequency"
Expand Down
12 changes: 6 additions & 6 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bandit==1.7.9
codespell==2.3.0
ruff==0.5.2
ruff==0.5.5
yamllint==1.35.1

0 comments on commit 76e6ce4

Please sign in to comment.