jinnatar / python-cozify

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

uncaught state inconsistency - KeyError: 'remotetoken' #10

Closed jinnatar closed 6 years ago

jinnatar commented 7 years ago
%> sudo -Hu srv /srv/ephemeral/cozify-temp.git/cozify-single-sample.py
Traceback (most recent call last):
  File "/srv/ephemeral/cozify-temp.git/cozify-single-sample.py", line 20, in <module>
    main()
  File "/srv/ephemeral/cozify-temp.git/cozify-single-sample.py", line 9, in main
    data = hub.getDevices()
  File "/usr/local/lib/python3.5/dist-packages/cozify/hub.py", line 39, in getDevices
    if cloud._needHubToken():
  File "/usr/local/lib/python3.5/dist-packages/cozify/cloud.py", line 219, in _needHubToken
    ping = hub.ping()
  File "/usr/local/lib/python3.5/dist-packages/cozify/hub.py", line 116, in ping
    cloud_token = c.state['Cloud']['remotetoken']
  File "/usr/lib/python3.5/configparser.py", line 1230, in __getitem__
    raise KeyError(key)
KeyError: 'remotetoken'

On the previous run I entered an incorrect OTP, on the subsequent one we're unable to gracefully reset.

State at time of error, originally generated by v0.2.4:

[Cloud]                                                                                                                                                        

[Hubs]                                                                                                                                                         
default = Hub                                                                                                                                            

[Hubs.Hub]                                                                                                                                               
hubtoken = XXXX                                                                                               
host = XXXX                                                                                                                                           
hubid = XXXX

Highly possible this is due to the hub state storage scheme change from name to uuid. Removing state and starting over recovers from this situation.

jinnatar commented 6 years ago

There's now helpers in between that should at least fail more gracefully.