Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion custom_components/xiaomi_miot/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,26 @@ def host(self):

@property
def token(self):
return self.data.get(CONF_TOKEN) or self.miio_info.token or ''
primary_token = self.data.get(CONF_TOKEN) or ''
# For Yi cameras and similar devices, the top-level token may not be valid hex
# Check if token is valid hexadecimal, otherwise try extra.token
if primary_token:
try:
bytes.fromhex(primary_token)
return primary_token
except ValueError:
# Primary token is not valid hex, try extra.token
pass

extra_token = self.data.get('extra', {}).get('token', '')
if extra_token:
try:
bytes.fromhex(extra_token)
return extra_token
except ValueError:
# Extra token is also not valid hex, fall through to miio_info.token
pass
return self.miio_info.token

@cached_property
def pid(self):
Expand Down
Loading