jaroschek / home-assistant-myuplink

Custom Home Assistant integration for devices and sensors in myUplink account.
39 stars 8 forks source link

Show value as text in Enum params rather than number #6

Closed 7RST1 closed 1 year ago

7RST1 commented 1 year ago

Made sensors with device classes set as ENUM get human readable strings from raw data rather than integers.

Since the human readable enum-values are included in the raw data, it was pretty straight forward to implement. ~I put the logic into an existing loop, so shouldn't be much more expensive either.~

I've tested it and it works as it should, see images below.

Before: bilde

After: Screenshot from 2023-04-10 22-02-16

7RST1 commented 1 year ago

I see now that strVal simply could do the job. I think the for logic was wrong anyways. lemme fix

jaroschek commented 1 year ago

Hello, I have tried to solve this through translations based on the list of key-value pairs provided by the myUplink-API for each enum sensor. While the numeric value ist stored in the database, Home Assistant can display the human readable value for the enum sensor in the current locale used in the frontend.

But through your screenshots I have discovered, that I have not yet covered the list of "Possible states":

possible-states

So I would try to solve the missing translations in this specific view.

With your solution we would store the human readable value of each enum sensor based on the locale of the API (en_US per default). But I would like to store the numeric values in the database and just display human readable values in the frontend in the right locale through translations.

As I only have my own Nibe heatpump for sample data, I have definitely not all strings prepared for all enum values of all possible devices and sensors.

If you would be so kind to just add your strings and translations, this could solve your problem in a more flexible way regarding human readability in multiple languages.

7RST1 commented 1 year ago

Ah, that makes sense! I should have realized what those sensor translations were. I tried searching for enum translations in the HASS docs and such, but I guess I didn't search thoroughly enough.

I'll close this PR and add the translations relevant for my water heater in English and Norwegian.

7RST1 commented 1 year ago

I see the same sensor translations reside both in en.json and sensor.en.json (and in myuplink/strings.json in the case of English). Are all files used?

jaroschek commented 1 year ago

Hi, sorry for the late answer.

To be honest, I just looked through the other official integrations and tried to do the same. So I honestly am not sure, if all files are needed. But I remember, that at some point the translations were not visible in the frontend, when I forgot to add the them to one of the files.

May be it could be worth to try and test removing the enum translations from one file after another and test if translations are missing in the frontend. I currently just don't have the time for that.

So I would recommend to add your translations to all these files.