philippelt / netatmo-api-python

Netatmo connect API python client (for Netatmo information, see https://dev.netatmo.com)
GNU General Public License v3.0
193 stars 121 forks source link

'lastData(station=station, exclude=0)' no longer works when iterating through multiple stations #50

Closed baiti closed 1 year ago

baiti commented 1 year ago

until recently I have used code from grafana-netamo like this:

for station in weatherData.stations:
    for module, moduleData in weatherData.lastData(station=station_name, exclude=0).items():

Now after an authentication related update of lnetatmo the code above (taken from sample code shown in grafana-netatmo) no longer works, it throws a TypeError

Traceback (most recent call last): File "./netatmo_influx.py", line 46, in for module, moduleData in weatherData.lastData(station=station, exclude=0).items(): TypeError: lastData() got an unexpected keyword argument 'station' I got it back working by just dropping that station agrument.

Looking at the lnetatmo.py source makes it clear, that parameter station no longer exists. Of course I can jusrt remove that parameter in the for loop above, however, then, when iterating more than one station, I fetch one and the same set of measurements and values for all stations. It must be possible somehow, to reference that lastData by station. Can anybody shed some light into this?

philippelt commented 1 year ago

Thanks for reporting this behavior. You are right, I removed the station parameter when the home was introduced.

My, obviously wrong assumption, was that people having accounts with multiple stations where in fact using one station in each different home. For such case, you have to instantiate WeatherStationData for each home.

In case you have multiple stations in a single home, all stations are still reachable and, as you requested, it is legitimate to be able to collect data for each station.

I made a change to restore the station parameter, as an optional argument to avoid changing library behavior for existing application. Let me know if the change works for you, I don't have access to such a configuration for testing.

I did not publish a release, just download lnetatmo.py from the last commit (eab27662d9fc4757c3ae96b3eac22c24421ae1be) and give it a try.

baiti commented 1 year ago

Very cool! Works, and I am back in business.

However, in fact my two stations are in different homes. Should I consider changing the workflow such that each home is addressed in its own query? How would I address each home?

philippelt commented 1 year ago

Homes are used to group various Netatmo devices so you don't make mistake accessing them.

I have two "homes" (far from each other) and a weather station in each but there are in both cases "external" named sensor for outside temperature. The home avoid confusion here.

The home is mainly designed to group multiple Netatmo devices in a user interface. It is important for cameras for example, because you can swipe between camera views that belongs to the same home in the mobile app for example.

I don't remember enumerating/looping on homes ( it should be possible using WeatherStationData.homes.keys() ), most of the time my utilities are targeting a specific home.

Enjoy