Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entity translation strings for ScreenLogic #130708

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

dieselrabbit
Copy link
Contributor

@dieselrabbit dieselrabbit commented Nov 15, 2024

Proposed change

  • Add translation strings for 'static' entity names within screenlogic.
    • This excludes names for circuits as those are provided by the device, and names derived from circuit names (pump-related entities).
  • Add translation strings for climate preset_modes.
  • Add translation strings for dose state enums.
  • Make use of common strings.
    • Move service data config_entry name+description to common.

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:

Checklist

  • 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.

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:

@home-assistant
Copy link

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

Code owner commands

Code owners of screenlogic 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 screenlogic 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) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Comment on lines +155 to +164
"calcium_hardness": {
"name": "Calcium Hardness"
},
"cya": {
"name": "Cyanuric Acid"
},
"total_alkalinity": {
"name": "Total Alkalinity"
},
"salt_tds_ppm": {
Copy link
Member

Choose a reason for hiding this comment

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

FYI, the names need to be Sentence case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, ok. And it's ok that this would be a change from the current Title Case?

Copy link
Member

Choose a reason for hiding this comment

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

Yep!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, the user-selected names that come from the device are all Title-Case. Do I need to filter all of those down to Sentence-case?

),
ScreenLogicPushBinarySensorDescription(
subscription_code=CODE.CHEMISTRY_CHANGED,
data_root=(DEVICE.INTELLICHEM, GROUP.ALERT),
key=VALUE.ORP_LIMIT,
translation_key="chem_limit",
translation_placeholders={"chem": "ORP"},
Copy link
Member

Choose a reason for hiding this comment

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

What's ORP? Should we write it out? Does pH have different translations for other languages? Maybe it would make sense to keep them as part of the translation string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ORP stands for Oxidation Reduction Potential. Neither appear to be translated for other languages. Looking at the Pentair Europe site and cycling through the available languages, neither ORP or pH are ever referred to by their full name, or translated.

@@ -55,7 +55,8 @@ def __init__(
self._data_path = (*self.entity_description.data_root, self._data_key)
mac = self.mac
self._attr_unique_id = f"{mac}_{generate_unique_id(*self._data_path)}"
self._attr_name = self.entity_data[ATTR.NAME]
if not entity_description.translation_key:
self._attr_name = self.entity_data[ATTR.NAME]
Copy link
Member

Choose a reason for hiding this comment

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

What's this name?

Copy link
Contributor Author

@dieselrabbit dieselrabbit Nov 15, 2024

Choose a reason for hiding this comment

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

Currently all entities get their name from the api. The referenced change leaves that convention in place for entities that get their name from the device (user named circuits/features), which as it applies to the integration, are switch and light entities, and sensor entities for the pump(s), which are named by the api after the first circuit associated with them in the device.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add some examples with what you want to achieve where? With translations set, you usually don't need to use _attr_name anymore, except for when the entity needs to be the device name

Copy link
Contributor Author

@dieselrabbit dieselrabbit Nov 16, 2024

Choose a reason for hiding this comment

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

The api lib screenlogicpy (which I maintain) originally provided the majority of data that HA uses, for each value intended to be supported in HA.
Example of data provided by the api lib:

"air_temperature": {
  "name": "Air Temperature",
  "value": 62,
  "unit": "\u00b0F",
  "device_type": "temperature",
  "state_type": "measurement"
},
"ph": {
  "name": "pH",
  "value": 7.5,
  "unit": "pH",
  "state_type": "measurement"
},
"orp": {
  "name": "ORP",
  "value": 726,
  "unit": "mV",
  "state_type": "measurement"
},

Since moving to EntityDescriptions though, the majority of that extra data is no longer used, except for the name. Prior to this PR adding entity translations, all entities were sill using the name provided by the api lib. That's where the self._attr_name = self.entity_data[ATTR.NAME] came from.

Some of the entities this integration exposes (like the example above) are statically named, meaning the integration knows ahead of time what value it is exposing, but there are other entities that are created dynamically. Because the ScreenLogic gateway device supports various equipment configurations there can be different amounts of circuits, pumps, and heaters (along with other equipment either present or not). Additionally, the pool controller allows the user to custom name the individual circuits within the device. It is intended for entities that expose these circuits (switch, light, and some sensor) to use the name the user has set in the pool controller device.

Therefore for the entities known ahead of time I've provided translations for them, but for the ones not known ahead of time (where I haven't provided a translation_key), the integration "falls-back" to the name provided by the api lib, which is what the end user has set within the device itself.

Sorry it's a bit long-winded, but I thought it might be helpful to have a little context as to how the code got to where it is now.

Copy link
Member

Choose a reason for hiding this comment

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

Okay this explains it well. I'll check the code on how we can do this the best. How do the devices currently look in HA? Is every pump its own device? Or is everything thrown under 1 device?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everything is currently under one device.

There's a mix of conventions within the Pentair ScreenLogic system that made breaking out individual devices messy and in my opinion confusing. Some equipment is presented as a stand-alone device, some are only referenced through the central controller, and some are presented as multiple devices that are only active depending on what mode the central controller is in.

Because the official app presents as one point of connection/device I elected to start there.

Copy link
Member

Choose a reason for hiding this comment

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

Ideally we have one device per physical device. I don't think there's a big lack of user experience if we can't do that and just put it on the controller when that's not possible. How do you mean with the device being active?

Using devices is quite a nice way to not use a lot of placeholders. We can use via_device to neatly connect them to the main controller.

(Also, I don't see this as a must, if we can't do that and the user experience is worse, we shouldn't, I'm just exploring at this point :) )

homeassistant/components/screenlogic/climate.py Outdated Show resolved Hide resolved
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.

3 participants