Skip to content

Commit

Permalink
Sensors: increase update interval while charging
Browse files Browse the repository at this point in the history
  • Loading branch information
DasBasti committed Feb 5, 2024
1 parent a041fe6 commit 540acf0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions custom_components/smarthashtag/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Sensor platform for Smar #1/#3 intergration."""
from __future__ import annotations

from datetime import timedelta

from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import SensorEntityDescription
from pysmarthashtag.models import ValueWithUnit
Expand Down Expand Up @@ -198,6 +200,13 @@ def native_value(self) -> int:
data = getattr(
self.coordinator.account.vehicles[0].battery, self.entity_description.key
)

if self.entity_description.key == "charging_current":
if data.value != 0:
self.coordinator.update_interval = timedelta(seconds=30)
else:
self.coordinator.update_interval = timedelta(minutes=5)

if isinstance(data, ValueWithUnit):
return data.value

Expand Down

0 comments on commit 540acf0

Please sign in to comment.