Use UnitOfPower in integrations [s-z] (#83826)

This commit is contained in:
epenet 2022-12-12 12:20:16 +01:00 committed by GitHub
parent eb6310f7bb
commit 52d4a358a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 69 additions and 70 deletions

View file

@ -22,9 +22,9 @@ from homeassistant.const import (
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
LIGHT_LUX, LIGHT_LUX,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TEMP_CELSIUS, TEMP_CELSIUS,
UnitOfPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
@ -97,7 +97,7 @@ SENSORS: Final = {
("light", "power"): BlockSensorDescription( ("light", "power"): BlockSensorDescription(
key="light|power", key="light|power",
name="Power", name="Power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
value=lambda value: round(value, 1), value=lambda value: round(value, 1),
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -106,7 +106,7 @@ SENSORS: Final = {
("device", "power"): BlockSensorDescription( ("device", "power"): BlockSensorDescription(
key="device|power", key="device|power",
name="Power", name="Power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
value=lambda value: round(value, 1), value=lambda value: round(value, 1),
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -114,7 +114,7 @@ SENSORS: Final = {
("emeter", "power"): BlockSensorDescription( ("emeter", "power"): BlockSensorDescription(
key="emeter|power", key="emeter|power",
name="Power", name="Power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
value=lambda value: round(value, 1), value=lambda value: round(value, 1),
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -147,7 +147,7 @@ SENSORS: Final = {
("relay", "power"): BlockSensorDescription( ("relay", "power"): BlockSensorDescription(
key="relay|power", key="relay|power",
name="Power", name="Power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
value=lambda value: round(value, 1), value=lambda value: round(value, 1),
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -155,7 +155,7 @@ SENSORS: Final = {
("roller", "rollerPower"): BlockSensorDescription( ("roller", "rollerPower"): BlockSensorDescription(
key="roller|rollerPower", key="roller|rollerPower",
name="Power", name="Power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
value=lambda value: round(value, 1), value=lambda value: round(value, 1),
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -317,7 +317,7 @@ RPC_SENSORS: Final = {
key="switch", key="switch",
sub_key="apower", sub_key="apower",
name="Power", name="Power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
value=lambda status, _: round(float(status), 1), value=lambda status, _: round(float(status), 1),
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,

View file

@ -11,7 +11,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT from homeassistant.const import ENERGY_KILO_WATT_HOUR, UnitOfPower
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -73,7 +73,7 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
if self.native_unit_of_measurement == ENERGY_KILO_WATT_HOUR: if self.native_unit_of_measurement == ENERGY_KILO_WATT_HOUR:
self._attr_state_class = SensorStateClass.TOTAL_INCREASING self._attr_state_class = SensorStateClass.TOTAL_INCREASING
self._attr_device_class = SensorDeviceClass.ENERGY self._attr_device_class = SensorDeviceClass.ENERGY
if self.native_unit_of_measurement == POWER_WATT: if self.native_unit_of_measurement == UnitOfPower.WATT:
self._attr_state_class = SensorStateClass.MEASUREMENT self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_device_class = SensorDeviceClass.POWER self._attr_device_class = SensorDeviceClass.POWER

View file

@ -14,7 +14,7 @@ from homeassistant.const import (
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
ENERGY_WATT_HOUR, ENERGY_WATT_HOUR,
POWER_WATT, UnitOfPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
@ -53,7 +53,7 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = (
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
key="total_power", key="total_power",
name="Total consumption - Active power", name="Total consumption - Active power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
sensor_id="total_power", sensor_id="total_power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -62,7 +62,7 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = (
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
key="alwayson", key="alwayson",
name="Always on - Active power", name="Always on - Active power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
sensor_id="alwayson", sensor_id="alwayson",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -104,7 +104,7 @@ REACTIVE_SENSORS: tuple[SmappeeSensorEntityDescription, ...] = (
SmappeeSensorEntityDescription( SmappeeSensorEntityDescription(
key="total_reactive_power", key="total_reactive_power",
name="Total consumption - Reactive power", name="Total consumption - Reactive power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
sensor_id="total_reactive_power", sensor_id="total_reactive_power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -114,7 +114,7 @@ SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = (
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
key="solar_power", key="solar_power",
name="Total production - Active power", name="Total production - Active power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
sensor_id="solar_power", sensor_id="solar_power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -254,7 +254,7 @@ async def async_setup_entry(
description=SmappeeSensorEntityDescription( description=SmappeeSensorEntityDescription(
key="load", key="load",
name=measurement.name, name=measurement.name,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
sensor_id=measurement_id, sensor_id=measurement_id,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,

View file

@ -3,7 +3,7 @@ from datetime import timedelta
import logging import logging
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import ENERGY_WATT_HOUR, PERCENTAGE, POWER_WATT from homeassistant.const import ENERGY_WATT_HOUR, PERCENTAGE, UnitOfPower
from .models import SolarEdgeSensorEntityDescription from .models import SolarEdgeSensorEntityDescription
@ -70,7 +70,7 @@ SENSOR_TYPES = [
name="Current Power", name="Current Power",
icon="mdi:solar-power", icon="mdi:solar-power",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
), ),
SolarEdgeSensorEntityDescription( SolarEdgeSensorEntityDescription(

View file

@ -21,8 +21,8 @@ from homeassistant.const import (
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
FREQUENCY_HERTZ, FREQUENCY_HERTZ,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS, TEMP_CELSIUS,
UnitOfPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
@ -70,7 +70,7 @@ SENSOR_DESCRIPTIONS: dict[tuple[Units, bool], SensorEntityDescription] = {
(Units.W, False): SensorEntityDescription( (Units.W, False): SensorEntityDescription(
key=f"{Units.W}_{False}", key=f"{Units.W}_{False}",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
(Units.PERCENT, False): SensorEntityDescription( (Units.PERCENT, False): SensorEntityDescription(

View file

@ -7,7 +7,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT from homeassistant.const import ENERGY_KILO_WATT_HOUR, UnitOfPower
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -76,7 +76,7 @@ class SpiderPowerPlugPower(SensorEntity):
_attr_device_class = SensorDeviceClass.POWER _attr_device_class = SensorDeviceClass.POWER
_attr_state_class = SensorStateClass.MEASUREMENT _attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = POWER_WATT _attr_native_unit_of_measurement = UnitOfPower.WATT
def __init__(self, api, power_plug) -> None: def __init__(self, api, power_plug) -> None:
"""Initialize the Spider Power Plug.""" """Initialize the Spider Power Plug."""

View file

@ -11,7 +11,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import POWER_WATT, UnitOfElectricCurrent from homeassistant.const import UnitOfElectricCurrent, UnitOfPower
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -38,7 +38,7 @@ class AttributeDescription:
POWER_SENSORS = { POWER_SENSORS = {
"power_consumption": AttributeDescription( "power_consumption": AttributeDescription(
name="Power Consumption", name="Power Consumption",
unit=POWER_WATT, unit=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),

View file

@ -21,9 +21,9 @@ from homeassistant.const import (
FREQUENCY_HERTZ, FREQUENCY_HERTZ,
FREQUENCY_MEGAHERTZ, FREQUENCY_MEGAHERTZ,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
REVOLUTIONS_PER_MINUTE, REVOLUTIONS_PER_MINUTE,
TEMP_CELSIUS, TEMP_CELSIUS,
UnitOfPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -455,7 +455,7 @@ async def async_setup_entry(
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
value=lambda data, k=gpu["key"]: getattr(data.gpu, f"{k}_power"), value=lambda data, k=gpu["key"]: getattr(data.gpu, f"{k}_power"),
), ),
entry.data[CONF_PORT], entry.data[CONF_PORT],

View file

@ -27,7 +27,6 @@ from homeassistant.const import (
LIGHT_LUX, LIGHT_LUX,
MASS_KILOGRAMS, MASS_KILOGRAMS,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
PRESSURE_HPA, PRESSURE_HPA,
SIGNAL_STRENGTH_DECIBELS, SIGNAL_STRENGTH_DECIBELS,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
@ -38,6 +37,7 @@ from homeassistant.const import (
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
TEMP_KELVIN, TEMP_KELVIN,
UnitOfApparentPower, UnitOfApparentPower,
UnitOfPower,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -221,7 +221,7 @@ SENSOR_UNIT_MAP = {
hc.LIGHT_LUX: LIGHT_LUX, hc.LIGHT_LUX: LIGHT_LUX,
hc.MASS_KILOGRAMS: MASS_KILOGRAMS, hc.MASS_KILOGRAMS: MASS_KILOGRAMS,
hc.PERCENTAGE: PERCENTAGE, hc.PERCENTAGE: PERCENTAGE,
hc.POWER_WATT: POWER_WATT, hc.POWER_WATT: UnitOfPower.WATT,
hc.PRESSURE_HPA: PRESSURE_HPA, hc.PRESSURE_HPA: PRESSURE_HPA,
hc.SIGNAL_STRENGTH_DECIBELS: SIGNAL_STRENGTH_DECIBELS, hc.SIGNAL_STRENGTH_DECIBELS: SIGNAL_STRENGTH_DECIBELS,
hc.SIGNAL_STRENGTH_DECIBELS_MILLIWATT: SIGNAL_STRENGTH_DECIBELS_MILLIWATT, hc.SIGNAL_STRENGTH_DECIBELS_MILLIWATT: SIGNAL_STRENGTH_DECIBELS_MILLIWATT,

View file

@ -31,8 +31,8 @@ from homeassistant.const import (
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_STOP,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
SIGNAL_STRENGTH_DECIBELS, SIGNAL_STRENGTH_DECIBELS,
UnitOfPower,
) )
from homeassistant.core import Event, HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
@ -61,33 +61,33 @@ RT_SENSORS: tuple[SensorEntityDescription, ...] = (
key="averagePower", key="averagePower",
name="average power", name="average power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="power", key="power",
name="power", name="power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="powerProduction", key="powerProduction",
name="power production", name="power production",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="minPower", key="minPower",
name="min power", name="min power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="maxPower", key="maxPower",
name="max power", name="max power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="accumulatedConsumption", key="accumulatedConsumption",

View file

@ -13,8 +13,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS, TEMP_CELSIUS,
UnitOfPower,
UnitOfVolume, UnitOfVolume,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -212,7 +212,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = (
name="Average Power Usage", name="Average Power Usage",
section="power_usage", section="power_usage",
measurement="average", measurement="average",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
cls=ToonElectricityMeterDeviceSensor, cls=ToonElectricityMeterDeviceSensor,
@ -272,7 +272,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = (
name="Current Power Usage", name="Current Power Usage",
section="power_usage", section="power_usage",
measurement="current", measurement="current",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
cls=ToonElectricityMeterDeviceSensor, cls=ToonElectricityMeterDeviceSensor,
@ -372,7 +372,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = (
name="Current Solar Power Production", name="Current Solar Power Production",
section="power_usage", section="power_usage",
measurement="current_solar", measurement="current_solar",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
cls=ToonSolarDeviceSensor, cls=ToonSolarDeviceSensor,
@ -382,7 +382,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = (
name="Max Solar Power Production Today", name="Max Solar Power Production Today",
section="power_usage", section="power_usage",
measurement="day_max_solar", measurement="day_max_solar",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
cls=ToonSolarDeviceSensor, cls=ToonSolarDeviceSensor,
), ),
@ -391,7 +391,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = (
name="Solar Power Production to Grid", name="Solar Power Production to Grid",
section="power_usage", section="power_usage",
measurement="current_produced", measurement="current_produced",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
cls=ToonSolarDeviceSensor, cls=ToonSolarDeviceSensor,
@ -431,7 +431,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = (
name="Average Solar Power Production to Grid", name="Average Solar Power Production to Grid",
section="power_usage", section="power_usage",
measurement="average_produced", measurement="average_produced",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
cls=ToonSolarDeviceSensor, cls=ToonSolarDeviceSensor,

View file

@ -18,7 +18,7 @@ from homeassistant.const import (
ELECTRIC_CURRENT_AMPERE, ELECTRIC_CURRENT_AMPERE,
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
POWER_WATT, UnitOfPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -46,7 +46,7 @@ class TPLinkSensorEntityDescription(SensorEntityDescription):
ENERGY_SENSORS: tuple[TPLinkSensorEntityDescription, ...] = ( ENERGY_SENSORS: tuple[TPLinkSensorEntityDescription, ...] = (
TPLinkSensorEntityDescription( TPLinkSensorEntityDescription(
key=ATTR_CURRENT_POWER_W, key=ATTR_CURRENT_POWER_W,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
name="Current Consumption", name="Current Consumption",

View file

@ -22,8 +22,6 @@ from homeassistant.const import (
ENERGY_WATT_HOUR, ENERGY_WATT_HOUR,
LIGHT_LUX, LIGHT_LUX,
PERCENTAGE, PERCENTAGE,
POWER_KILO_WATT,
POWER_WATT,
PRESSURE_BAR, PRESSURE_BAR,
PRESSURE_HPA, PRESSURE_HPA,
PRESSURE_INHG, PRESSURE_INHG,
@ -37,6 +35,7 @@ from homeassistant.const import (
VOLUME_CUBIC_FEET, VOLUME_CUBIC_FEET,
VOLUME_CUBIC_METERS, VOLUME_CUBIC_METERS,
Platform, Platform,
UnitOfPower,
) )
DOMAIN = "tuya" DOMAIN = "tuya"
@ -505,12 +504,12 @@ UNITS = (
conversion_fn=lambda x: x * 1000, conversion_fn=lambda x: x * 1000,
), ),
UnitOfMeasurement( UnitOfMeasurement(
unit=POWER_WATT, unit=UnitOfPower.WATT,
aliases={"watt"}, aliases={"watt"},
device_classes={SensorDeviceClass.POWER}, device_classes={SensorDeviceClass.POWER},
), ),
UnitOfMeasurement( UnitOfMeasurement(
unit=POWER_KILO_WATT, unit=UnitOfPower.KILO_WATT,
aliases={"kilowatt"}, aliases={"kilowatt"},
device_classes={SensorDeviceClass.POWER}, device_classes={SensorDeviceClass.POWER},
), ),

View file

@ -16,9 +16,9 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
PERCENTAGE, PERCENTAGE,
POWER_KILO_WATT,
TIME_MINUTES, TIME_MINUTES,
UnitOfElectricCurrent, UnitOfElectricCurrent,
UnitOfPower,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -675,7 +675,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
name="Phase A power", name="Phase A power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT, native_unit_of_measurement=UnitOfPower.KILO_WATT,
subkey="power", subkey="power",
), ),
TuyaSensorEntityDescription( TuyaSensorEntityDescription(
@ -699,7 +699,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
name="Phase B power", name="Phase B power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT, native_unit_of_measurement=UnitOfPower.KILO_WATT,
subkey="power", subkey="power",
), ),
TuyaSensorEntityDescription( TuyaSensorEntityDescription(
@ -723,7 +723,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
name="Phase C power", name="Phase C power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT, native_unit_of_measurement=UnitOfPower.KILO_WATT,
subkey="power", subkey="power",
), ),
TuyaSensorEntityDescription( TuyaSensorEntityDescription(
@ -757,7 +757,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
name="Phase A power", name="Phase A power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT, native_unit_of_measurement=UnitOfPower.KILO_WATT,
subkey="power", subkey="power",
), ),
TuyaSensorEntityDescription( TuyaSensorEntityDescription(
@ -781,7 +781,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
name="Phase B power", name="Phase B power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT, native_unit_of_measurement=UnitOfPower.KILO_WATT,
subkey="power", subkey="power",
), ),
TuyaSensorEntityDescription( TuyaSensorEntityDescription(
@ -805,7 +805,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
name="Phase C power", name="Phase C power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT, native_unit_of_measurement=UnitOfPower.KILO_WATT,
subkey="power", subkey="power",
), ),
TuyaSensorEntityDescription( TuyaSensorEntityDescription(

View file

@ -15,10 +15,10 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
LIGHT_LUX, LIGHT_LUX,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
Platform, Platform,
UnitOfPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -90,7 +90,7 @@ class VeraSensor(VeraDevice[veraApi.VeraSensor], SensorEntity):
if self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR: if self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
return PERCENTAGE return PERCENTAGE
if self.vera_device.category == veraApi.CATEGORY_POWER_METER: if self.vera_device.category == veraApi.CATEGORY_POWER_METER:
return POWER_WATT return UnitOfPower.WATT
return None return None
def update(self) -> None: def update(self) -> None:

View file

@ -21,7 +21,7 @@ from homeassistant.const import (
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
PERCENTAGE, PERCENTAGE,
POWER_WATT, UnitOfPower,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -105,7 +105,7 @@ SENSORS: tuple[VeSyncSensorEntityDescription, ...] = (
key="power", key="power",
name="current power", name="current power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda device: device.details["power"], value_fn=lambda device: device.details["power"],
update_fn=update_energy, update_fn=update_energy,

View file

@ -17,7 +17,7 @@ from homeassistant.const import (
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
LENGTH_KILOMETERS, LENGTH_KILOMETERS,
PERCENTAGE, PERCENTAGE,
POWER_KILO_WATT, UnitOfPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -62,7 +62,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
key=CHARGER_CHARGING_POWER_KEY, key=CHARGER_CHARGING_POWER_KEY,
name="Charging Power", name="Charging Power",
precision=2, precision=2,
native_unit_of_measurement=POWER_KILO_WATT, native_unit_of_measurement=UnitOfPower.KILO_WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),

View file

@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT from homeassistant.const import ENERGY_KILO_WATT_HOUR, UnitOfPower
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -37,7 +37,7 @@ ATTRIBUTE_SENSORS = (
name="Current Power", name="Current Power",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
key="current_power_watts", key="current_power_watts",
unique_id_suffix="currentpower", unique_id_suffix="currentpower",
state_conversion=lambda state: round(cast(float, state), 2), state_conversion=lambda state: round(cast(float, state), 2),

View file

@ -8,7 +8,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import POWER_WATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, UnitOfPower
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -36,7 +36,7 @@ POWER_SENSORS: tuple[SensorEntityDescription, ...] = (
name="Current power", name="Current power",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
), ),
) )

View file

@ -14,9 +14,9 @@ from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_BATTERY_LEVEL,
LIGHT_LUX, LIGHT_LUX,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
PRESSURE_HPA, PRESSURE_HPA,
TEMP_CELSIUS, TEMP_CELSIUS,
UnitOfPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -65,7 +65,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
), ),
"load_power": SensorEntityDescription( "load_power": SensorEntityDescription(
key="load_power", key="load_power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),

View file

@ -12,7 +12,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_DEVICE, CONF_DEVICE,
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
POWER_WATT, UnitOfPower,
UnitOfVolume, UnitOfVolume,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -117,7 +117,7 @@ class GasSensor(YoulessBaseSensor):
class CurrentPowerSensor(YoulessBaseSensor): class CurrentPowerSensor(YoulessBaseSensor):
"""The current power usage sensor.""" """The current power usage sensor."""
_attr_native_unit_of_measurement = POWER_WATT _attr_native_unit_of_measurement = UnitOfPower.WATT
_attr_device_class = SensorDeviceClass.POWER _attr_device_class = SensorDeviceClass.POWER
_attr_state_class = SensorStateClass.MEASUREMENT _attr_state_class = SensorStateClass.MEASUREMENT
@ -220,7 +220,7 @@ class ExtraMeterSensor(YoulessBaseSensor):
class ExtraMeterPowerSensor(YoulessBaseSensor): class ExtraMeterPowerSensor(YoulessBaseSensor):
"""The Youless extra meter power value sensor (s0).""" """The Youless extra meter power value sensor (s0)."""
_attr_native_unit_of_measurement = POWER_WATT _attr_native_unit_of_measurement = UnitOfPower.WATT
_attr_device_class = SensorDeviceClass.POWER _attr_device_class = SensorDeviceClass.POWER
_attr_state_class = SensorStateClass.MEASUREMENT _attr_state_class = SensorStateClass.MEASUREMENT

View file

@ -19,9 +19,9 @@ from homeassistant.const import (
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
LIGHT_LUX, LIGHT_LUX,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
PRESSURE_KPA, PRESSURE_KPA,
TEMP_CELSIUS, TEMP_CELSIUS,
UnitOfPower,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -97,7 +97,7 @@ SENSORS_MAP: dict[str, ZWaveMeSensorEntityDescription] = {
"meterElectric_watt": ZWaveMeSensorEntityDescription( "meterElectric_watt": ZWaveMeSensorEntityDescription(
key="meterElectric_watt", key="meterElectric_watt",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
"temperature": ZWaveMeSensorEntityDescription( "temperature": ZWaveMeSensorEntityDescription(