toreamun / amshan-homeassistant

Home Assistant integrasjon for strømmålere (AMS/HAN/P1). Integrasjonen støter både streaming (serieport/TCP-IP) og MQTT (Tibber Pulse, energyintelligence.se etc)
MIT License
146 stars 9 forks source link

POWER_WATT was used from amshan, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfPower.WATT instead #69

Open lindsand opened 8 months ago

lindsand commented 8 months ago

Warnings after upgrading to HA Core 2024.1.0 4.1.2024

Logger: homeassistant.const Source: helpers/deprecation.py:204 First occurred: 17:51:09 (17 occurrences) Last logged: 17:52:52

POWER_WATT was used from amshan, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfPower.WATT instead.

ELECTRIC_CURRENT_AMPERE was used from amshan, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfElectricCurrent.AMPERE instead.

ELECTRIC_POTENTIAL_VOLT was used from amshan, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfElectricPotential.VOLT instead.

ENERGY_KILO_WATT_HOUR was used from amshan, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfEnergy.KILO_WATT_HOUR instead.

troppavegen84 commented 7 months ago

So, where/how do I change this?

lindsand commented 7 months ago

The values are assigned in sensor.py and field native_unit_of_measurement is the one getting warnings

https://github.com/toreamun/amshan-homeassistant/blob/master/custom_components/amshan/sensor.py

    AmsHanSensorEntityDescription(
        key=obis_map.FIELD_ACTIVE_POWER_EXPORT,
        device_class=SensorDeviceClass.POWER,
        native_unit_of_measurement=ha_const.POWER_WATT,
        state_class=SensorStateClass.MEASUREMENT,
        icon=ICON_POWER_EXPORT,
        name="Active power export (Q2+Q3)",
        decimals=0,
        use_configured_scaling=True,

Valid values are included from HA: from homeassistant import const as ha_const

so defined here: https://github.com/home-assistant/core/blob/dev/homeassistant/const.py

...

Power units class UnitOfPower(StrEnum): """Power units."""

WATT = "W"
KILO_WATT = "kW"
BTU_PER_HOUR = "BTU/h"

_DEPRECATED_POWER_WATT: Final = DeprecatedConstantEnum( UnitOfPower.WATT, "2025.1", ) """Deprecated: please use UnitOfPower.WATT.""" _DEPRECATED_POWER_KILO_WATT: Final = DeprecatedConstantEnum( UnitOfPower.KILO_WATT, "2025.1", )

Electric_current units class UnitOfElectricCurrent(StrEnum): """Electric current units."""

MILLIAMPERE = "mA"
AMPERE = "A"

_DEPRECATED_ELECTRIC_CURRENT_MILLIAMPERE: Final = DeprecatedConstantEnum( UnitOfElectricCurrent.MILLIAMPERE, "2025.1", ) """Deprecated: please use UnitOfElectricCurrent.MILLIAMPERE.""" _DEPRECATED_ELECTRIC_CURRENT_AMPERE: Final = DeprecatedConstantEnum( UnitOfElectricCurrent.AMPERE, "2025.1", ) """Deprecated: please use UnitOfElectricCurrent.AMPERE."""

and so on also for the other units.

lindsand commented 7 months ago

Here is a related one, total_increasing would be preferred.

Logger: homeassistant.components.sensor Source: components/sensor/init.py:576 Integration: Sensor (documentation, issues) First occurred: 16:42:45 (2 occurrences) Last logged: 16:42:45

Entity sensor.adn9_energy_active_negative (<class 'homeassistant.components.mqtt.sensor.MqttSensor'>) is using state class 'measurement' which is impossible considering device class ('energy') it is using; expected None or one of 'total', 'total_increasing';

Entity sensor.adn9_energy_active_positive (<class 'homeassistant.components.mqtt.sensor.MqttSensor'>) is using state class 'measurement' which is impossible considering device class ('energy') it is using; expected None or one of 'total', 'total_increasing';