mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Remove last_reset attribute from fritz sensors (#54806)
This commit is contained in:
parent
bafbbc6563
commit
1280a38e0f
@ -8,7 +8,11 @@ from typing import Callable, TypedDict
|
|||||||
from fritzconnection.core.exceptions import FritzConnectionException
|
from fritzconnection.core.exceptions import FritzConnectionException
|
||||||
from fritzconnection.lib.fritzstatus import FritzStatus
|
from fritzconnection.lib.fritzstatus import FritzStatus
|
||||||
|
|
||||||
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
|
from homeassistant.components.sensor import (
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
|
SensorEntity,
|
||||||
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DATA_GIGABYTES,
|
DATA_GIGABYTES,
|
||||||
@ -134,7 +138,6 @@ class SensorData(TypedDict, total=False):
|
|||||||
name: str
|
name: str
|
||||||
device_class: str | None
|
device_class: str | None
|
||||||
state_class: str | None
|
state_class: str | None
|
||||||
last_reset: bool
|
|
||||||
unit_of_measurement: str | None
|
unit_of_measurement: str | None
|
||||||
icon: str | None
|
icon: str | None
|
||||||
state_provider: Callable
|
state_provider: Callable
|
||||||
@ -185,16 +188,14 @@ SENSOR_DATA = {
|
|||||||
),
|
),
|
||||||
"gb_sent": SensorData(
|
"gb_sent": SensorData(
|
||||||
name="GB sent",
|
name="GB sent",
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
last_reset=True,
|
|
||||||
unit_of_measurement=DATA_GIGABYTES,
|
unit_of_measurement=DATA_GIGABYTES,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
state_provider=_retrieve_gb_sent_state,
|
state_provider=_retrieve_gb_sent_state,
|
||||||
),
|
),
|
||||||
"gb_received": SensorData(
|
"gb_received": SensorData(
|
||||||
name="GB received",
|
name="GB received",
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
last_reset=True,
|
|
||||||
unit_of_measurement=DATA_GIGABYTES,
|
unit_of_measurement=DATA_GIGABYTES,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
state_provider=_retrieve_gb_received_state,
|
state_provider=_retrieve_gb_received_state,
|
||||||
@ -284,7 +285,6 @@ class FritzBoxSensor(FritzBoxBaseEntity, SensorEntity):
|
|||||||
"""Init FRITZ!Box connectivity class."""
|
"""Init FRITZ!Box connectivity class."""
|
||||||
self._sensor_data: SensorData = SENSOR_DATA[sensor_type]
|
self._sensor_data: SensorData = SENSOR_DATA[sensor_type]
|
||||||
self._last_device_value: str | None = None
|
self._last_device_value: str | None = None
|
||||||
self._last_wan_value: str | None = None
|
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
self._attr_device_class = self._sensor_data.get("device_class")
|
self._attr_device_class = self._sensor_data.get("device_class")
|
||||||
self._attr_icon = self._sensor_data.get("icon")
|
self._attr_icon = self._sensor_data.get("icon")
|
||||||
@ -316,12 +316,3 @@ class FritzBoxSensor(FritzBoxBaseEntity, SensorEntity):
|
|||||||
self._attr_native_value = self._last_device_value = self._state_provider(
|
self._attr_native_value = self._last_device_value = self._state_provider(
|
||||||
status, self._last_device_value
|
status, self._last_device_value
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._sensor_data.get("last_reset") is True:
|
|
||||||
self._last_wan_value = _retrieve_connection_uptime_state(
|
|
||||||
status, self._last_wan_value
|
|
||||||
)
|
|
||||||
self._attr_last_reset = datetime.datetime.strptime(
|
|
||||||
self._last_wan_value,
|
|
||||||
"%Y-%m-%dT%H:%M:%S%z",
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user