From 517fd7075a092d68c3bae2aa3c71cb1eaca5396f Mon Sep 17 00:00:00 2001 From: SCA075 <82227818+sca075@users.noreply.github.com> Date: Wed, 16 Oct 2024 08:38:22 +0200 Subject: [PATCH 1/8] Adding in_room and fix loaded map for Rand256 sensors. Signed-off-by: 82227818+sca075@users.noreply.github.com <82227818+sca075@users.noreply.github.com> --- .../mqtt_vacuum_camera/coordinator.py | 21 ++++++++++++++----- .../mqtt_vacuum_camera/sensor.py | 9 ++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/custom_components/mqtt_vacuum_camera/coordinator.py b/custom_components/mqtt_vacuum_camera/coordinator.py index 6bff9149..285c8b38 100644 --- a/custom_components/mqtt_vacuum_camera/coordinator.py +++ b/custom_components/mqtt_vacuum_camera/coordinator.py @@ -1,8 +1,9 @@ """ MQTT Vacuum Camera Coordinator. -Version: v2024.10.0 +Version: v2024.11.0 """ +import asyncio from datetime import timedelta import logging from typing import Optional @@ -53,6 +54,15 @@ def __init__( # Initialize shared data and MQTT connector self.shared, self.file_name = self._init_shared_data(self.vacuum_topic) self.start_up_mqtt() + self.scheduled_refresh: asyncio.TimerHandle | None = None + + def schedule_refresh(self) -> None: + """Schedule coordinator refresh after 1 second.""" + if self.scheduled_refresh: + self.scheduled_refresh.cancel() + self.scheduled_refresh = self.hass.loop.call_later( + 1, lambda: asyncio.create_task(self.async_refresh()) + ) async def _async_update_data(self): """ @@ -99,9 +109,7 @@ def start_up_mqtt(self) -> ValetudoConnector: """ Initialize the MQTT Connector. """ - self.connector = ValetudoConnector( - self.vacuum_topic, self.hass, self.shared - ) + self.connector = ValetudoConnector(self.vacuum_topic, self.hass, self.shared) return self.connector def update_shared_data(self, dev_info: DeviceInfo) -> tuple[CameraShared, str]: @@ -134,7 +142,9 @@ async def async_update_sensor_data(self, sensor_data): # Assume sensor_data is a dictionary or transform it into the expected format battery_level = await self.connector.get_battery_level() vacuum_state = await self.connector.get_vacuum_status() + vacuum_room = self.shared.current_room last_run_stats = sensor_data.get("last_run_stats", {}) + last_loaded_map = sensor_data.get("last_loaded_map", {}) formatted_data = { "mainBrush": sensor_data.get("mainBrush", 0), "sideBrush": sensor_data.get("sideBrush", 0), @@ -152,7 +162,8 @@ async def async_update_sensor_data(self, sensor_data): "last_run_area": last_run_stats.get("area", 0), "last_bin_out": sensor_data.get("last_bin_out", 0), "last_bin_full": sensor_data.get("last_bin_full", 0), - "last_loaded_map": sensor_data.get("last_loaded_map", "None"), + "last_loaded_map": last_loaded_map.get("name", "NoMap"), + "robot_in_room": vacuum_room.get("in_room", "Unsupported"), } return formatted_data return SENSOR_NO_DATA diff --git a/custom_components/mqtt_vacuum_camera/sensor.py b/custom_components/mqtt_vacuum_camera/sensor.py index 718648cb..c5b75752 100644 --- a/custom_components/mqtt_vacuum_camera/sensor.py +++ b/custom_components/mqtt_vacuum_camera/sensor.py @@ -155,9 +155,17 @@ class VacuumSensorDescription(SensorEntityDescription): key="last_loaded_map", icon="mdi:map", name="Last loaded map", + device_class=SensorDeviceClass.ENUM, entity_category=EntityCategory.DIAGNOSTIC, value=lambda v, _: v if isinstance(v, str) else "Unknown", ), + "robot_in_room": VacuumSensorDescription( + key="robot_in_room", + icon="mdi:location-enter", + name="Current Room", + entity_category=EntityCategory.DIAGNOSTIC, + value=lambda v, _: v if isinstance(v, str) else "Unsupported", + ), } @@ -242,6 +250,7 @@ async def _handle_coordinator_update(self): self.async_write_ha_state() + def convert_duration(seconds): """Convert seconds in days""" # Create a timedelta object from seconds From d09abc0f2112cc0b4232605452ebdc09d21bd8f9 Mon Sep 17 00:00:00 2001 From: SCA075 <82227818+sca075@users.noreply.github.com> Date: Wed, 16 Oct 2024 08:42:15 +0200 Subject: [PATCH 2/8] Adding Support for Pkohelrs maploader. Signed-off-by: 82227818+sca075@users.noreply.github.com <82227818+sca075@users.noreply.github.com> --- .../mqtt_vacuum_camera/camera.py | 12 ++--- custom_components/mqtt_vacuum_camera/const.py | 4 +- .../valetudo/MQTT/connector.py | 54 +++++++++++++++---- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/custom_components/mqtt_vacuum_camera/camera.py b/custom_components/mqtt_vacuum_camera/camera.py index 592d65f0..556a9f84 100755 --- a/custom_components/mqtt_vacuum_camera/camera.py +++ b/custom_components/mqtt_vacuum_camera/camera.py @@ -1,6 +1,6 @@ """ Camera -Version: v2024.10.0 +Version: v2024.11.0 """ from __future__ import annotations @@ -84,7 +84,7 @@ def __init__(self, coordinator, device_info): self._attr_brand = "MQTT Vacuum Camera" self._attr_name = "Camera" self._attr_is_on = True - self._directory_path = self.hass.config.path() # get Home Assistant path + self._homeassistant_path = self.hass.config.path() # get Home Assistant path self._shared, self._file_name = coordinator.update_shared_data(device_info) self._start_up_logs() self._storage_path, self.snapshot_img, self.log_file = self._init_paths() @@ -135,9 +135,9 @@ def _init_clear_www_folder(self): """Remove PNG and ZIP's stored in HA config WWW""" # If enable_snapshots check if for png in www if not self._shared.enable_snapshots and os.path.isfile( - f"{self._directory_path}/www/snapshot_{self._file_name}.png" + f"{self._homeassistant_path}/www/snapshot_{self._file_name}.png" ): - os.remove(f"{self._directory_path}/www/snapshot_{self._file_name}.png") + os.remove(f"{self._homeassistant_path}/www/snapshot_{self._file_name}.png") # If there is a log zip in www remove it if os.path.isfile(self.log_file): os.remove(self.log_file) @@ -146,7 +146,7 @@ def _init_paths(self): """Initialize Camera Paths""" storage_path = f"{self.hass.config.path(STORAGE_DIR)}/{CAMERA_STORAGE}" if not os.path.exists(storage_path): - storage_path = f"{self._directory_path}/{STORAGE_DIR}" + storage_path = f"{self._homeassistant_path}/{STORAGE_DIR}" snapshot_img = f"{storage_path}/{self._file_name}.png" log_file = f"{storage_path}/{self._file_name}.zip" return storage_path, snapshot_img, log_file @@ -225,7 +225,7 @@ def extra_state_attributes(self) -> dict: return attributes async def handle_vacuum_start(self, event): - """Handle the vacuum.start event.""" + """Handle the event_vacuum_start event.""" _LOGGER.debug(f"Received event: {event.event_type}, Data: {event.data}") # Call the reset_trims service when vacuum.start event occurs diff --git a/custom_components/mqtt_vacuum_camera/const.py b/custom_components/mqtt_vacuum_camera/const.py index d957998f..57a45418 100755 --- a/custom_components/mqtt_vacuum_camera/const.py +++ b/custom_components/mqtt_vacuum_camera/const.py @@ -1,6 +1,6 @@ """Constants for the mqtt_vacuum_camera integration.""" -"""Version v2024.10.0""" +"""Version v2024.11.0""" """Required in Config_Flow""" PLATFORMS = ["camera"] @@ -270,6 +270,8 @@ DECODED_TOPICS = { "/MapData/segments", + "/maploader/map", + "/maploader/status", "/StatusStateAttribute/status", "/StatusStateAttribute/error_description", "/$state", diff --git a/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py b/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py index 436d4db8..541456c6 100755 --- a/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py +++ b/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py @@ -1,5 +1,5 @@ """ -Version: v2024.10.0 +Version: v2024.11.0 - Removed the PNG decode, the json is extracted from map-data instead of map-data-hass. - Refactoring the subscribe method and decode payload method. """ @@ -56,6 +56,8 @@ def __init__(self, mqtt_topic: str, hass: HomeAssistant, camera_shared): f"{self._mqtt_topic}/hass/{self._mqtt_topic.split('/')[-1]}_vacuum/command" ) self.rrm_command = f"{self._mqtt_topic}/command" # added for ValetudoRe + self._pkohelrs_maploader_map = None + self.pkohelrs_state = None async def update_data(self, process: bool = True): """ @@ -103,6 +105,12 @@ async def update_data(self, process: bool = True): self._is_rrm = False return None, data_type + async def async_get_pkohelrs_maploader_map(self) -> str: + """Return the Loaded Map of Dreame vacuums""" + if self._pkohelrs_maploader_map: + return self._pkohelrs_maploader_map + return "No Maps Loaded" + async def get_vacuum_status(self) -> str: """Return the vacuum status.""" if self._mqtt_vac_stat: @@ -142,6 +150,19 @@ async def get_rand256_attributes(self): return self.rrm_attributes return {} + async def handle_pkohelrs_maploader_map(self, msg) -> None: + """Handle Pkohelrs Maploader current map loaded payload""" + self._pkohelrs_maploader_map = await self.async_decode_mqtt_payload(msg) + _LOGGER.debug(f"{self._file_name}: Loaded Map {self._pkohelrs_maploader_map}.") + + async def handle_pkohelrs_maploader_state(self, msg) -> str: + """Get the pkohelrs state and handle camera restart""" + new_state = await self.async_decode_mqtt_payload(msg) + _LOGGER.debug(f"{self._file_name}: {self.pkohelrs_state} -> {new_state}") + if (self.pkohelrs_state == "loading_map") and (new_state == "idle"): + await self.async_fire_event_restart_camera(data=str(msg.payload)) + return new_state + async def hypfer_handle_image_data(self, msg) -> None: """ Handle new MQTT messages. @@ -156,7 +177,7 @@ async def hypfer_handle_image_data(self, msg) -> None: async def hypfer_handle_status_payload(self, state) -> None: """ Handle new MQTT messages. - /StatusStateAttribute/status" is for Hypfer. + /StatusStateAttribute/status is for Hypfer. """ if state: self._mqtt_vac_stat = state @@ -220,7 +241,9 @@ async def hypfer_handle_map_segments(self, msg): """ self._mqtt_segments = await self.async_decode_mqtt_payload(msg) # Store the decoded segments in RoomStore - await self._room_store.async_set_rooms_data(self._file_name, self._mqtt_segments) + await self._room_store.async_set_rooms_data( + self._file_name, self._mqtt_segments + ) async def rand256_handle_image_payload(self, msg): """ @@ -303,15 +326,22 @@ async def rrm_handle_active_segments(self, msg) -> None: self._shared.rand256_active_zone = rrm_active_segments + async def async_fire_event_restart_camera( + self, event_text:str="event_vacuum_start", data:str ="" + ): + """Fire Event to reset the camera trims""" + _LOGGER.debug(f"{event_text} <<<<<<<<<<<<<<<") + self._hass.bus.async_fire( + event_text, + event_data=data, + origin=EventOrigin.local, + ) + async def async_handle_start_command(self, msg): """fire event vacuum start""" if str(msg.payload).lower() == "start": # Fire the vacuum.start event when START command is detected - self._hass.bus.async_fire( - "event_vacuum_start", - event_data=str(msg.payload), - origin=EventOrigin.local, - ) + await self.async_fire_event_restart_camera(data=str(msg.payload)) @callback async def async_message_received(self, msg) -> None: @@ -354,6 +384,10 @@ async def async_message_received(self, msg) -> None: await self.async_handle_start_command(msg) elif self._rcv_topic == f"{self._mqtt_topic}/attributes": self.rrm_attributes = await self.async_decode_mqtt_payload(msg) + elif self._rcv_topic == f"{self._mqtt_topic}/maploader/map": + await self.handle_pkohelrs_maploader_map(msg) + elif self._rcv_topic == f"{self._mqtt_topic}/maploader/status": + self.pkohelrs_state = await self.handle_pkohelrs_maploader_state(msg) async def async_subscribe_to_topics(self) -> None: """Subscribe to the MQTT topics for Hypfer and ValetudoRe.""" @@ -421,8 +455,8 @@ def parse_string_payload(string_payload: str) -> Any: else: return msg.payload except ValueError as e: - _LOGGER.warning(f"Value error during payload decoding: {e}") - raise + _LOGGER.warning(f"Value error during payload decoding: {e}") + raise except TypeError as e: _LOGGER.warning(f"Type error during payload decoding: {e}") raise From 7cae6455ca8532624e09a8d340ea2e24fe951a23 Mon Sep 17 00:00:00 2001 From: SCA075 <82227818+sca075@users.noreply.github.com> Date: Wed, 16 Oct 2024 08:45:40 +0200 Subject: [PATCH 3/8] Updated manifest.json pillow dep. Signed-off-by: 82227818+sca075@users.noreply.github.com <82227818+sca075@users.noreply.github.com> --- custom_components/mqtt_vacuum_camera/manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/mqtt_vacuum_camera/manifest.json b/custom_components/mqtt_vacuum_camera/manifest.json index b5139e5a..a711386b 100755 --- a/custom_components/mqtt_vacuum_camera/manifest.json +++ b/custom_components/mqtt_vacuum_camera/manifest.json @@ -7,6 +7,6 @@ "documentation": "https://github.com/sca075/mqtt_vacuum_camera", "iot_class": "local_polling", "issue_tracker": "https://github.com/sca075/mqtt_vacuum_camera/issues", - "requirements": ["pillow>=10.3.0,<10.5.0", "numpy"], - "version": "2024.10.0" + "requirements": ["pillow<=11.0.0", "numpy"], + "version": "2024.11.0b0" } From 72b57a440badff5498d55a09b14335f245df8f35 Mon Sep 17 00:00:00 2001 From: SCA075 <82227818+sca075@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:06:15 +0200 Subject: [PATCH 4/8] tone_instructions: 'cool' Signed-off-by: 82227818+sca075@users.noreply.github.com <82227818+sca075@users.noreply.github.com> --- .coderabbit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.coderabbit.yaml b/.coderabbit.yaml index b03bd437..c6f5a8ee 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -1,5 +1,5 @@ language: en-US -tone_instructions: '' +tone_instructions: 'cool' early_access: false enable_free_tier: true reviews: From b041a5876506671715082633e59a8239a4b77d96 Mon Sep 17 00:00:00 2001 From: SCA075 <82227818+sca075@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:06:15 +0200 Subject: [PATCH 5/8] tone_instructions: 'cool' Signed-off-by: 82227818+sca075@users.noreply.github.com <82227818+sca075@users.noreply.github.com> --- .coderabbit.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.coderabbit.yaml b/.coderabbit.yaml index b03bd437..c174ba0d 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -1,5 +1,5 @@ language: en-US -tone_instructions: '' +tone_instructions: 'cool' early_access: false enable_free_tier: true reviews: @@ -22,7 +22,7 @@ reviews: path_instructions: [] abort_on_close: true auto_review: - enabled: false + enabled: true auto_incremental_review: true ignore_title_keywords: [] labels: [] From 150bbf9f32fb553efe7f857ea2fed9939b98f053 Mon Sep 17 00:00:00 2001 From: SCA075 <82227818+sca075@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:10:10 +0200 Subject: [PATCH 6/8] changes on event_data and pillow dep. Signed-off-by: 82227818+sca075@users.noreply.github.com <82227818+sca075@users.noreply.github.com> --- custom_components/mqtt_vacuum_camera/manifest.json | 2 +- .../mqtt_vacuum_camera/valetudo/MQTT/connector.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/custom_components/mqtt_vacuum_camera/manifest.json b/custom_components/mqtt_vacuum_camera/manifest.json index a711386b..9fec4ea7 100755 --- a/custom_components/mqtt_vacuum_camera/manifest.json +++ b/custom_components/mqtt_vacuum_camera/manifest.json @@ -7,6 +7,6 @@ "documentation": "https://github.com/sca075/mqtt_vacuum_camera", "iot_class": "local_polling", "issue_tracker": "https://github.com/sca075/mqtt_vacuum_camera/issues", - "requirements": ["pillow<=11.0.0", "numpy"], + "requirements": ["pillow>=10.3.0,<=11.0.0", "numpy"], "version": "2024.11.0b0" } diff --git a/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py b/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py index 541456c6..777cd245 100755 --- a/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py +++ b/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py @@ -330,10 +330,13 @@ async def async_fire_event_restart_camera( self, event_text:str="event_vacuum_start", data:str ="" ): """Fire Event to reset the camera trims""" - _LOGGER.debug(f"{event_text} <<<<<<<<<<<<<<<") self._hass.bus.async_fire( event_text, - event_data=data, + event_data={ + "device_id": f"mqtt_vacuum_{self._file_name}", + "type": "mqtt_payload", + "data": data, + }, origin=EventOrigin.local, ) From 5565a16b1002c814eaf83fdd60678e3b36fc0f05 Mon Sep 17 00:00:00 2001 From: SCA075 <82227818+sca075@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:44:54 +0200 Subject: [PATCH 7/8] handle_pkohelrs_maploader_state modified to set the self.pkohelrs_state. Fixed an issue vacuum_room == None Signed-off-by: 82227818+sca075@users.noreply.github.com <82227818+sca075@users.noreply.github.com> --- custom_components/mqtt_vacuum_camera/const.py | 11 ++++++++++- custom_components/mqtt_vacuum_camera/coordinator.py | 6 ++++-- .../mqtt_vacuum_camera/valetudo/MQTT/connector.py | 6 +++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/custom_components/mqtt_vacuum_camera/const.py b/custom_components/mqtt_vacuum_camera/const.py index 57a45418..e8e5fad9 100755 --- a/custom_components/mqtt_vacuum_camera/const.py +++ b/custom_components/mqtt_vacuum_camera/const.py @@ -53,12 +53,21 @@ "mainBrush": 0, "sideBrush": 0, "filter": 0, - "sensor": 0, "currentCleanTime": 0, "currentCleanArea": 0, "cleanTime": 0, "cleanArea": 0, "cleanCount": 0, + "battery": 0, + "state": 0, + "last_run_start": 0, + "last_run_end": 0, + "last_run_duration": 0, + "last_run_area": 0, + "last_bin_out": 0, + "last_bin_full": 0, + "last_loaded_map": "NoMap", + "robot_in_room": "Unsupported" } DEFAULT_PIXEL_SIZE = 5 diff --git a/custom_components/mqtt_vacuum_camera/coordinator.py b/custom_components/mqtt_vacuum_camera/coordinator.py index 285c8b38..0c74168e 100644 --- a/custom_components/mqtt_vacuum_camera/coordinator.py +++ b/custom_components/mqtt_vacuum_camera/coordinator.py @@ -70,7 +70,7 @@ async def _async_update_data(self): """ if (self.sensor_data == SENSOR_NO_DATA) or ( self.shared is not None and self.shared.vacuum_state != "docked" - ): + ) and self.connector: try: async with async_timeout.timeout(10): # Fetch and process sensor data from the MQTT connector @@ -83,7 +83,7 @@ async def _async_update_data(self): return self.sensor_data return self.sensor_data except Exception as err: - _LOGGER.error(f"Error fetching sensor data: {err}") + _LOGGER.error(f"Exception raised fetching sensor data: {err}") raise UpdateFailed(f"Error fetching sensor data: {err}") from err else: return self.sensor_data @@ -143,6 +143,8 @@ async def async_update_sensor_data(self, sensor_data): battery_level = await self.connector.get_battery_level() vacuum_state = await self.connector.get_vacuum_status() vacuum_room = self.shared.current_room + if not vacuum_room: + vacuum_room = {"in_room": "Unsupported"} last_run_stats = sensor_data.get("last_run_stats", {}) last_loaded_map = sensor_data.get("last_loaded_map", {}) formatted_data = { diff --git a/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py b/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py index 777cd245..af1fa493 100755 --- a/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py +++ b/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py @@ -155,13 +155,13 @@ async def handle_pkohelrs_maploader_map(self, msg) -> None: self._pkohelrs_maploader_map = await self.async_decode_mqtt_payload(msg) _LOGGER.debug(f"{self._file_name}: Loaded Map {self._pkohelrs_maploader_map}.") - async def handle_pkohelrs_maploader_state(self, msg) -> str: + async def handle_pkohelrs_maploader_state(self, msg) -> None: """Get the pkohelrs state and handle camera restart""" new_state = await self.async_decode_mqtt_payload(msg) _LOGGER.debug(f"{self._file_name}: {self.pkohelrs_state} -> {new_state}") if (self.pkohelrs_state == "loading_map") and (new_state == "idle"): await self.async_fire_event_restart_camera(data=str(msg.payload)) - return new_state + self.pkohelrs_state = new_state async def hypfer_handle_image_data(self, msg) -> None: """ @@ -390,7 +390,7 @@ async def async_message_received(self, msg) -> None: elif self._rcv_topic == f"{self._mqtt_topic}/maploader/map": await self.handle_pkohelrs_maploader_map(msg) elif self._rcv_topic == f"{self._mqtt_topic}/maploader/status": - self.pkohelrs_state = await self.handle_pkohelrs_maploader_state(msg) + await self.handle_pkohelrs_maploader_state(msg) async def async_subscribe_to_topics(self) -> None: """Subscribe to the MQTT topics for Hypfer and ValetudoRe.""" From 6a1fea4c25b8ad5f2d77b55ad7bc5f853d95cb0f Mon Sep 17 00:00:00 2001 From: SCA075 <82227818+sca075@users.noreply.github.com> Date: Wed, 16 Oct 2024 12:35:04 +0200 Subject: [PATCH 8/8] black and format. coordinator.py shedule_update refactor. Signed-off-by: 82227818+sca075@users.noreply.github.com <82227818+sca075@users.noreply.github.com> --- custom_components/mqtt_vacuum_camera/const.py | 2 +- custom_components/mqtt_vacuum_camera/coordinator.py | 10 ++++++---- .../mqtt_vacuum_camera/valetudo/MQTT/connector.py | 4 +--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/custom_components/mqtt_vacuum_camera/const.py b/custom_components/mqtt_vacuum_camera/const.py index e8e5fad9..0810ba0b 100755 --- a/custom_components/mqtt_vacuum_camera/const.py +++ b/custom_components/mqtt_vacuum_camera/const.py @@ -67,7 +67,7 @@ "last_bin_out": 0, "last_bin_full": 0, "last_loaded_map": "NoMap", - "robot_in_room": "Unsupported" + "robot_in_room": "Unsupported", } DEFAULT_PIXEL_SIZE = 5 diff --git a/custom_components/mqtt_vacuum_camera/coordinator.py b/custom_components/mqtt_vacuum_camera/coordinator.py index 0c74168e..6b7776e4 100644 --- a/custom_components/mqtt_vacuum_camera/coordinator.py +++ b/custom_components/mqtt_vacuum_camera/coordinator.py @@ -11,6 +11,7 @@ import async_timeout from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant +from homeassistant.helpers.event import async_call_later from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -60,16 +61,17 @@ def schedule_refresh(self) -> None: """Schedule coordinator refresh after 1 second.""" if self.scheduled_refresh: self.scheduled_refresh.cancel() - self.scheduled_refresh = self.hass.loop.call_later( - 1, lambda: asyncio.create_task(self.async_refresh()) + self.scheduled_refresh = async_call_later( + self.hass, 1, lambda: asyncio.create_task(self.async_refresh()) ) async def _async_update_data(self): """ Fetch data from the MQTT topics for sensors. """ - if (self.sensor_data == SENSOR_NO_DATA) or ( - self.shared is not None and self.shared.vacuum_state != "docked" + if ( + (self.sensor_data == SENSOR_NO_DATA) + or (self.shared is not None and self.shared.vacuum_state != "docked") ) and self.connector: try: async with async_timeout.timeout(10): diff --git a/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py b/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py index af1fa493..57fcd9e3 100755 --- a/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py +++ b/custom_components/mqtt_vacuum_camera/valetudo/MQTT/connector.py @@ -1,7 +1,5 @@ """ Version: v2024.11.0 -- Removed the PNG decode, the json is extracted from map-data instead of map-data-hass. -- Refactoring the subscribe method and decode payload method. """ import asyncio @@ -327,7 +325,7 @@ async def rrm_handle_active_segments(self, msg) -> None: self._shared.rand256_active_zone = rrm_active_segments async def async_fire_event_restart_camera( - self, event_text:str="event_vacuum_start", data:str ="" + self, event_text: str = "event_vacuum_start", data: str = "" ): """Fire Event to reset the camera trims""" self._hass.bus.async_fire(