Skip to content

Commit

Permalink
Update api detection to assume the much more common version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
iothacker42 authored Oct 13, 2024
1 parent 506d5c3 commit 0b4f92a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ttls/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,21 @@ async def get_api_version(self) -> int:

async def detect_api_version(self) -> int:
try:
info = await self._info()
return int(info["api"]["min_version"].split(".")[0])
except (ClientResponseError, ServerDisconnectedError) as e:
_LOGGER.debug(e)
self._api_version = 1
_ = await self.get_details()
return 1
except (ClientResponseError, TwinklyError):
pass

try:
self._api_version = 2
_ = await self.get_details()
return 2
except (ClientResponseError, TwinklyError):
pass

self._api_version = None
return None

async def _post(self, endpoint: str, **kwargs) -> Any:
await self.get_api_version()
Expand Down

0 comments on commit 0b4f92a

Please sign in to comment.