jinnatar / python-cozify

Unofficial Cozify Python bindings and helpers
MIT License
16 stars 4 forks source link

Some calls are confusing when unauthenticated #16

Open jinnatar opened 3 years ago

jinnatar commented 3 years ago

If there is no valid cloud state saved:

%> util/devicelist.py     
WARNING:absl:Cloud attribute remotetoken not found in state.
Traceback (most recent call last):
  File "util/devicelist.py", line 21, in <module>
    main()
  File "util/devicelist.py", line 11, in main
    devs = hub.devices()
  File "/home/artanicus/python-cozify.git/cozify/hub.py", line 40, in devices
    _fill_kwargs(kwargs)
  File "/home/artanicus/python-cozify.git/cozify/hub.py", line 542, in _fill_kwargs
    kwargs['cloud_token'] = cloud.token()
  File "/home/artanicus/python-cozify.git/cozify/cloud.py", line 346, in token
    return _getAttr('remotetoken')
  File "/home/artanicus/python-cozify.git/cozify/cloud.py", line 304, in _getAttr
    raise AttributeError
AttributeError

Instead, it should be detected that auth hasn't been done successfully and error on that, not an internal consistency AttributeError.

jinnatar commented 2 years ago

This is a bit better today but still not great:

%> util/devicelist.py 
CRITICAL:absl:Default hub not known, you should run cozify.authenticate()
Traceback (most recent call last):
  File "util/devicelist.py", line 21, in <module>
    main()
  File "util/devicelist.py", line 11, in main
    devs = hub.devices()
  File "/home/artanicus/.local/lib/python3.8/site-packages/cozify/hub.py", line 37, in devices
    _fill_kwargs(kwargs)
  File "/home/artanicus/.local/lib/python3.8/site-packages/cozify/hub.py", line 546, in _fill_kwargs
    kwargs['hub_id'] = _get_id(**kwargs)
  File "/home/artanicus/.local/lib/python3.8/site-packages/cozify/hub.py", line 535, in _get_id
    return default()
  File "/home/artanicus/.local/lib/python3.8/site-packages/cozify/hub.py", line 456, in default
    raise AttributeError
AttributeError