Skip to content

Conversation

@scop
Copy link
Member

@scop scop commented Dec 25, 2025

Proposed change

Hassfest validation of icons translation file with state keys for state values that are not slugs fails currently with:

* [ERROR] [ICONS] Invalid icons.json: Invalid translation key '...', need to be [a-z0-9-_]+ and cannot start or end with a hyphen or underscore. for dictionary value @ ...

There are two things wrong with this:

  • State values are what they are, an orthogonal discussion is if we want something to enforce their values (e.g. valid slugs for enum-like), but it is not the icon validator's job to make assertions about them.
  • These are not "translation keys" but state keys.

Related discussion in #159611 (comment), and an example improvement waiting for this to be fixed in #159753, related CI fail in https://github.com/home-assistant/core/actions/runs/20511413499/job/58932915333?pr=159753#step:7:157

Error: R] [ICONS] Invalid icons.json: Invalid translation key '2G', need to be [a-z0-9-_]+ and cannot start or end with a hyphen or underscore. for dictionary value @ data['entity']['sensor']['mode']['state']. Got {'2G': 'mdi:signal-2g', '3G': 'mdi:signal-3g', '4G': 'mdi:signal-4g'}

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

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

State values are what they are, it is not the icon validator's job to
make assertions about them.
@MartinHjelmare
Copy link
Member

We generally don't allow anything but lowercase snake_case strings as states if the state should be non numeric.

@MartinHjelmare MartinHjelmare marked this pull request as draft December 25, 2025 22:58
@scop
Copy link
Member Author

scop commented Dec 26, 2025

That rule seems to be undocumented.

What I could find was https://developers.home-assistant.io/docs/dev_101_states (mentions "You can store anything you want in the state, as long as it's a string (will be converted if it's not)." which BTW does not seem accurate re numeric), and https://www.home-assistant.io/docs/configuration/state_object/ which does not mention any state constraints.

@scop
Copy link
Member Author

scop commented Dec 26, 2025

Lowercase snake_case would also rule out states like IP and MAC addresses, possibly hostnames (if they contain dots), textual resolved locations (as in maps), currently playing songs for media players, etc etc, there are a lot of valid ones. These examples are not well suited for state aware icons, but mentioning it as we're talking generally here.

I think such a general rule would be overly restrictive, but can understand if we'd want that for states with enum-like string values where we are in control or source of the values.

@MartinHjelmare
Copy link
Member

The things you mention are all not suitable for translations including icon translations, so aren't relevant, right?

@scop
Copy link
Member Author

scop commented Dec 27, 2025

As I mentioned,

These examples are not well suited for state aware icons, but mentioning it as we're talking generally here.

"generally" coming from your previous comment.

Anyway, I think I understand the gist of this, and as such it makes sense to me, although in some cases I think it causes some chores for little benefit. But I'd also like to see the docs rectified, as at least the one pointer I noted above seems clearly wrong per your comment. It appears I wasted some time on this, and it would be nice to decrease chances that others will. It doesn't seem too efficient for me to submit a PR, because I don't know what the actual rules are. Could you have a look at that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix cla-signed small-pr PRs with less than 30 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants