From b8ec0825d3ccf031b6b10b7b5d9ffd5816f04145 Mon Sep 17 00:00:00 2001 From: deftdawg Date: Fri, 19 Nov 2021 03:16:08 -0500 Subject: [PATCH] Add energy support to Neurio_Energy (#54445) * - Patch Neurio_Energy to support new HA energy Enables the Neurio Energy Meter as a Consumption device for Home Assistant Energy * Only return last_reset value for DEVICE_CLASS_ENERGY * Update homeassistant/components/neurio_energy/sensor.py Co-authored-by: Martin Hjelmare * Update with recommendations from CI/Black * Support new style typing * Attempt setting the state_class statically * Make state class static * Changing state class to STATE_CLASS_TOTAL_INCREASING and removing last_reset seems to work ok * Remove unused datetime import that was previously in last_reset * Apply suggestions from code review apply emontnemery's recommended changes Co-authored-by: Erik Montnemery Co-authored-by: Martin Hjelmare Co-authored-by: Erik Montnemery --- homeassistant/components/neurio_energy/sensor.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/neurio_energy/sensor.py b/homeassistant/components/neurio_energy/sensor.py index 37113dde8b7..b316281faa1 100644 --- a/homeassistant/components/neurio_energy/sensor.py +++ b/homeassistant/components/neurio_energy/sensor.py @@ -1,4 +1,6 @@ """Support for monitoring a Neurio energy sensor.""" +from __future__ import annotations + from datetime import timedelta import logging @@ -9,9 +11,16 @@ import voluptuous as vol from homeassistant.components.sensor import ( PLATFORM_SCHEMA, STATE_CLASS_MEASUREMENT, + STATE_CLASS_TOTAL_INCREASING, SensorEntity, ) -from homeassistant.const import CONF_API_KEY, ENERGY_KILO_WATT_HOUR, POWER_WATT +from homeassistant.const import ( + CONF_API_KEY, + DEVICE_CLASS_ENERGY, + DEVICE_CLASS_POWER, + ENERGY_KILO_WATT_HOUR, + POWER_WATT, +) import homeassistant.helpers.config_validation as cv from homeassistant.util import Throttle import homeassistant.util.dt as dt_util @@ -139,9 +148,12 @@ class NeurioEnergy(SensorEntity): if sensor_type == ACTIVE_TYPE: self._unit_of_measurement = POWER_WATT + self._attr_device_class = DEVICE_CLASS_POWER self._attr_state_class = STATE_CLASS_MEASUREMENT elif sensor_type == DAILY_TYPE: self._unit_of_measurement = ENERGY_KILO_WATT_HOUR + self._attr_device_class = DEVICE_CLASS_ENERGY + self._attr_state_class = STATE_CLASS_TOTAL_INCREASING @property def name(self):