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 <marhje52@gmail.com>

* 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 <erik@montnemery.com>

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
deftdawg 2021-11-19 03:16:08 -05:00 committed by GitHub
parent 2f00f8d3de
commit b8ec0825d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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):