Skip to content

Commit

Permalink
Merge pull request #581 from PiotrMachowski/dev
Browse files Browse the repository at this point in the history
v2.2.3
  • Loading branch information
PiotrMachowski authored Jan 3, 2025
2 parents 833b4f9 + c4d671b commit c9ae97e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,39 @@ 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):
return match.country, match.user_id, match.device_id, match.model

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",
Expand Down

0 comments on commit c9ae97e

Please sign in to comment.