Skip to content

Commit

Permalink
stop updating mower on notifications for now, trial experimental upda…
Browse files Browse the repository at this point in the history
…te interval changes
  • Loading branch information
mikey0000 committed Nov 13, 2024
1 parent 1202669 commit dec212a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions custom_components/mammotion/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from pymammotion.proto import has_field
from pymammotion.proto.luba_msg import LubaMsg
from pymammotion.proto.mctrl_sys import RptAct, RptDevStatus, RptInfoType
from pymammotion.utility.constant import WorkMode
from pymammotion.utility.device_type import DeviceType

from .const import (
Expand Down Expand Up @@ -175,8 +176,8 @@ def store_cloud_credentials(self) -> None:

async def _async_update_notification(self) -> None:
"""Update data from incoming messages."""
mower = self.manager.mower(self.device_name)
self.async_set_updated_data(mower)
# mower = self.manager.mower(self.device_name)
# self.async_set_updated_data(mower)

async def check_and_restore_cloud(self) -> CloudIOTGateway | None:
"""Check and restore previous cloud connection."""
Expand Down Expand Up @@ -349,6 +350,10 @@ async def async_save_data(self, data: MowingDevice) -> None:
await store.async_save(stored_data)


DEFAULT_INTERVAL = timedelta(minutes=5)
WORKING_INTERVAL = timedelta(seconds=5)


class MammotionDataUpdateCoordinator(MammotionBaseUpdateCoordinator[MowingDevice]):
"""Class to manage fetching mammotion data."""

Expand All @@ -357,7 +362,7 @@ def __init__(self, hass: HomeAssistant, config_entry: MammotionConfigEntry) -> N
super().__init__(
hass=hass,
config_entry=config_entry,
update_interval=timedelta(minutes=1),
update_interval=DEFAULT_INTERVAL,
)

async def async_sync_maps(self) -> None:
Expand Down Expand Up @@ -584,6 +589,12 @@ async def _async_update_data(self) -> MowingDevice:
self.update_failures = 0
data = self.manager.get_device_by_name(self.device_name).mower_state
await self.async_save_data(data)

if data.report_data.dev.sys_status is WorkMode.MODE_WORKING:
self.update_interval = WORKING_INTERVAL
else:
self.update_interval = DEFAULT_INTERVAL

return data

@property
Expand Down

0 comments on commit dec212a

Please sign in to comment.