briis / meteobridge

The Meteobridge Integration adds support for retrieving current weather data from a Meteobridge datalogger connected to a local Weather Station.
MIT License
14 stars 5 forks source link

Integration is using deprecated `DEVICE_CLASS_*` constants #27

Closed frenck closed 1 year ago

frenck commented 1 year ago

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 a SensorDeviceClass enum. So if a sensor previously used the DEVICE_CLASS_ENERGY constant, it should now use SensorDeviceClass.ENERGY. Other platforms (like binary_sensor, and number) 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

briis commented 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"
        }
    }
}
frenck commented 1 year ago

@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

briis commented 1 year ago

How did I miss that 👏 Thanks. I have a little work to do.

briis commented 1 year ago

All done, and after a bit of struggle I found the right json structure for my local translations to use the translation_key .