From 1667b4b19edf59c8fa98eb989c59cc3e66874701 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 12 Dec 2022 11:49:02 +0100 Subject: [PATCH] Use POWER device class in enphase_envoy (#83811) --- .../components/enphase_envoy/const.py | 22 +++++++++---------- .../components/enphase_envoy/sensor.py | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/enphase_envoy/const.py b/homeassistant/components/enphase_envoy/const.py index 7c493168526..16aae3f9a64 100644 --- a/homeassistant/components/enphase_envoy/const.py +++ b/homeassistant/components/enphase_envoy/const.py @@ -1,12 +1,10 @@ """The enphase_envoy component.""" - - from homeassistant.components.sensor import ( SensorDeviceClass, SensorEntityDescription, SensorStateClass, ) -from homeassistant.const import ENERGY_WATT_HOUR, POWER_WATT, Platform +from homeassistant.const import Platform, UnitOfEnergy, UnitOfPower DOMAIN = "enphase_envoy" @@ -20,54 +18,56 @@ SENSORS = ( SensorEntityDescription( key="production", name="Current Power Production", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, state_class=SensorStateClass.MEASUREMENT, + device_class=SensorDeviceClass.POWER, ), SensorEntityDescription( key="daily_production", name="Today's Energy Production", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.ENERGY, ), SensorEntityDescription( key="seven_days_production", name="Last Seven Days Energy Production", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.ENERGY, ), SensorEntityDescription( key="lifetime_production", name="Lifetime Energy Production", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.ENERGY, ), SensorEntityDescription( key="consumption", name="Current Power Consumption", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, state_class=SensorStateClass.MEASUREMENT, + device_class=SensorDeviceClass.POWER, ), SensorEntityDescription( key="daily_consumption", name="Today's Energy Consumption", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.ENERGY, ), SensorEntityDescription( key="seven_days_consumption", name="Last Seven Days Energy Consumption", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.ENERGY, ), SensorEntityDescription( key="lifetime_consumption", name="Lifetime Energy Consumption", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.ENERGY, ), diff --git a/homeassistant/components/enphase_envoy/sensor.py b/homeassistant/components/enphase_envoy/sensor.py index c8d791907a6..2870a61d9a0 100644 --- a/homeassistant/components/enphase_envoy/sensor.py +++ b/homeassistant/components/enphase_envoy/sensor.py @@ -14,7 +14,7 @@ from homeassistant.components.sensor import ( 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.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -60,8 +60,9 @@ def _inverter_last_report_time( INVERTER_SENSORS = ( EnvoySensorEntityDescription( key=INVERTERS_KEY, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, state_class=SensorStateClass.MEASUREMENT, + device_class=SensorDeviceClass.POWER, value_fn=lambda watt_report_time: watt_report_time[0], ), EnvoySensorEntityDescription(