Closed frenck closed 1 year ago
Thanks. I have already moved most of the sensor to the new enums
, but the remaining a locally defined constants I use to look up a local translated string. A while ago I found that if I defined a string and set the device_class to that string it would look up a translated value and display it in the UI. For this integration the sensor translation looks like below. And f.ex the device class constant DEVICE_CLASS_LOCAL_WIND_CARDINAL
has the value of wind_cardinal
, that then displays the value in the translated language in the UI.
So to the question: Is there another way of doing this for a custom component? Or any other suggestion on how I can avoid to break this, when removing the local device class?
{
"state": {
"aqi_description": {
"excellent": "Sehr gut",
"fine": "Gut",
"moderate": "Mittelmäßig",
"poor": "Ausreichend",
"very_poor": "Schlecht",
"severe": "Sehrt schlecht"
},
"trend": {
"falling": "Falling",
"rising": "Rising",
"steady": "Steady"
},
"beaufort": {
"calm": "Windstille",
"light_air": "Leiser Zug",
"light_breeze": "Leichte Brise",
"gentle_breeze": "Schwache Brise",
"moderate_breeze": "Mäßige Brise",
"fresh_breeze": "Frische Brise",
"strong_breeze": "Starker Wind",
"moderate_gale": "Steifer Wind",
"fresh_gale": "Stürmischer Wind",
"strong_gale": "Sturm",
"storm": "Schwerer Sturm",
"violent_storm": "Orkanartiger Sturm",
"hurricane": "Orkan"
},
"wind_cardinal": {
"n": "N",
"nne": "NNO",
"ne": "NO",
"ene": "ONO",
"e": "O",
"ese": "OSO",
"se": "SO",
"sse": "SSO",
"s": "S",
"ssw": "SSW",
"sw": "SW",
"wsw": "WSW",
"w": "W",
"wnw": "WNW",
"nw": "NW",
"nnw": "NNW"
},
"uv_description": {
"extreme": "Extrem",
"very-high": "Sehr hoch",
"high": "Hoch",
"moderate": "Mittel",
"low": "Gering",
"none": "Kein"
}
}
}
@briis As per 2023.1 release you do not need custom device classes for those anymore.
See: https://developers.home-assistant.io/blog/2022/12/01/entity_translations
../Frenck
How did I miss that 👏 Thanks. I have a little work to do.
All done, and after a bit of struggle I found the right json structure for my local translations to use the translation_key
.
This custom integration uses deprecated
DEVICE_CLASS_*
constants in its codebase.The
DEVICE_CLASS_*
constants have been deprecated and replaced in Home Assistant Core 2021.12 (over a year ago). I would highly suggest updating/migrating this integration to the new enums.For example, for the device classes supported by the
sensor
platform, there is now aSensorDeviceClass
enum. So if a sensor previously used theDEVICE_CLASS_ENERGY
constant, it should now useSensorDeviceClass.ENERGY
. Other platforms (likebinary_sensor
, andnumber
) provide similar enumerations for their supported device classes.The migration thus only consists of replacing constants with an enumeration member and is, therefore, very low impact and should be fairly straightforward.
If I can help resolve any questions regarding this change or migration, feel free to ask or respond to this issue. I'm happy to help!
Kindest regards,
../Frenck