rene-d / netatmo

Python3 API for the Netatmo Weather Station
The Unlicense
36 stars 18 forks source link

Get KeyError: 'last_upgrade' when running netatmo dump #5

Closed jestern666 closed 4 years ago

jestern666 commented 4 years ago

Hi!

I get the following error when attempting to run 'netatmo dump':

jester@gandalf:~$ netatmo dump station Gruvfogden date_setup : 1591265084 - 2020-06-04 12:04:44 last_setup : 1591265084 - 2020-06-04 12:04:44 Traceback (most recent call last): File "/usr/local/bin/netatmo", line 10, in sys.exit(main()) File "/usr/local/lib/python3.6/dist-packages/netatmo/netatmo.py", line 890, in main args.func(args) File "/usr/local/lib/python3.6/dist-packages/netatmo/netatmo.py", line 689, in dump % ("last_upgrade", station["last_upgrade"], fmtdate(station["last_upgrade"])) KeyError: 'last_upgrade'

All other commands work fine; fetch fetches files for the Indoor and Outdoor module I have and list lists all my modules.

Could the issue be that I have more modules than what this was intended for? I have an extra indoor module and also the wind gauge.

Would appreciate some assistance.

Thanks!

rene-d commented 4 years ago

However, I can't reproduce myself this issue: the last_upgrade field is always included in the responses, for me. I have an extra module too. Probably in some case this field is omitted, when no upgrade has been done. You can comment the offending line, and I will secure this routine soon.

Thanks for interest :)

rene-d commented 4 years ago

fixed in 1.0.2 pip3 install -U netatmo

jestern666 commented 4 years ago

Thank you!

I turned out it's the Anemometer which is the problem, because it still gives me issues even after upgrade, but at least the dump doesn't fail so early.

I've tried removing it and then everything works fine.

It's even giving me issues if I try API requests directly via the netatmo api-interface they provide over the web. So, my guess is something's broken there.

But thanks so much for your effort!

rene-d commented 4 years ago

Well, I don't have the anenometer, so it's difficult for me to test :)

You can try netatmo -vv dump to print the raw data returned by the netatmo api and - maybe - understand what goes wrong.

jestern666 commented 4 years ago

I got this far now:

I can actually have the anemometer active and get readings from it using 'netatmo dump', but it fails when it's going to print the summarized history at the bottom of the output. But, the readings are printed, and hence I can use them as I wanted to, so almost all is good. I never like requests ending in error, but in this case I get all I want anyway. :D

This is the error message:

module Windfinder - Wind Sensor _id : data_type : ['Wind'] last_setup : 1592686893 - 2020-06-20 23:01:33 firmware : 25 rf_status : 74 (90=low, 60=highest) battery_percent : 100 % last_message : 1592729674 - 2020-06-20 23:01:33 last_seen : 1592729674 - 2020-06-20 23:01:33 GustAngle > 74 GustStrength > 2 WindAngle > -1 WindStrength > 0 date_max_wind_str > 1592701821 - 2020-06-21 03:10:21 max_wind_angle > 0 max_wind_str > 5 time_utc > 1592729071 - 2020-06-21 10:44:31 {'_id': '', 'battery_percent': 100, 'battery_vp': 6117, 'dashboard_data': {'GustAngle': 74, 'GustStrength': 2, 'WindAngle': -1, 'WindStrength': 0, 'date_max_wind_str': 1592701821, 'max_wind_angle': 0, 'max_wind_str': 5, 'time_utc': 1592729071}, 'data_type': ['Wind'], 'firmware': 25, 'last_message': 1592729674, 'last_seen': 1592729674, 'last_setup': 1592686893, 'module_name': 'Windfinder', 'reachable': True, 'rf_status': 74, 'type': 'NAModule2'} Traceback (most recent call last): File "/usr/local/bin/netatmo", line 8, in sys.exit(main()) File "/usr/local/lib/python3.6/dist-packages/netatmo/netatmo.py", line 896, in main args.func(args) File "/usr/local/lib/python3.6/dist-packages/netatmo/netatmo.py", line 718, in dump dump1(mod, True) # dumps an attached module File "/usr/local/lib/python3.6/dist-packages/netatmo/netatmo.py", line 664, in dump1 print("%20s = %s" % (sensor, values["dashboard_data"][sensor])) KeyError: 'Wind'

rene-d commented 4 years ago

Well, it's hard for me to debug without the anemometer. I have added a the test for the key at line 664. But not sure it's enough :/