Skip to content

Add translation support for multi-value error and warning entities#39

Closed
Copilot wants to merge 11 commits intomainfrom
copilot/find-multi-value-entity
Closed

Add translation support for multi-value error and warning entities#39
Copilot wants to merge 11 commits intomainfrom
copilot/find-multi-value-entity

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

Error and warning entities display comma-separated error codes (e.g., OFFLINE_MOTOR_1,REGENERATIV_20) which HomeAssistant's standard translation mechanisms cannot handle since they only translate single enum values, not concatenated strings.

Implementation

  • Translation files: Added 44 error code translations in strings.json, en.json, de.json under entity.sensor.{sensor_key}.state.* format
  • TranslatableErrorMixin: Loads translations via async_get_translations() when entity is added to HA, provides _translate_code() method
  • ErrorSensor/WarningSensor: Apply mixin, translate individual codes before joining with ", " separator
  • Attributes: Raw codes preserved in error_codes/warning_codes attributes for automation use

The implementation uses HomeAssistant's official translation system with the proper format (entity.sensor.errors.state.{error_code}) that passes hassfest validation.

Example

Before: State shows OFFLINE_MOTOR_1,REGENERATIV_20

After:

  • State shows Motor 1 offline, Regeneration salt level < 20% (or German equivalent)
  • Attributes contain error_codes: ["OFFLINE_MOTOR_1", "REGENERATIV_20"] for automations
# Automations can still use raw codes via attributes
condition:
  - condition: template
    value_template: "{{ 'OFFLINE_MOTOR_1' in state_attr('sensor.bwt_perla_errors', 'error_codes') }}"

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 6 commits February 13, 2026 22:49
- Add translation keys for all error codes in strings.json, en.json, and de.json
- Modify ErrorSensor and WarningSensor to load and use translations
- Add extra_state_attributes with raw error codes for automation use
- Change separator from comma to comma+space for better readability

Co-authored-by: dkarv <3708591+dkarv@users.noreply.github.com>
Add FAQ section explaining how to use error codes in automations
Update entity table to clarify translated error messages and attribute access

Co-authored-by: dkarv <3708591+dkarv@users.noreply.github.com>
- Move _translate_error method from ErrorSensor and WarningSensor to BwtEntity
- Remove code duplication
- Remove trailing whitespace for better code style

Co-authored-by: dkarv <3708591+dkarv@users.noreply.github.com>
- Create TranslatableErrorMixin class for shared translation logic
- Rename _translate_error to _translate_code to reflect dual purpose
- Move async_added_to_hass translation loading to mixin
- Update ErrorSensor and WarningSensor to use the mixin
- Eliminates all code duplication between error and warning sensors

Co-authored-by: dkarv <3708591+dkarv@users.noreply.github.com>
- Add _get_errors() helper method to ErrorSensor
- Add _get_warnings() helper method to WarningSensor
- Remove extra blank line between classes
- Further reduce code duplication

Co-authored-by: dkarv <3708591+dkarv@users.noreply.github.com>
Add comprehensive docstring to TranslatableErrorMixin class explaining
its purpose and the _translations attribute lifecycle

Co-authored-by: dkarv <3708591+dkarv@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate Home Assistant integration for multi-value entities Add translation support for multi-value error and warning entities Feb 13, 2026
Copilot AI requested a review from dkarv February 13, 2026 22:57
@dkarv
Copy link
Owner

dkarv commented Feb 15, 2026

@copilot Checks are failing, please investigate

Copilot AI and others added 2 commits February 15, 2026 10:03
- Remove invalid entity_component._.state.error structure from JSON files
- Replace async translation loading with hardcoded dictionaries
- Add _ERROR_TRANSLATIONS_EN and _ERROR_TRANSLATIONS_DE constants
- Simplify TranslatableErrorMixin to use hardcoded translations
- Remove async_added_to_hass overrides from ErrorSensor and WarningSensor
- Fix HomeAssistant translation validation failures

Co-authored-by: dkarv <3708591+dkarv@users.noreply.github.com>
- Add translations under entity.sensor.errors.state.{code} structure
- Add translations under entity.sensor.warnings.state.{code} structure
- Load translations using async_get_translations from HA
- Use translation category "entity" instead of "entity_component"
- Restore async_added_to_hass to load translations on entity initialization
- Support both English and German through HA translation files

Co-authored-by: dkarv <3708591+dkarv@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 15, 2026

@copilot Checks are failing, please investigate

Fixed the hassfest validation errors. The issue was using an invalid translation structure. Now using the proper HomeAssistant format: entity.sensor.errors.state.{error_code} and entity.sensor.warnings.state.{error_code}.

Changes in commit 4c0752e:

  • Translations now use HomeAssistant's native translation system
  • Error codes stored under entity.sensor.{sensor_key}.state.{code}
  • Loads translations via async_get_translations from HA
  • Both English and German translations maintained in proper JSON files

The integration now properly uses HA's translation system instead of hardcoded values.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • developers.home-assistant.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@dkarv dkarv closed this Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants