Skip to content

Commit

Permalink
Improve map validation (#73)
Browse files Browse the repository at this point in the history
* Improve map validation

* Fix one comment

* Fix service_version condition

* Edit persistent map schema
  • Loading branch information
Santobert authored Jun 24, 2021
1 parent 2d7c6b4 commit 12fe4d7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions pybotvac/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
"delocalized": Any(bool, None),
# Everything below this line is not documented, but still present
"generated_at": Any(str, None),
"persistent_map_id": Any(str, None),
"cleaned_with_persistent_map_id": Any(str, None),
"persistent_map_id": Any(int, str, None),
"cleaned_with_persistent_map_id": Any(int, str, None),
"valid_as_persistent_map": Any(bool, None),
"navigation_mode": Any(int, None),
"navigation_mode": Any(int, str, None),
},
extra=ALLOW_EXTRA,
)
Expand All @@ -84,7 +84,7 @@
)
PERSISTENT_MAP_SCHEMA = Schema(
{
Required("id"): str,
Required("id"): Any(int, str),
Required("name"): str,
Required("url"): Url,
"raw_floor_map_url": Any(Url, None),
Expand Down Expand Up @@ -145,12 +145,13 @@ def refresh_maps(self):
for robot in self.robots:
url = f"users/me/robots/{robot.serial}/maps"
resp2 = self._session.get(url)
resp2_json = resp2.json()
try:
MAPS_SCHEMA(resp2.json())
self._maps.update({robot.serial: resp2.json()})
MAPS_SCHEMA(resp2_json)
self._maps.update({robot.serial: resp2_json})
except MultipleInvalid as ex:
_LOGGER.warning(
"Invalid response from %s: %s. Got: %s", url, ex, resp2.json()
"Invalid response from %s: %s. Got: %s", url, ex, resp2_json
)

def refresh_robots(self):
Expand Down
2 changes: 1 addition & 1 deletion pybotvac/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def start_cleaning(
"cmd": "startCleaning",
"params": {"category": category, "mode": mode, "modifier": 1},
}
elif self.service_version == "basic-3" or "basic-4":
elif self.service_version in ["basic-3", "basic-4"]:
json = {
"reqId": "1",
"cmd": "startCleaning",
Expand Down
2 changes: 1 addition & 1 deletion pybotvac/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def urljoin(self, path):
def generate_headers(
self, custom_headers: Optional[Dict[str, str]] = None
) -> Dict[str, str]:
""""Merge self.headers with custom headers id necessary."""
"""Merge self.headers with custom headers id necessary."""
if not custom_headers:
return self.headers

Expand Down

0 comments on commit 12fe4d7

Please sign in to comment.