Add last reset to Shelly (#53654)
This commit is contained in:
parent
d40012f110
commit
bbd1a85b09
2 changed files with 11 additions and 0 deletions
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from typing import Any, Callable, Final, cast
|
||||
|
||||
|
@ -179,6 +180,7 @@ class BlockAttributeDescription:
|
|||
# Callable (settings, block), return true if entity should be removed
|
||||
removal_condition: Callable[[dict, aioshelly.Block], bool] | None = None
|
||||
extra_state_attributes: Callable[[aioshelly.Block], dict | None] | None = None
|
||||
last_reset: datetime | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Sensor for Shelly."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Final, cast
|
||||
|
||||
from homeassistant.components import sensor
|
||||
|
@ -20,6 +21,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.util import dt
|
||||
|
||||
from .const import SHAIR_MAX_WORK_HOURS
|
||||
from .entity import (
|
||||
|
@ -119,6 +121,7 @@ SENSORS: Final = {
|
|||
value=lambda value: round(value / 1000, 2),
|
||||
device_class=sensor.DEVICE_CLASS_ENERGY,
|
||||
state_class=sensor.STATE_CLASS_MEASUREMENT,
|
||||
last_reset=dt.utc_from_timestamp(0),
|
||||
),
|
||||
("emeter", "energyReturned"): BlockAttributeDescription(
|
||||
name="Energy Returned",
|
||||
|
@ -126,6 +129,7 @@ SENSORS: Final = {
|
|||
value=lambda value: round(value / 1000, 2),
|
||||
device_class=sensor.DEVICE_CLASS_ENERGY,
|
||||
state_class=sensor.STATE_CLASS_MEASUREMENT,
|
||||
last_reset=dt.utc_from_timestamp(0),
|
||||
),
|
||||
("light", "energy"): BlockAttributeDescription(
|
||||
name="Energy",
|
||||
|
@ -257,6 +261,11 @@ class ShellySensor(ShellyBlockAttributeEntity, SensorEntity):
|
|||
"""State class of sensor."""
|
||||
return self.description.state_class
|
||||
|
||||
@property
|
||||
def last_reset(self) -> datetime | None:
|
||||
"""State class of sensor."""
|
||||
return self.description.last_reset
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
"""Return unit of sensor."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue