Use POWER device class in enphase_envoy (#83811)

This commit is contained in:
epenet 2022-12-12 11:49:02 +01:00 committed by GitHub
parent 4fe025b297
commit 1667b4b19e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View file

@ -1,12 +1,10 @@
"""The enphase_envoy component.""" """The enphase_envoy component."""
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
SensorDeviceClass, SensorDeviceClass,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import ENERGY_WATT_HOUR, POWER_WATT, Platform from homeassistant.const import Platform, UnitOfEnergy, UnitOfPower
DOMAIN = "enphase_envoy" DOMAIN = "enphase_envoy"
@ -20,54 +18,56 @@ SENSORS = (
SensorEntityDescription( SensorEntityDescription(
key="production", key="production",
name="Current Power Production", name="Current Power Production",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER,
), ),
SensorEntityDescription( SensorEntityDescription(
key="daily_production", key="daily_production",
name="Today's Energy 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, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SensorEntityDescription( SensorEntityDescription(
key="seven_days_production", key="seven_days_production",
name="Last Seven Days Energy 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, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SensorEntityDescription( SensorEntityDescription(
key="lifetime_production", key="lifetime_production",
name="Lifetime Energy Production", name="Lifetime Energy Production",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SensorEntityDescription( SensorEntityDescription(
key="consumption", key="consumption",
name="Current Power Consumption", name="Current Power Consumption",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER,
), ),
SensorEntityDescription( SensorEntityDescription(
key="daily_consumption", key="daily_consumption",
name="Today's Energy 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, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SensorEntityDescription( SensorEntityDescription(
key="seven_days_consumption", key="seven_days_consumption",
name="Last Seven Days Energy 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, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),
SensorEntityDescription( SensorEntityDescription(
key="lifetime_consumption", key="lifetime_consumption",
name="Lifetime Energy Consumption", name="Lifetime Energy Consumption",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
), ),

View file

@ -14,7 +14,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 from homeassistant.const import 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
@ -60,8 +60,9 @@ def _inverter_last_report_time(
INVERTER_SENSORS = ( INVERTER_SENSORS = (
EnvoySensorEntityDescription( EnvoySensorEntityDescription(
key=INVERTERS_KEY, key=INVERTERS_KEY,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER,
value_fn=lambda watt_report_time: watt_report_time[0], value_fn=lambda watt_report_time: watt_report_time[0],
), ),
EnvoySensorEntityDescription( EnvoySensorEntityDescription(