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

Integration is using deprecated DEVICE_CLASS_* constants #27

Closed
frenck opened this issue Jan 3, 2023 · 4 comments
Closed

Integration is using deprecated DEVICE_CLASS_* constants #27

frenck opened this issue Jan 3, 2023 · 4 comments

Comments

@frenck
Copy link

frenck commented Jan 3, 2023

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
Copy link
Owner

briis commented Jan 4, 2023

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
Copy link
Author

frenck commented Jan 4, 2023

@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
Copy link
Owner

briis commented Jan 4, 2023

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

@briis
Copy link
Owner

briis commented Jan 4, 2023

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

@briis briis closed this as completed Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants