Skip to content

Commit

Permalink
Merge pull request #141 from DasBasti/140-update-intervals-are-not-co…
Browse files Browse the repository at this point in the history
…rrect

Update Intervals are not correct
  • Loading branch information
DasBasti authored Aug 6, 2024
2 parents ccacaaf + f346878 commit 698938e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
9 changes: 6 additions & 3 deletions custom_components/smarthashtag/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def hvac_mode(self) -> HVACMode:
)

# value is true, last setting is off -> keep on requesting
if current_mode == self._last_mode:
if (
current_mode == self._last_mode
and self.coordinator.update_interval.seconds == FAST_INTERVAL
):
self.coordinator.update_interval = timedelta(
seconds=self.coordinator.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
Expand Down Expand Up @@ -118,7 +121,7 @@ async def async_turn_on(self) -> None:
)
self._last_mode = HVACMode.HEAT_COOL
self.coordinator.update_interval = timedelta(seconds=FAST_INTERVAL)
await self.coordinator.async_refresh()
await self.coordinator.async_request_refresh()

async def async_turn_off(self) -> None:
"""Turn off the climate system."""
Expand All @@ -127,7 +130,7 @@ async def async_turn_off(self) -> None:
)
self._last_mode = HVACMode.OFF
self.coordinator.update_interval = timedelta(seconds=FAST_INTERVAL)
await self.coordinator.async_refresh()
await self.coordinator.async_request_refresh()

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature for the vehicle."""
Expand Down
57 changes: 28 additions & 29 deletions custom_components/smarthashtag/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
DEFAULT_DRIVING_INTERVAL,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
FAST_INTERVAL,
)
from .coordinator import SmartHashtagDataUpdateCoordinator
from .entity import SmartHashtagEntity
Expand Down Expand Up @@ -1027,23 +1026,24 @@ def native_value(self) -> str | int | float:
remove_vin_from_key(self.entity_description.key),
)

if (
"charging_current" in self.entity_description.key
and self.coordinator.update_interval.seconds != FAST_INTERVAL
):
if "charging_current" in self.entity_description.key:
scan_interval = self.coordinator.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
)
charging_interval = self.coordinator.config_entry.options.get(
CONF_CHARGING_INTERVAL, DEFAULT_CHARGING_INTERVAL
)
if data.value != 0:
self.coordinator.update_interval = timedelta(
seconds=self.coordinator.config_entry.options.get(
CONF_CHARGING_INTERVAL, DEFAULT_CHARGING_INTERVAL
if self.coordinator.update_interval.seconds == scan_interval:
self.coordinator.update_interval = timedelta(
seconds=charging_interval
)
)
else:
self.coordinator.update_interval = timedelta(
seconds=self.coordinator.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
self.hass.async_create_task(
self.coordinator.async_request_refresh()
)
)
self.hass.async_create_task(self.coordinator.async_request_refresh())
else:
if self.coordinator.update_interval.seconds == charging_interval:
self.coordinator.update_interval = timedelta(seconds=scan_interval)

if "charging_power" in self.entity_description.key:
if data.value == -0.0:
Expand Down Expand Up @@ -1149,25 +1149,24 @@ def native_value(self) -> float:
remove_vin_from_key(self.entity_description.key),
)

if (
key == "engine_state"
and self.coordinator.update_interval.seconds != FAST_INTERVAL
):
scan_interval = self.coordinator.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
)
driving_interval = self.coordinator.config_entry.options.get(
CONF_DRIVING_INTERVAL, DEFAULT_DRIVING_INTERVAL
)
if key == "engine_state":
if data == "engine_running":
self.coordinator.update_interval = timedelta(
seconds=self.coordinator.config_entry.options.get(
CONF_DRIVING_INTERVAL, DEFAULT_DRIVING_INTERVAL
if self.coordinator.update_interval.seconds == scan_interval:
self.coordinator.update_interval = timedelta(
seconds=driving_interval
)
)
self.hass.async_create_task(self.coordinator.async_request_refresh())
self.icon = "mdi:engine"
else:
self.coordinator.update_interval = timedelta(
seconds=self.coordinator.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
)
)
if self.coordinator.update_interval.seconds == driving_interval:
self.coordinator.update_interval = timedelta(seconds=scan_interval)
self.icon = "mdi:engine-off"
self.hass.async_create_task(self.coordinator.async_request_refresh())

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

0 comments on commit 698938e

Please sign in to comment.