diff --git a/custom_components/mammotion/coordinator.py b/custom_components/mammotion/coordinator.py index 81894aa..60aa92a 100644 --- a/custom_components/mammotion/coordinator.py +++ b/custom_components/mammotion/coordinator.py @@ -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.""" @@ -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.""" @@ -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.""" @@ -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 =================") @@ -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 diff --git a/custom_components/mammotion/lawn_mower.py b/custom_components/mammotion/lawn_mower.py index 5d11fa2..e4e6674 100644 --- a/custom_components/mammotion/lawn_mower.py +++ b/custom_components/mammotion/lawn_mower.py @@ -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") diff --git a/custom_components/mammotion/manifest.json b/custom_components/mammotion/manifest.json index 0f51678..452adcc 100644 --- a/custom_components/mammotion/manifest.json +++ b/custom_components/mammotion/manifest.json @@ -30,6 +30,6 @@ ], "iot_class": "local_push", "requirements": [ - "pymammotion==0.3.3" + "pymammotion==0.3.4" ] } diff --git a/poetry.lock b/poetry.lock index 662eaa5..28d38c1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2686,13 +2686,13 @@ testutils = ["gitpython (>3)"] [[package]] name = "pymammotion" -version = "0.3.1" +version = "0.3.4" description = "" optional = false python-versions = "<3.13,>=3.10" files = [ - {file = "pymammotion-0.3.1-py3-none-any.whl", hash = "sha256:c55a4e699b4cba91837de5864f840d0f7ece327d0e66c179697f797f8a3c13b5"}, - {file = "pymammotion-0.3.1.tar.gz", hash = "sha256:b149abf1ca68c449dd574930347fef9c3946c8ad71e8ce53a4e8906b37cf4ba2"}, + {file = "pymammotion-0.3.4-py3-none-any.whl", hash = "sha256:95e20a5c152225bb5e2d617fe962ae190ac1d4d7a749021ebca97d5dd4be6903"}, + {file = "pymammotion-0.3.4.tar.gz", hash = "sha256:b252dfc1154f1067a343e1cbcece5748e414ca8b09c9705c97544387361aaa9a"}, ] [package.dependencies] @@ -3655,4 +3655,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "~3.12.0" -content-hash = "129a780541206c74dd91ef0a96efe72d9886a855a8d942fdd1f7a5bc23d3405b" +content-hash = "06e8220223df977da9b8490b8cded8058a46b82c0f4768b9f36d4a629ced53c0" diff --git a/pyproject.toml b/pyproject.toml index e6aefbb..3930dbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"