shenxn / libdyson

Python library for dyson devices
Apache License 2.0
62 stars 41 forks source link

TypeError when getting device info #2

Closed shenxn closed 3 years ago

shenxn commented 3 years ago

This is originally reported in https://github.com/shenxn/ha-dyson/issues/1#issuecomment-792259004 by @lolongan.

Here is the log

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 248, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/config/custom_components/dyson_cloud/__init__.py", line 43, in async_setup_entry
    devices = await hass.async_add_executor_job(account.devices)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/libdyson/cloud/account.py", line 173, in devices
    devices.append(DysonDeviceInfo.from_raw(raw))
  File "/usr/local/lib/python3.8/site-packages/libdyson/cloud/device_info.py", line 31, in from_raw
    decrypt_password(raw["LocalCredentials"]),
  File "/usr/local/lib/python3.8/site-packages/libdyson/cloud/utils.py", line 29, in decrypt_password
    encrypted = base64.b64decode(encrypted_password)
  File "/usr/local/lib/python3.8/base64.py", line 80, in b64decode
    s = _bytes_from_decode_data(s)
  File "/usr/local/lib/python3.8/base64.py", line 45, in _bytes_from_decode_data
    raise TypeError("argument should be a bytes-like object or ASCII "
TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType'
shenxn commented 3 years ago

@lolongan This problem need further investigation. Maybe I will write a script for you to run and give me more info.

lolongan commented 3 years ago

@lolongan This problem need further investigation. Maybe I will write a script for you to run and give me more info.

With pleasure, when you wish.

shenxn commented 3 years ago

@lolongan I've made a new branch https://github.com/shenxn/libdyson/tree/debug that prints raw data from HTTP request. Download or clone the branch, run python3 get_devices.py. You may need to install dependencies by running pip3 install -r requirements.txt. Then you should see several message starting with Device raw info:. Paste those lines here. Feel free to change LocalCredentials value for privacy.

lolongan commented 3 years ago

@lolongan I've made a new branch https://github.com/shenxn/libdyson/tree/debug that prints raw data from HTTP request. Download or clone the branch, run python3 get_devices.py. You may need to install dependencies by running pip3 install -r requirements.txt. Then you should see several message starting with Device raw info:. Paste those lines here. Feel free to change LocalCredentials value for privacy.

@shenxn Here you are. Note that Device #1 is a Pure Cool + Hot and Device #2 is a Lightcycle Lamp. I suspect that this is this device which creates the issue because it has no 'LocalCredentials'.

Device raw info:  {'Serial': 'A1B-EU-NJA2043A', 'Name': 'Salon', 'Version': 'ECG2PF.30.06.003.0002', 'LocalCredentials': 'XXXX----XXXX', 'AutoUpdate': True, 'NewVersionAvailable': True, 'ProductType': '527', 'ConnectionType': 'wss'}
Device raw info:  {'Serial': 'YS4-EU-MCA0660A', 'Name': 'Bureau', 'Version': '0552PF.00.05.017.0002', 'LocalCredentials': None, 'AutoUpdate': True, 'NewVersionAvailable': False, 'ProductType': '552', 'ConnectionType': 'wss'}
Traceback (most recent call last):
  File "/Users/comedie/Downloads/libdyson-debug/get_devices.py", line 30, in <module>
    devices = account.devices()
  File "/Users/comedie/Downloads/libdyson-debug/libdyson/cloud/account.py", line 174, in devices
    devices.append(DysonDeviceInfo.from_raw(raw))
  File "/Users/comedie/Downloads/libdyson-debug/libdyson/cloud/device_info.py", line 31, in from_raw
    decrypt_password(raw["LocalCredentials"]),
  File "/Users/comedie/Downloads/libdyson-debug/libdyson/cloud/utils.py", line 29, in decrypt_password
    encrypted = base64.b64decode(encrypted_password)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/base64.py", line 80, in b64decode
    s = _bytes_from_decode_data(s)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/base64.py", line 45, in _bytes_from_decode_data
    raise TypeError("argument should be a bytes-like object or ASCII "
TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType'
shenxn commented 3 years ago

Yes. I'll fix that soon. Thanks a lot.

shenxn commented 3 years ago

Fixed and released in version 0.7.0 of libdyson. Will be included in ha-dyson-cloud in the next major release.