Skip to content

homematicip_cloud: migrate binary sensors to entity descriptions#166052

Draft
lackas wants to merge 1 commit intohome-assistant:devfrom
lackas:hmip-entity-translations-v2
Draft

homematicip_cloud: migrate binary sensors to entity descriptions#166052
lackas wants to merge 1 commit intohome-assistant:devfrom
lackas:hmip-entity-translations-v2

Conversation

@lackas
Copy link
Contributor

@lackas lackas commented Mar 20, 2026

Proposed change

RFC / prototype for @joostlek to review the approach before migrating more platforms.

Refactors simple binary sensor entities from individual subclasses to the EntityDescription pattern (following the ViCare model as suggested by Joost). This consolidates 7 entity classes into a single HomematicipSimpleBinarySensor class with descriptions:

Converted: motion detector, presence detector, smoke detector, water detector, power mains failure, rain sensor, battery sensor

Left as legacy classes (too complex for the description pattern): cloud connection, acceleration/tilt, contact/shutter interfaces, storm (custom icon), sunshine (extra attrs), FLC lock/glass break, security groups, chamber degraded

Key design decisions (looking for feedback):

  1. legacy_class_name on description — preserves unique_id backward compatibility since unique_ids are currently derived from class names (HomematicipMotionDetector_DEVICEID). Is there a better approach?

  2. Base class name propertyHomematicipGenericEntity overrides Entity.name which prevents HA's _name_internal from handling translation_key. For entities with has_entity_name=True, we delegate to _name_internal explicitly. Is this acceptable, or should we refactor the base class differently?

  3. name=None vs translation_key — primary entities (motion, presence, smoke, water, power) use name=None on the description (entity IS the device). Sub-entities (battery, rain) use translation_key for the name suffix. Correct approach?

  4. Home name prefix — the legacy name property prepends the HmIP home name to every entity. With has_entity_name, this prefix disappears. Entity IDs are stable (stored in registry), but friendly names change for users with a home name set. Acceptable?

All 159 existing tests pass without modifications.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Refactor simple binary sensor entities to use EntityDescription pattern
instead of individual subclasses. This consolidates 7 entity classes
(motion, presence, smoke, water, battery, rain, power mains) into a
single HomematicipSimpleBinarySensor class with descriptions.

Adds has_entity_name support to the base entity class and translation
keys for sub-entity names (battery, rain).
@home-assistant
Copy link

Hey there @hahn-th, mind taking a look at this pull request as it has been labeled with an integration (homematicip_cloud) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of homematicip_cloud can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign homematicip_cloud Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the homematicip_cloud integration’s simpler binary sensor entities to use the EntityDescription pattern, reducing per-entity subclass boilerplate while keeping backward compatibility for existing unique_ids.

Changes:

  • Introduces HmipBinarySensorEntityDescription and a generic HomematicipSimpleBinarySensor to replace several simple binary sensor subclasses.
  • Updates HomematicipGenericEntity.name to delegate to Home Assistant’s standard naming/translation machinery when has_entity_name is enabled.
  • Adds translation strings for the new battery and rain binary sensor translation_keys.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
homeassistant/components/homematicip_cloud/strings.json Adds entity name translations for battery and rain binary sensors.
homeassistant/components/homematicip_cloud/entity.py Adjusts entity naming to support has_entity_name + translations via _name_internal.
homeassistant/components/homematicip_cloud/binary_sensor.py Migrates several simple binary sensors to EntityDescriptions and adds the generic entity class + mappings.

Comment on lines +209 to +215
if self.has_entity_name:
if not self.platform_data:
return self._name_internal(None, {})
return self._name_internal(
self._device_class_name,
self.platform_data.platform_translations,
)
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because HomematicipGenericEntity overrides Entity.name, Home Assistant will no longer use Entity’s default suggested_object_id logic (which uses object-id translations). For entities that rely on translation_key/EntityDescription (e.g. the new battery/rain sensors), this means the entity_id generated on first creation can depend on the user’s UI language (platform_translations) instead of the stable default-language object-id translations. Consider overriding suggested_object_id for this integration (at least when has_entity_name is True) to derive the object id via _name_internal(..., platform_data.object_id_platform_translations) like Entity does, so new entity_ids are language-independent.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants