From 5b663b1fb9ec9b1a20b2d1649f2f7429cc3bf3ca Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 23 Jun 2021 19:46:00 +0200 Subject: [PATCH] Add state class to Enphase Envoy (#52113) --- homeassistant/components/enphase_envoy/const.py | 17 ++++++++++------- .../components/enphase_envoy/sensor.py | 4 ++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/enphase_envoy/const.py b/homeassistant/components/enphase_envoy/const.py index 89803d32351..7a1de25e242 100644 --- a/homeassistant/components/enphase_envoy/const.py +++ b/homeassistant/components/enphase_envoy/const.py @@ -1,6 +1,7 @@ """The enphase_envoy component.""" +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT from homeassistant.const import ENERGY_WATT_HOUR, POWER_WATT DOMAIN = "enphase_envoy" @@ -12,19 +13,21 @@ COORDINATOR = "coordinator" NAME = "name" SENSORS = { - "production": ("Current Energy Production", POWER_WATT), - "daily_production": ("Today's Energy Production", ENERGY_WATT_HOUR), + "production": ("Current Energy Production", POWER_WATT, STATE_CLASS_MEASUREMENT), + "daily_production": ("Today's Energy Production", ENERGY_WATT_HOUR, None), "seven_days_production": ( "Last Seven Days Energy Production", ENERGY_WATT_HOUR, + None, ), - "lifetime_production": ("Lifetime Energy Production", ENERGY_WATT_HOUR), - "consumption": ("Current Energy Consumption", POWER_WATT), - "daily_consumption": ("Today's Energy Consumption", ENERGY_WATT_HOUR), + "lifetime_production": ("Lifetime Energy Production", ENERGY_WATT_HOUR, None), + "consumption": ("Current Energy Consumption", POWER_WATT, STATE_CLASS_MEASUREMENT), + "daily_consumption": ("Today's Energy Consumption", ENERGY_WATT_HOUR, None), "seven_days_consumption": ( "Last Seven Days Energy Consumption", ENERGY_WATT_HOUR, + None, ), - "lifetime_consumption": ("Lifetime Energy Consumption", ENERGY_WATT_HOUR), - "inverters": ("Inverter", POWER_WATT), + "lifetime_consumption": ("Lifetime Energy Consumption", ENERGY_WATT_HOUR, None), + "inverters": ("Inverter", POWER_WATT, STATE_CLASS_MEASUREMENT), } diff --git a/homeassistant/components/enphase_envoy/sensor.py b/homeassistant/components/enphase_envoy/sensor.py index 050a497f69e..5ccb540efd0 100644 --- a/homeassistant/components/enphase_envoy/sensor.py +++ b/homeassistant/components/enphase_envoy/sensor.py @@ -74,6 +74,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): config_entry.unique_id, serial_number, SENSORS[condition][1], + SENSORS[condition][2], coordinator, ) ) @@ -91,6 +92,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): config_entry.unique_id, None, SENSORS[condition][1], + SENSORS[condition][2], coordinator, ) ) @@ -109,6 +111,7 @@ class Envoy(CoordinatorEntity, SensorEntity): device_serial_number, serial_number, unit, + state_class, coordinator, ): """Initialize Envoy entity.""" @@ -118,6 +121,7 @@ class Envoy(CoordinatorEntity, SensorEntity): self._device_name = device_name self._device_serial_number = device_serial_number self._unit_of_measurement = unit + self._attr_state_class = state_class super().__init__(coordinator)