Skip to content

Commit

Permalink
Use UnitOfPower in integrations [a-g] (#83812)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Dec 12, 2022
1 parent 431df61 commit 4fe025b
Show file tree
Hide file tree
Showing 23 changed files with 88 additions and 91 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/atome/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
CONF_PASSWORD,
CONF_USERNAME,
ENERGY_KILO_WATT_HOUR,
POWER_WATT,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -262,7 +262,7 @@ def __init__(self, data, name, sensor_type):

if sensor_type == LIVE_TYPE:
self._attr_device_class = SensorDeviceClass.POWER
self._attr_native_unit_of_measurement = POWER_WATT
self._attr_native_unit_of_measurement = UnitOfPower.WATT
self._attr_state_class = SensorStateClass.MEASUREMENT
else:
self._attr_device_class = SensorDeviceClass.ENERGY
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/aurora_abb_powerone/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT, TEMP_CELSIUS
from homeassistant.const import ENERGY_KILO_WATT_HOUR, TEMP_CELSIUS, UnitOfPower
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -28,7 +28,7 @@
SensorEntityDescription(
key="instantaneouspower",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
name="Power Output",
),
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/bosch_shc/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
CONCENTRATION_PARTS_PER_MILLION,
ENERGY_KILO_WATT_HOUR,
PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -302,7 +302,7 @@ class PowerSensor(SHCEntity, SensorEntity):
"""Representation of an SHC power reporting sensor."""

_attr_device_class = SensorDeviceClass.POWER
_attr_native_unit_of_measurement = POWER_WATT
_attr_native_unit_of_measurement = UnitOfPower.WATT

def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None:
"""Initialize an SHC power reporting sensor."""
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/broadlink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR,
PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS,
UnitOfElectricCurrent,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -53,7 +53,7 @@
SensorEntityDescription(
key="power",
name="Current power",
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/comfoconnect/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
CONF_RESOURCES,
ENERGY_KILO_WATT_HOUR,
PERCENTAGE,
POWER_WATT,
REVOLUTIONS_PER_MINUTE,
TEMP_CELSIUS,
TIME_DAYS,
VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -241,7 +241,7 @@ class ComfoconnectSensorEntityDescription(
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
name="Power usage",
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
sensor_id=SENSOR_POWER_CURRENT,
),
ComfoconnectSensorEntityDescription(
Expand All @@ -257,7 +257,7 @@ class ComfoconnectSensorEntityDescription(
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
name="Preheater power usage",
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
sensor_id=SENSOR_PREHEATER_POWER_CURRENT,
),
ComfoconnectSensorEntityDescription(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/daikin/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
ENERGY_KILO_WATT_HOUR,
FREQUENCY_HERTZ,
PERCENTAGE,
POWER_KILO_WATT,
TEMP_CELSIUS,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
Expand Down Expand Up @@ -90,7 +90,7 @@ class DaikinSensorEntityDescription(SensorEntityDescription, DaikinRequiredKeysM
name="Compressor estimated power consumption",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
value_func=lambda device: round(device.current_total_power_consumption, 2),
),
DaikinSensorEntityDescription(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/deconz/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
ENERGY_KILO_WATT_HOUR,
LIGHT_LUX,
PERCENTAGE,
POWER_WATT,
PRESSURE_HPA,
TEMP_CELSIUS,
UnitOfPower,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory
Expand Down Expand Up @@ -180,7 +180,7 @@ class DeconzSensorDescription(SensorEntityDescription, DeconzSensorDescriptionMi
instance_check=Power,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
),
DeconzSensorDescription[Pressure](
key="pressure",
Expand Down
18 changes: 9 additions & 9 deletions homeassistant/components/dsmr_reader/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
CURRENCY_EURO,
ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR,
POWER_KILO_WATT,
VOLUME_CUBIC_METERS,
UnitOfElectricCurrent,
UnitOfPower,
)
from homeassistant.util import dt as dt_util

Expand Down Expand Up @@ -78,62 +78,62 @@ class DSMRReaderSensorEntityDescription(SensorEntityDescription):
key="dsmr/reading/electricity_currently_delivered",
name="Current power usage",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRReaderSensorEntityDescription(
key="dsmr/reading/electricity_currently_returned",
name="Current power return",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRReaderSensorEntityDescription(
key="dsmr/reading/phase_currently_delivered_l1",
name="Current power usage L1",
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRReaderSensorEntityDescription(
key="dsmr/reading/phase_currently_delivered_l2",
name="Current power usage L2",
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRReaderSensorEntityDescription(
key="dsmr/reading/phase_currently_delivered_l3",
name="Current power usage L3",
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRReaderSensorEntityDescription(
key="dsmr/reading/phase_currently_returned_l1",
name="Current power return L1",
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRReaderSensorEntityDescription(
key="dsmr/reading/phase_currently_returned_l2",
name="Current power return L2",
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRReaderSensorEntityDescription(
key="dsmr/reading/phase_currently_returned_l3",
name="Current power return L3",
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRReaderSensorEntityDescription(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/edl21/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
ENERGY_KILO_WATT_HOUR,
ENERGY_WATT_HOUR,
FREQUENCY_HERTZ,
POWER_WATT,
UnitOfElectricCurrent,
UnitOfPower,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_registry as er
Expand Down Expand Up @@ -257,7 +257,7 @@
SENSOR_UNIT_MAPPING = {
"Wh": ENERGY_WATT_HOUR,
"kWh": ENERGY_KILO_WATT_HOUR,
"W": POWER_WATT,
"W": UnitOfPower.WATT,
"A": UnitOfElectricCurrent.AMPERE,
"V": ELECTRIC_POTENTIAL_VOLT,
"°": DEGREE,
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/efergy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SensorStateClass,
)
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.helpers import entity_platform
from homeassistant.helpers.typing import StateType
Expand All @@ -27,7 +27,7 @@
key="instant_readings",
name="Power Usage",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
Expand Down Expand Up @@ -97,7 +97,7 @@
key=CONF_CURRENT_VALUES,
name="Power Usage",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/emoncms/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
CONF_UNIT_OF_MEASUREMENT,
CONF_URL,
CONF_VALUE_TEMPLATE,
POWER_WATT,
STATE_UNKNOWN,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import template
Expand All @@ -46,7 +46,7 @@
CONF_SENSOR_NAMES = "sensor_names"

DECIMALS = 2
DEFAULT_UNIT = POWER_WATT
DEFAULT_UNIT = UnitOfPower.WATT
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=5)

ONLY_INCL_EXCL_NONE = "only_include_exclude_or_none"
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/emonitor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import POWER_WATT
from homeassistant.const import UnitOfPower
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import DeviceInfo
Expand Down Expand Up @@ -64,7 +64,7 @@ class EmonitorPowerSensor(CoordinatorEntity, SensorEntity):
"""Representation of an Emonitor power sensor entity."""

_attr_device_class = SensorDeviceClass.POWER
_attr_native_unit_of_measurement = POWER_WATT
_attr_native_unit_of_measurement = UnitOfPower.WATT
_attr_state_class = SensorStateClass.MEASUREMENT

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/enocean/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
CONF_ID,
CONF_NAME,
PERCENTAGE,
POWER_WATT,
STATE_CLOSED,
STATE_OPEN,
TEMP_CELSIUS,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -82,7 +82,7 @@ class EnOceanSensorEntityDescription(
SENSOR_DESC_POWER = EnOceanSensorEntityDescription(
key=SENSOR_TYPE_POWER,
name="Power",
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
icon="mdi:power-plug",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/forecast_solar/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import timedelta

from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT
from homeassistant.const import ENERGY_KILO_WATT_HOUR, UnitOfPower

from .models import ForecastSolarSensorEntityDescription

Expand Down Expand Up @@ -47,7 +47,7 @@
device_class=SensorDeviceClass.POWER,
state=lambda estimate: estimate.power_production_now,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
),
ForecastSolarSensorEntityDescription(
key="power_production_next_hour",
Expand All @@ -57,7 +57,7 @@
name="Estimated power production - next hour",
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
),
ForecastSolarSensorEntityDescription(
key="power_production_next_12hours",
Expand All @@ -67,7 +67,7 @@
name="Estimated power production - next 12 hours",
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
),
ForecastSolarSensorEntityDescription(
key="power_production_next_24hours",
Expand All @@ -77,7 +77,7 @@
name="Estimated power production - next 24 hours",
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
),
ForecastSolarSensorEntityDescription(
key="energy_current_hour",
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/fritzbox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR,
PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS,
UnitOfElectricCurrent,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
Expand Down Expand Up @@ -131,7 +131,7 @@ def value_scheduled_preset(device: FritzhomeDevice) -> str:
FritzSensorEntityDescription(
key="power_consumption",
name="Power Consumption",
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return]
Expand Down
Loading

0 comments on commit 4fe025b

Please sign in to comment.