From 375ba63d8b82df77fe3ef27f29bb423c56acaba0 Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Sun, 10 Nov 2024 14:47:01 +0100 Subject: [PATCH 01/14] change Homecoach --- lnetatmo.py | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index 11bfb6d4..e04dee6b 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -932,10 +932,10 @@ class HomeCoach: authData (clientAuth): Authentication information with a working access Token home : Home name or id of the home who's HomeCoach belongs to """ - # FIXME: home parameter not used, unpredictible behavior - def __init__(self, authData, home=None): - # I don't own a HomeCoach thus I am not able to test the HomeCoach support + def __init__(self, authData): + # I don't own a HomeCoach thus I am not able to test the HomeCoach support + # Homecoach does not need or use HomeID parameter # warnings.warn("The HomeCoach code is not tested due to the lack of test environment.\n", RuntimeWarning ) # "As Netatmo is continuously breaking API compatibility, risk that current bindings are wrong is high.\n" \ # "Please report found issues (https://github.com/philippelt/netatmo-api-python/issues)" @@ -949,34 +949,40 @@ def __init__(self, authData, home=None): # homecoach data if not self.rawData : raise NoDevice("No HomeCoach available") - for h in self.rawData: - # FIXME: This loop is nonsense (always end with the last value) - self.HomecoachDevice = h -# print ('Homecoach = ', self.HomecoachDevice) -# print (' ') -# print ('Homecoach_data = ', self.rawData[i]['dashboard_data']) -# print (' ') + def HomecoachDevice(self, id=""): + for device in self.rawData: + if id in device['_id']: + return device + self.HomecoachDevice = device - def Dashboard(self): - D = self.HomecoachDevice['dashboard_data'] - return D + def Dashboard(self, id=""): + #D = self.HomecoachDevice['dashboard_data'] + for device in self.rawData: + if id in device['_id']: + D = device['dashboard_data'] + return D - # FIXME: Exclusion of outdated info is not handled (exclude parameter unused) def lastData(self, hid=None, exclude=0): - if hid is not None: - s = self.HomecoachDevice['dashboard_data']['time_utc'] - _id = self.HomecoachDevice[hid] - return {'When':s}, {'_id':_id} - return {'When': 0 }, {'_id': hid} + for device in self.rawData: + if id == device['_id']: + #s = self.HomecoachDevice['dashboard_data']['time_utc'] + # Define oldest acceptable sensor measure event + limit = (time.time() - exclude) if exclude else 0 + ds = self.HomecoachDevice['dashboard_data'] + if ds.get('time_utc',limit+10) > limit : + _id = s[id] + return {'When':s, '_id':_id} + else: + return {'When': 0, 'id': id} - def checkNotUpdated(self, res, _id, delay=3600): + def checkNotUpdated(self, res, hid, delay=3600): ret = [] - if time.time()-res['When'] > delay : ret.append({_id: 'Device Not Updated'}) + if time.time()-res['When'] > delay : ret.append({hid: 'Device Not Updated'}) return ret if ret else None - def checkUpdated(self, res, _id, delay=3600): + def checkUpdated(self, res, hid, delay=3600): ret = [] - if time.time()-res['When'] < delay : ret.append({_id: 'Device up-to-date'}) + if time.time()-res['When'] < delay : ret.append({hid: 'Device up-to-date'}) return ret if ret else None From 42d4e8e5f011ac561081d54b18f978651fa78bed Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Sun, 10 Nov 2024 14:55:05 +0100 Subject: [PATCH 02/14] change Thermostat --- lnetatmo.py | 84 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index e04dee6b..de03079c 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -341,8 +341,8 @@ def getModuleParam(self, module_id, param): class ThermostatData: """ - List the Thermostat and temperature modules - + List the Relay station and Thermostat modules + Valves are controlled by HomesData and HomeStatus in new API Args: authData (clientAuth): Authentication information with a working access Token home : Home name or id of the home who's thermostat belongs to @@ -375,36 +375,72 @@ def __init__(self, authData, home=None): # Standard the first Relaystation and Thermostat is returned # self.rawData is list all stations - # FIXME : This code is wrong as it will always return the first Relay - # I don't own a thermostat I can't fix this code, help welcome - def Relay_Plug(self, _id=None): +# if no ID is given the Relaystation at index 0 is returned + def Relay_Plug(self, Rid=""): for Relay in self.rawData: - if _id in Relay: - return Relay - else: + if Rid in Relay['_id']: + print ('Relay ', Rid, 'in rawData') + #print (Relay.keys()) #print (Relay['_id']) return Relay +#dict_keys(['_id', 'applications', 'cipher_id', 'command', 'config_version', 'd_amount', 'date_creation', 'dev_has_init', 'device_group', 'firmware', 'firmware_private', 'homekit_nb_pairing', 'last_bilan', 'last_day_extremum', 'last_fw_update', 'last_measure_stored', 'last_setup', 'last_status_store', 'last_sync_asked', 'last_time_boiler_on', 'mg_station_name', 'migration_date', 'module_history', 'netcom_transport', 'new_historic_data', 'place', 'plug_connected_boiler', 'recompute_outdoor_time', 'record_storage', 'rf_amb_status', 'setpoint_order_history', 'skip_module_history_creation', 'subtype', 'type', 'u_amount', 'update_device', 'upgrade_record_ts', 'wifi_status', 'room', 'modules', 'station_name', 'udp_conn', 'last_plug_seen']) + +# if no ID is given the Thermostatmodule at index 0 is returned + def Thermostat_Data(self, tid=""): + for Relay in self.rawData: + for thermostat in Relay['modules']: + if tid in thermostat['_id']: + print ('Thermostat ',tid, 'in Relay', Relay['_id'], Relay['station_name']) + #print (thermostat['_id']) + #print (thermostat.keys()) + return thermostat +#dict_keys(['_id', 'module_name', 'type', 'firmware', 'last_message', 'rf_status', 'battery_vp', 'therm_orientation', 'therm_relay_cmd', 'anticipating', 'battery_percent', 'event_history', 'last_therm_seen', 'setpoint', 'therm_program_list', 'measured']) - # FIXME : Probably wrong again, always returning "first" thermostat ? - def Thermostat_Data(self): - for thermostat in self.Relay_Plug()['modules']: - # - return thermostat - def getThermostat(self, name=None, tid=None): - if self.rawData[0]['station_name'] != name: return None # OLD ['name'] - # FIXME: No thermostat property !! - return self.thermostat[self.defaultThermostatId] + def getThermostat(self, name=None, id=""): + for Relay in self.rawData: + for module in Relay['modules']: + if id == Relay['_id']: + print ('Relay ', id, 'found') + return Relay + elif name == Relay['station_name']: + print ('Relay ', name, 'found') + return Relay + elif id == module['_id']: + print ('Thermostat ', id, 'found in Relay', Relay['_id'], Relay['station_name']) + return module + elif name == module['module_name']: + print ('Thermostat ', name, 'found in Relay', Relay['_id'], Relay['station_name']) + return module + else: + #print ('Device NOT Found') + pass def moduleNamesList(self, name=None, tid=None): - thermostat = self.getThermostat(name=name, tid=tid) - return [m['name'] for m in thermostat['modules']] if thermostat else None + l = [] + for Relay in self.rawData: + if id == Relay['_id'] or name == Relay['station_name']: + RL = [] + for module in Relay['modules']: + RL.append(module['module_name']) + return RL + else: + #print ("Cloud Data") + for module in Relay['modules']: + l.append(module['module_name']) + #This return a list off all connected Thermostat in the cloud. + return l - def getModuleByName(self, name, thermostatId=None): # ERROR 'NoneType' object is not subscriptable - thermostat = self.getThermostat(tid=thermostatId) - for m in thermostat['modules']: - if m['name'] == name: return m - return None + def getModuleByName(self, name, tid=""): + for Relay in self.rawData: + for module in Relay['modules']: + #print (module['module_name'], module['_id']) + if module['module_name'] == name: + return module + elif module['_id'] == tid: + return module + else: + pass class WeatherStationData: From b9692c679dbcd5f588a4aa79a0c4343b5121e338 Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Sun, 10 Nov 2024 16:07:25 +0100 Subject: [PATCH 03/14] Update Homecoach --- lnetatmo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index de03079c..1679c9ec 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -1006,8 +1006,8 @@ def lastData(self, hid=None, exclude=0): limit = (time.time() - exclude) if exclude else 0 ds = self.HomecoachDevice['dashboard_data'] if ds.get('time_utc',limit+10) > limit : - _id = s[id] - return {'When':s, '_id':_id} + _id = ds[id] + return {'When':ds, '_id':_id} else: return {'When': 0, 'id': id} From af6ed09662d3780c704735cde2a0c6744f7d992c Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Sun, 10 Nov 2024 16:58:20 +0100 Subject: [PATCH 04/14] Update HomeData This class is deprecated in the last API from Netatmo Most devices are in HomesData with HomeStatus --- lnetatmo.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index 1679c9ec..f985bee5 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -631,8 +631,11 @@ class HomeData: Args: authData (ClientAuth): Authentication information with a working access Token + home : Home name of the home where's devices are installed """ def __init__(self, authData, home=None): + warnings.warn("The 'HomeData' class is deprecated'", + DeprecationWarning ) self.getAuthToken = authData.accessToken postParams = { "access_token" : self.getAuthToken @@ -647,13 +650,29 @@ def __init__(self, authData, home=None): C = v.get('cameras') P = v.get('persons') S = v.get('smokedetectors') + for d in self.rawData['homes'] : + if home == d['name']: + self.homes = d + else: + pass + # + C = self.homes['cameras'] + P = self.homes['persons'] + S = self.homes['smokedetectors'] + E = None + # events not always in self.homes + if 'events' in self.homes.keys(): E = v.get('events') - S or logger.warning('No smoke detector found') - C or logger.warning('No Cameras found') - P or logger.warning('No Persons found') - E or logger.warning('No events found') - if not (C or P or S or E): - raise NoDevice("No device found in home %s" % k) + if not S: + logger.warning('No smoke detector found') + if not C: + logger.warning('No Cameras found') + if not P: + logger.warning('No Persons found') + if not E: + logger.warning('No events found') + # if not (C or P or S or E): + # raise NoDevice("No device found in home %s" % k) if S or C or P or E: self.default_home = home or list(self.homes.values())[0]['name'] # Split homes data by category @@ -680,6 +699,7 @@ def __init__(self, authData, home=None): c["home_id"] = curHome['id'] for camera,e in self.events.items(): self.lastEvent[camera] = e[sorted(e)[-1]] + #self.default_home has no key homeId use homeName instead! if not self.cameras[self.default_home] : raise NoDevice("No camera available in default home") self.default_camera = list(self.cameras[self.default_home].values())[0] else: From afe6d46377bb2c2e3573e03a768753d358c1fcfa Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:08:23 +0100 Subject: [PATCH 05/14] Update lnetatmo.py some rewrite for successful selftest --- lnetatmo.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index f985bee5..40a197c6 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -131,6 +131,7 @@ 'NSD' : ["smoke sensor", 'Home + Security'], 'NHC' : ["home coach", 'Aircare'], 'NIS' : ["indoor sirene", 'Home + Security'], + 'NDL' : ["Doorlock", 'Home + Security'], 'NLC' : ["Cable Outlet", 'Home+Control'], 'NLE' : ["Ecometer", 'Home+Control'], @@ -643,19 +644,16 @@ def __init__(self, authData, home=None): resp = postRequest("Home data", _GETHOMEDATA_REQ, postParams) self.rawData = resp['body'] # Collect homes - self.homes = { d['id'] : d for d in self.rawData['homes'] } - # FIXME : Doesn't use the home parameter to select the appropriate home ! - for k, v in self.homes.items(): - self.homeid = k - C = v.get('cameras') - P = v.get('persons') - S = v.get('smokedetectors') + self.homes = self.rawData['homes'][0] for d in self.rawData['homes'] : if home == d['name']: self.homes = d else: pass # + #print (self.homes.keys()) + #dict_keys(['id', 'name', 'persons', 'place', 'cameras', 'smokedetectors', 'events']) + self.homeid = self.homes['id'] C = self.homes['cameras'] P = self.homes['persons'] S = self.homes['smokedetectors'] @@ -663,6 +661,7 @@ def __init__(self, authData, home=None): # events not always in self.homes if 'events' in self.homes.keys(): E = v.get('events') + # if not S: logger.warning('No smoke detector found') if not C: @@ -674,7 +673,7 @@ def __init__(self, authData, home=None): # if not (C or P or S or E): # raise NoDevice("No device found in home %s" % k) if S or C or P or E: - self.default_home = home or list(self.homes.values())[0]['name'] + self.default_home = home or self.homes['name'] # Split homes data by category self.persons = {} self.events = {} @@ -1169,6 +1168,9 @@ def getStationMinMaxTH(station=None, module=None, home=None): thermostat = ThermostatData(authorization) Default_relay = thermostat.Relay_Plug() Default_thermostat = thermostat.Thermostat_Data() + thermostat.getThermostat() + print (thermostat.moduleNamesList()) + #print (thermostat.getModuleByName(name)) except NoDevice: logger.warning("No thermostat avaible for testing") From e8863dcf2ece57f395e5f42a89e6531a82ed8203 Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:11:12 +0100 Subject: [PATCH 06/14] Fix typo --- lnetatmo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnetatmo.py b/lnetatmo.py index 40a197c6..78ddac41 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -660,7 +660,7 @@ def __init__(self, authData, home=None): E = None # events not always in self.homes if 'events' in self.homes.keys(): - E = v.get('events') + E = self.homes['events'] # if not S: logger.warning('No smoke detector found') From 1a13c29fd561eae74558672d89cd501d66bf9dae Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:52:56 +0100 Subject: [PATCH 07/14] change HomesData and self-test --- lnetatmo.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lnetatmo.py b/lnetatmo.py index 78ddac41..5e25908c 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -976,6 +976,9 @@ def __init__(self, authData, home=None): #print (h.keys()) if home in (h["name"], h["id"]): self.Homes_Data = h + else: + self.Homes_Data = self.rawData[0] + self.homeid = self.Homes_Data['id'] if not self.Homes_Data : raise NoDevice("No Devices available") @@ -1160,7 +1163,6 @@ def getStationMinMaxTH(station=None, module=None, home=None): try: homes = HomeData(authorization) - homeid = homes.homeid except NoDevice : logger.warning("No home available for testing") @@ -1175,11 +1177,24 @@ def getStationMinMaxTH(station=None, module=None, home=None): logger.warning("No thermostat avaible for testing") try: + print (' ') + logger.info("Homes Data") + #homesdata = HomesData(authorization, homeid) homesdata = HomesData(authorization) + homeid = homesdata.homeid except NoDevice: logger.warning("No HomesData avaible for testing") try: + print (' ') + logger.info("Home Status") + HomeStatus(authorization, homeid) + except NoDevice: + logger.warning("No Home available for testing") + + try: + print (' ') + logger.info("HomeCoach") Homecoach = HomeCoach(authorization) except NoDevice: logger.warning("No HomeCoach avaible for testing") From 9c4f9dafeec750790833ab02047f7b135ff305f6 Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:15:49 +0100 Subject: [PATCH 08/14] correcting comment --- lnetatmo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index 5e25908c..6d8642de 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -121,8 +121,8 @@ 'NAModule2' : ["wind unit", 'Weather'], 'NAModule3' : ["rain unit", 'Weather'], 'NAModule4' : ["indoor unit", 'Weather'], - 'NAPlug' : ["thermostat relais station", 'Energy'], # A smart thermostat exist of a thermostat and a Relais module - # The relais module is also the bridge for thermostat and Valves + 'NAPlug' : ["thermostat relais station", 'Energy'], # A smart thermostat exist of a thermostat module and a Relay device + # The relay device is also the bridge for thermostat and Valves 'NATherm1' : ["thermostat", 'Energy'], 'NCO' : ["co2 sensor", 'Home + Security'], # The same API as smoke sensor 'NDB' : ["doorbell", 'Home + Security'], From 49c889daa785de4cf72e4b281eef1732e8322210 Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:46:26 +0100 Subject: [PATCH 09/14] Update homecoach lastdata --- lnetatmo.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index 6d8642de..52c5a194 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -1011,7 +1011,7 @@ def HomecoachDevice(self, id=""): for device in self.rawData: if id in device['_id']: return device - self.HomecoachDevice = device + return None def Dashboard(self, id=""): #D = self.HomecoachDevice['dashboard_data'] @@ -1023,15 +1023,17 @@ def Dashboard(self, id=""): def lastData(self, hid=None, exclude=0): for device in self.rawData: if id == device['_id']: - #s = self.HomecoachDevice['dashboard_data']['time_utc'] + # LastData in HomeCoach + #s = self.HomecoachDevice['dashboard_data']['time_utc'] # Define oldest acceptable sensor measure event limit = (time.time() - exclude) if exclude else 0 - ds = self.HomecoachDevice['dashboard_data'] - if ds.get('time_utc',limit+10) > limit : - _id = ds[id] - return {'When':ds, '_id':_id} + ds = device['dashboard_data']['time_utc'] + if device.get('time_utc',limit+10) > limit : + return {'When': ds, '_id': id} + else: + return {'When': 0, 'id': hid} else: - return {'When': 0, 'id': id} + pass def checkNotUpdated(self, res, hid, delay=3600): ret = [] From 18271cfdfeb7062eee629fdb5e51e02398156d49 Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Mon, 11 Nov 2024 19:02:43 +0100 Subject: [PATCH 10/14] Update lnetatmo.py --- lnetatmo.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index 52c5a194..0d18ce54 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -1009,27 +1009,27 @@ def __init__(self, authData): def HomecoachDevice(self, id=""): for device in self.rawData: - if id in device['_id']: + if id == device['_id']: return device return None def Dashboard(self, id=""): #D = self.HomecoachDevice['dashboard_data'] for device in self.rawData: - if id in device['_id']: + if id == device['_id']: D = device['dashboard_data'] return D def lastData(self, hid=None, exclude=0): for device in self.rawData: - if id == device['_id']: + if hid == device['_id']: # LastData in HomeCoach #s = self.HomecoachDevice['dashboard_data']['time_utc'] # Define oldest acceptable sensor measure event limit = (time.time() - exclude) if exclude else 0 ds = device['dashboard_data']['time_utc'] if device.get('time_utc',limit+10) > limit : - return {'When': ds, '_id': id} + return {'When': ds, '_id': hid} else: return {'When': 0, 'id': hid} else: From 16c2d20d108bcc27d8712a95f748b8f904fb94fa Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:29:22 +0100 Subject: [PATCH 11/14] change return lastdata in homecoach --- lnetatmo.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index 0d18ce54..971c6976 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -1028,10 +1028,7 @@ def lastData(self, hid=None, exclude=0): # Define oldest acceptable sensor measure event limit = (time.time() - exclude) if exclude else 0 ds = device['dashboard_data']['time_utc'] - if device.get('time_utc',limit+10) > limit : - return {'When': ds, '_id': hid} - else: - return {'When': 0, 'id': hid} + return { '_id': hid, 'When': ds if device.get('time_utc',limit+10) > limit else 0} else: pass From 6073c26ab1e6477b840f63a1538c0f3edb6ca9bb Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Mon, 18 Nov 2024 21:16:57 +0100 Subject: [PATCH 12/14] correcting use off access Token --- lnetatmo.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index 971c6976..9c07d7f0 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -3,7 +3,7 @@ # Multiple contributors : see https://github.com/philippelt/netatmo-api-python # License : GPL V3 """ -This API provides access to the Netatmo weather station or/and the Welcome camera +This API provides access to the Netatmo weather station or/and other installed devices This package can be used with Python2 or Python3 applications and do not require anything else than standard libraries @@ -210,12 +210,14 @@ class ClientAuth: def __init__(self, clientId=None, clientSecret=None, + accessToken=None, refreshToken=None, credentialFile=None): # replace values with content of env variables if defined clientId = getenv("CLIENT_ID", clientId) clientSecret = getenv("CLIENT_SECRET", clientSecret) + accessToken = getenv("ACCESS_TOKEN", accessToken) refreshToken = getenv("REFRESH_TOKEN", refreshToken) # Look for credentials in file if not already provided @@ -232,9 +234,9 @@ def __init__(self, clientId=None, self._clientId = clientId or cred["CLIENT_ID"] self._clientSecret = clientSecret or cred["CLIENT_SECRET"] + self._accessToken = accessToken or cred["ACCESS_TOKEN"] # Will be refreshed before any use self.refreshToken = refreshToken or cred["REFRESH_TOKEN"] self.expiration = 0 # Force refresh token - self._accessToken = None # Will be refreshed before any use @property def accessToken(self): @@ -253,6 +255,7 @@ def renew_token(self): self.refreshToken = resp['refresh_token'] cred = {"CLIENT_ID":self._clientId, "CLIENT_SECRET":self._clientSecret, + "ACCESS_TOKEN" : self._accessToken, "REFRESH_TOKEN":self.refreshToken } if self._credentialFile: with open(self._credentialFile, "w", encoding="utf-8") as f: @@ -1007,16 +1010,16 @@ def __init__(self, authData): # homecoach data if not self.rawData : raise NoDevice("No HomeCoach available") - def HomecoachDevice(self, id=""): + def HomecoachDevice(self, hid=""): for device in self.rawData: - if id == device['_id']: + if hid == device['_id']: return device return None - def Dashboard(self, id=""): + def Dashboard(self, hid=""): #D = self.HomecoachDevice['dashboard_data'] for device in self.rawData: - if id == device['_id']: + if hid == device['_id']: D = device['dashboard_data'] return D From 11e16a73261da95bad477a0ba9c60e811bfddcde Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Tue, 19 Nov 2024 06:49:21 +0100 Subject: [PATCH 13/14] Update .netatmo.credentials --- .netatmo.credentials | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.netatmo.credentials b/.netatmo.credentials index 2127562c..37b7e913 100644 --- a/.netatmo.credentials +++ b/.netatmo.credentials @@ -1,6 +1,10 @@ { + "USER_MAIL" : "", + "USER_PASSWORD" : "", "CLIENT_ID" : "", "CLIENT_SECRET" : "", - "REFRESH_TOKEN" : "" + "ACCESS_TOKEN" : "", + "REFRESH_TOKEN" : "", + "SCOPE" : "" } From 009231b8456756c09cf5f3783ed2b8ecd95aa000 Mon Sep 17 00:00:00 2001 From: JurgenLB <77586573+JurgenLB@users.noreply.github.com> Date: Fri, 22 Nov 2024 21:57:23 +0100 Subject: [PATCH 14/14] undo changes in authentication --- lnetatmo.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lnetatmo.py b/lnetatmo.py index 9c07d7f0..d4b8e2a8 100644 --- a/lnetatmo.py +++ b/lnetatmo.py @@ -210,14 +210,12 @@ class ClientAuth: def __init__(self, clientId=None, clientSecret=None, - accessToken=None, refreshToken=None, credentialFile=None): # replace values with content of env variables if defined clientId = getenv("CLIENT_ID", clientId) clientSecret = getenv("CLIENT_SECRET", clientSecret) - accessToken = getenv("ACCESS_TOKEN", accessToken) refreshToken = getenv("REFRESH_TOKEN", refreshToken) # Look for credentials in file if not already provided @@ -234,7 +232,7 @@ def __init__(self, clientId=None, self._clientId = clientId or cred["CLIENT_ID"] self._clientSecret = clientSecret or cred["CLIENT_SECRET"] - self._accessToken = accessToken or cred["ACCESS_TOKEN"] # Will be refreshed before any use + self._accessToken = None #accessToken or cred["ACCESS_TOKEN"] # Will be refreshed before any use self.refreshToken = refreshToken or cred["REFRESH_TOKEN"] self.expiration = 0 # Force refresh token @@ -255,7 +253,6 @@ def renew_token(self): self.refreshToken = resp['refresh_token'] cred = {"CLIENT_ID":self._clientId, "CLIENT_SECRET":self._clientSecret, - "ACCESS_TOKEN" : self._accessToken, "REFRESH_TOKEN":self.refreshToken } if self._credentialFile: with open(self._credentialFile, "w", encoding="utf-8") as f: