diff --git a/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py b/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py index b05fa32..ce135e2 100644 --- a/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py +++ b/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py @@ -28,6 +28,7 @@ class ImageHandler: COLOR_ZONES_OUTLINE: (0xAD, 0xD8, 0xFF), COLOR_VIRTUAL_WALLS: (255, 0, 0), COLOR_NEW_DISCOVERED_AREA: (64, 64, 64), + COLOR_MOP_PATH: (255, 255, 255, 0x48), COLOR_CARPETS: (0xA9, 0xF7, 0xA9), COLOR_NO_CARPET_ZONES: (255, 33, 55, 127), COLOR_NO_CARPET_ZONES_OUTLINE: (255, 0, 0), diff --git a/custom_components/xiaomi_cloud_map_extractor/common/xiaomi_cloud_connector.py b/custom_components/xiaomi_cloud_map_extractor/common/xiaomi_cloud_connector.py index a1e1130..f4a41a1 100644 --- a/custom_components/xiaomi_cloud_map_extractor/common/xiaomi_cloud_connector.py +++ b/custom_components/xiaomi_cloud_map_extractor/common/xiaomi_cloud_connector.py @@ -211,7 +211,7 @@ def get_devices_iter(self, country: Optional[str] = None): ) yield from devices - def get_device_details(self, token: str, country: Optional[str] = None): + def get_device_details_from_home(self, token: str, country: Optional[str] = None): devices = self.get_devices_iter(country) matching_token = filter(lambda device: device.token == token, devices) if match := next(matching_token, None): @@ -219,6 +219,31 @@ def get_device_details(self, token: str, country: Optional[str] = None): return None, None, None, None + def get_device_details(self, token: str, + country: Optional[str]) -> Tuple[Optional[str], Optional[str], Optional[str], Optional[str]]: + countries_to_check = CONF_AVAILABLE_COUNTRIES + if country is not None: + countries_to_check = [country] + for c in countries_to_check: + devices = self.get_devices(c) + if devices is None: + continue + found = list(filter(lambda d: str(d["token"]).casefold() == str(token).casefold(), + devices["result"]["list"])) + if len(found) > 0: + user_id = found[0]["uid"] + device_id = found[0]["did"] + model = found[0]["model"] + return c, user_id, device_id, model + return self.get_device_details_from_home(token, country) + + def get_devices(self, country: str) -> Any: + url = self.get_api_url(country) + "/home/device_list" + params = { + "data": '{"getVirtualModel":false,"getHuamiDevices":0}' + } + return self.execute_api_call_encrypted(url, params) + def execute_api_call_encrypted(self, url: str, params: Dict[str, str]) -> Any: headers = { "Accept-Encoding": "identity",