philippelt / netatmo-api-python

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

Error after updating to 2.0.0 #44

Closed genfersee closed 3 years ago

genfersee commented 3 years ago

Hello! I have an issue after updating to 2.0.0.

I updated my code with the following, because I have 2 homes linked to my Netatmo account, and 1 station in each home :

    devList = lnetatmo.WeatherStationData(authorization, home='Home A', station=None)
    externalTemperature = round(devList.lastData('Home A')['Exterieur']['Temperature'],1)
    externalHumidity = devList.lastData('Home A')['Home A']['Humidity']
    internalPressure = round(devList.lastData('Homa A')['Appart']['Pressure'],1)
    expirationdelay=1800
    someLost = devList.checkNotUpdated(station='Home A',delay=expirationdelay)
    if someLost and 'Exterieur' in someLost:
        currentTemperature = "--"
        currentHumidity = "--"
        currentPressure = "--"
    else:
        currentTemperature = str(externalTemperature)
        currentHumidity = str(externalHumidity)
        currentPressure = str(internalPressure)
    return (currentTemperature,currentHumidity,currentPressure)

Then, it gives me the following result:

Traceback (most recent call last): File "netamo.py", line 52, in main() File "netamo.py", line 46, in main currentTemperature,currentHumidity,currentPressure = getCurrentWeatherData() File "netamo.py", line 26, in getCurrentWeatherData externalTemperature = round(devList.lastData('Home A')['Exterieur']['Temperature'],1) File "/home/pi/.local/lib/python2.7/site-packages/lnetatmo.py", line 374, in lastData limit = (time.time() - exclude) if exclude else 0 TypeError: unsupported operand type(s) for -: 'float' and 'str'

Did I miss something? Thanks for your help!

genfersee commented 3 years ago

I finally reworked my code, now working!

genfersee commented 3 years ago

The issue I see now is that the weather data I get from the home set in lnetatmo.WeatherStationData is in fact the weather data from my other home set in my account!

authorization = lnetatmo.ClientAuth(clientId = "xxx", clientSecret = "xxx", username = "xxx", password = "xxx") weatherData = lnetatmo.WeatherStationData(authorization,unicode('Home A','utf-8')) theWeatherData = weatherData.lastData() externalTemperature = round(theWeatherData[unicode('Extérieur','utf-8')]['Temperature'],1)

gives me the external temperature of Home B...

philippelt commented 3 years ago

Thanks for reporting this issue. There was an error in default station selection for multi-home setup.

I just published the fix, if your confirm that the bug is fixed, please close the issue...

genfersee commented 3 years ago

Many thanks, I will test the fix and tell you!

I am also trying to make the checkNotUpdated to work.

for m in weatherData.checkNotUpdated(1800): print("Warning, sensor %s information is obsolete" % m) if moduleByName(m) == None : print("The station is lost")

Since I only have 1 module, I simplified with: if weatherData.checkNotUpdated(1800) == None print("Module is lost")

But I always get None, even if some fresh data were published... What am I doing wrong?

Thanks in advance!

philippelt commented 3 years ago

The response is the list of "not updated modules". If your data is fresh, it is the expected response to have "none" as a response. If one of your module was out of power for example, the corresponding data would not be fresh and it's name would be returned...

By the way, there was an obsolete station_name parameter that I am going to clean

genfersee commented 3 years ago

Many thanks!! And I have a last question:

Calling this is working: weatherData = lnetatmo.WeatherStationData(authorization,unicode('Home A','utf-8'))

But if I add the station name like this: weatherData = lnetatmo.WeatherStationData(authorization,unicode('Home A','utf-8'),unicode('Appart','utf-8')) It says:

Traceback (most recent call last): File "netamo.py", line 51, in main() File "netamo.py", line 48, in main currentTemperature,currentHumidity,currentPressure = getCurrentWeatherData() File "netamo.py", line 23, in getCurrentWeatherData weatherData = lnetatmo.WeatherStationData(authorization,unicode('Épesses','utf-8'),unicode('Appart','utf-8')) File "/home/pi/.local/lib/python2.7/site-packages/lnetatmo.py", line 323, in init if station and station not in self.stations: raise NoDevice("No station with name %s" % station) lnetatmo.NoDevice: No station with name Appart

Whereas my station main module is indeed named "Appart". Station name is main module name correct?

genfersee commented 3 years ago

How can I try your fix? I tried to enforce the resintall of 2.0.0 but the latest commits are not included. Should I wait for release 2.1.0?

genfersee commented 3 years ago

Hi @philippelt , I applied your commits yesterday and it works: I now get the weather data from Home A instead of Home B. Many thanks!