Skip to content

Commit

Permalink
re-add in updating info but only for report info, seperate out mainta…
Browse files Browse the repository at this point in the history
…in data
  • Loading branch information
mikey0000 committed Nov 19, 2024
1 parent 92f8797 commit 8fdb12e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
44 changes: 36 additions & 8 deletions custom_components/mammotion/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
from . import MammotionConfigEntry


MAINTENENCE_INTERVAL = timedelta(minutes=30)
DEFAULT_INTERVAL = timedelta(minutes=1)
WORKING_INTERVAL = timedelta(seconds=5)


class MammotionBaseUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
"""Mammotion DataUpdateCoordinator."""

Expand Down Expand Up @@ -174,10 +179,13 @@ def store_cloud_credentials(self) -> None:
self.config_entry, data=config_updates
)

async def _async_update_notification(self) -> None:
async def _async_update_notification(self, res: tuple[str, Any | None]) -> None:
"""Update data from incoming messages."""
# mower = self.manager.mower(self.device_name)
# self.async_set_updated_data(mower)
if res[0] == "sys" and res[1] is not None:
sys_msg = betterproto.which_one_of(res[1], "SubSysMsg")
if sys_msg[0] == "toapp_report_data":
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 @@ -350,10 +358,6 @@ 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 Down Expand Up @@ -573,8 +577,8 @@ async def _async_update_data(self) -> MowingDevice:
):
await self.manager.start_map_sync(self.device_name)

# if not device.has_queued_commands():
await self.async_send_command("get_report_cfg")
await self.async_send_command("get_maintenance")

LOGGER.debug("Updated Mammotion device %s", self.device_name)
LOGGER.debug("================= Debug Log =================")
Expand Down Expand Up @@ -608,3 +612,27 @@ def operation_settings(self) -> OperationSettings:
# await self.async_setup()
# except COMMAND_EXCEPTIONS as exc:
# raise UpdateFailed(f"Setting up Mammotion device failed: {exc}") from exc


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

def __init__(self, hass: HomeAssistant, config_entry: MammotionConfigEntry) -> None:
"""Initialize global mammotion data updater."""
super().__init__(
hass=hass,
config_entry=config_entry,
update_interval=MAINTENENCE_INTERVAL,
)

async def _async_update_data(self) -> MowingDevice:
"""Get data from the device."""

if not self.enabled:
return self.data

await self.async_send_command("get_maintenance")

return self.manager.get_device_by_name(self.device_name).mower_state.report_data
2 changes: 1 addition & 1 deletion custom_components/mammotion/lawn_mower.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async def async_start_mowing(self, **kwargs: Any) -> None:
if mode == WorkMode.MODE_READY:
trans_key = "start_failed"
if self.report_data.work.area >> 16 != 0:
await self.coordinator.async_send_command("start_job")
await self.coordinator.async_send_command("resume_execute_task")
return
if await self.coordinator.async_plan_route(operational_settings):
await self.coordinator.async_send_command("start_job")
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mammotion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
],
"iot_class": "local_push",
"requirements": [
"pymammotion==0.3.3"
"pymammotion==0.3.4"
]
}
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "~3.12.0"
pymammotion = "0.3.3"
pymammotion = "0.3.4"
homeassistant = "^2024.9.0"
autotyping = "^24.3.0"

Expand Down

0 comments on commit 8fdb12e

Please sign in to comment.