Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Shutgun committed May 7, 2023
1 parent f5b7297 commit 2ba7e7b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions devolo_home_control_api/devices/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ def __init__(self, gateway_id: str, mydevolo_instance: Mydevolo) -> None:
self.local_user = self._mydevolo.uuid()
self.local_passkey = details["localPasskey"]
self.external_access = details.get("externalAccess")
self.timezone = tz.gettz(details["location"].get("timezone") or self._mydevolo.get_timezone()) or timezone.utc
self.firmware_version = details.get("firmwareVersion")

if details["location"]:
self.timezone = tz.gettz(details["location"]["timezone"]) or timezone.utc
else:
self.timezone = tz.gettz(self._mydevolo.get_timezone()) or timezone.utc

try:
self.full_url: Optional[str] = self._mydevolo.get_full_url(self.id)
except GatewayOfflineError:
Expand Down
3 changes: 1 addition & 2 deletions devolo_home_control_api/mydevolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def get_gateway(self, gateway_id: str) -> Dict[str, Any]:
except WrongUrlError:
self._logger.error("Could not get full URL. Wrong gateway ID used?")
raise
if details["location"]:
details["location"] = self._call(details["location"])
details["location"] = self._call(details["location"]) if details["location"] else {}
return details

def get_full_url(self, gateway_id: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion tests/snapshots/test_mydevolo.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
'href': 'string',
}),
'localPasskey': '6b96ad097aa389209f1ceeaed6fe7029',
'location': None,
'location': dict({
}),
'name': 'DVT Lab 1409301750000598',
'partner': 'string',
'role': 'user',
Expand Down

0 comments on commit 2ba7e7b

Please sign in to comment.