Fix zwave_js meter sensor state class (#53716)

This commit is contained in:
Martin Hjelmare 2021-07-29 21:25:43 +02:00 committed by GitHub
parent 120a0bead0
commit 3c0e4b1fd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -229,8 +229,6 @@ class ZWaveNumericSensor(ZwaveSensorBase):
class ZWaveMeterSensor(ZWaveNumericSensor, RestoreEntity):
"""Representation of a Z-Wave Meter CC sensor."""
_attr_state_class = STATE_CLASS_MEASUREMENT
def __init__(
self,
config_entry: ConfigEntry,
@ -241,6 +239,7 @@ class ZWaveMeterSensor(ZWaveNumericSensor, RestoreEntity):
super().__init__(config_entry, client, info)
# Entity class attributes
self._attr_state_class = STATE_CLASS_MEASUREMENT
self._attr_last_reset = dt.utc_from_timestamp(0)
self._attr_device_class = DEVICE_CLASS_POWER
if self.info.primary_value.metadata.unit == "kWh":

View File

@ -3,7 +3,7 @@ from unittest.mock import patch
from zwave_js_server.event import Event
from homeassistant.components.sensor import ATTR_LAST_RESET
from homeassistant.components.sensor import ATTR_LAST_RESET, STATE_CLASS_MEASUREMENT
from homeassistant.components.zwave_js.const import (
ATTR_METER_TYPE,
ATTR_VALUE,
@ -62,6 +62,7 @@ async def test_energy_sensors(hass, hank_binary_switch, integration):
assert state.state == "0.0"
assert state.attributes["unit_of_measurement"] == POWER_WATT
assert state.attributes["device_class"] == DEVICE_CLASS_POWER
assert state.attributes["state_class"] == STATE_CLASS_MEASUREMENT
state = hass.states.get(ENERGY_SENSOR)
@ -69,6 +70,7 @@ async def test_energy_sensors(hass, hank_binary_switch, integration):
assert state.state == "0.16"
assert state.attributes["unit_of_measurement"] == ENERGY_KILO_WATT_HOUR
assert state.attributes["device_class"] == DEVICE_CLASS_ENERGY
assert state.attributes["state_class"] == STATE_CLASS_MEASUREMENT
async def test_disabled_notification_sensor(hass, multisensor_6, integration):