Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions lnetatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
'BNTR' : ["Bticino module towel rail", 'Home+Control'],
'BNXM' : ["Bticino X meter", 'Home+Control'],

'NACamera' : ["indoor camera", 'Home + Security'],
'NACamera' : ["indoor camera Welcome", 'Home + Security'],
'NACamDoorTag' : ["door tag", 'Home + Security'],
'NAMain' : ["weather station", 'Weather'],
'NAModule1' : ["outdoor unit", 'Weather'],
Expand All @@ -138,6 +138,7 @@
'NHC' : ["home coach", 'Aircare'],
'NIS' : ["indoor sirene", 'Home + Security'],
'NDL' : ["Doorlock", 'Home + Security'],
'NPC' : ["indoor camera Advance", 'Home + Security'],

'NLAO' : ["Magellan Green power remote control on-off", 'Home+Control'],
'NLAS' : ["Magellan Green Power Remote control scenarios", 'Home+Control'],
Expand Down Expand Up @@ -276,6 +277,7 @@ def renew_token(self):
"client_secret" : self._clientSecret
}
resp = postRequest("authentication", _AUTH_REQ, postParams)

if self.refreshToken != resp['refresh_token']:
self.refreshToken = resp['refresh_token']
cred = {"CLIENT_ID":self._clientId,
Expand All @@ -297,11 +299,16 @@ class User:
"""
warnings.warn("The 'User' class is no longer maintained by Netatmo",
DeprecationWarning )

def __init__(self, authData):
#
warnings.warn("The 'User' class code is deprecated and no longer maintained by Netatmo.\n" ,
RuntimeWarning )
postParams = {
"access_token" : authData.accessToken
}
resp = postRequest("Weather station", _GETSTATIONDATA_REQ, postParams)
resp = postRequest("Station User", _GETSTATIONDATA_REQ, postParams)

self.rawData = resp['body']
self.devList = self.rawData['devices']
self.ownerMail = self.rawData['user']['mail']
Expand Down Expand Up @@ -330,6 +337,7 @@ def __init__(self, authData, home_id):
"home_id": home_id
}
resp = postRequest("home_status", _HOME_STATUS, postParams)

self.resp = resp
self.rawData = resp['body']['home']
if not self.rawData : raise NoHome("No home %s found" % home_id)
Expand Down Expand Up @@ -388,6 +396,7 @@ def __init__(self, authData, home=None):
"access_token" : self.getAuthToken
}
resp = postRequest("Thermostat", _GETTHERMOSTATDATA_REQ, postParams)

self.rawData = resp['body']['devices']
if not self.rawData : raise NoDevice("No thermostat available")
#
Expand Down Expand Up @@ -484,6 +493,7 @@ def __init__(self, authData, home=None, station=None):
"access_token" : self.getAuthToken
}
resp = postRequest("Weather station", _GETSTATIONDATA_REQ, postParams)

self.rawData = resp['body']['devices']
# Weather data
if not self.rawData : raise NoDevice("No weather station in any homes")
Expand Down Expand Up @@ -662,13 +672,19 @@ class HomeData:
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 )
#
warnings.warn("The HomeData code is deprecated.\n" ,
RuntimeWarning )

self.getAuthToken = authData.accessToken
postParams = {
"access_token" : self.getAuthToken
}
resp = postRequest("Home data", _GETHOMEDATA_REQ, postParams)

self.rawData = resp['body']
# Collect homes
self.homes = self.rawData['homes'][0]
Expand Down Expand Up @@ -781,12 +797,13 @@ def cameraUrls(self, camera=None, home=None, cid=None):
if camera_data:
vpn_url = camera_data['vpn_url']
resp = postRequest("Camera", vpn_url + '/command/ping')

temp_local_url=resp['local_url']
try:
resp = postRequest("Camera", temp_local_url + '/command/ping',timeout=1)
if resp and temp_local_url == resp['local_url']:
local_url = temp_local_url
except: # On this particular request, vithout errors from previous requests, error is timeout
except: # On this particular request, without errors from previous requests, error is timeout
local_url = None
return vpn_url, local_url

Expand Down Expand Up @@ -819,6 +836,7 @@ def getCameraPicture(self, image_id, key):
"key" : key
}
resp = postRequest("Camera", _GETCAMERAPICTURE_REQ, postParams)

return resp, "jpeg"

def getProfileImage(self, name):
Expand Down Expand Up @@ -852,6 +870,7 @@ def updateEvent(self, event=None, home=None):
"event_id" : event['id']
}
resp = postRequest("Camera", _GETEVENTSUNTIL_REQ, postParams)

eventList = resp['body']['events_list']
for e in eventList:
self.events[ e['camera_id'] ][ e['time'] ] = e
Expand Down Expand Up @@ -993,6 +1012,7 @@ def __init__(self, authData, home=None):
}
#
resp = postRequest("Module", _GETHOMES_DATA, postParams)

# self.rawData = resp['body']['devices']
self.rawData = resp['body']['homes']
if not self.rawData : raise NoHome("No home %s found" % home)
Expand Down Expand Up @@ -1030,6 +1050,7 @@ def __init__(self, authData):
"access_token" : self.getAuthToken
}
resp = postRequest("HomeCoach", _GETHOMECOACH, postParams)

self.rawData = resp['body']['devices']
# homecoach data
if not self.rawData : raise NoDevice("No HomeCoach available")
Expand Down Expand Up @@ -1077,6 +1098,7 @@ def rawAPI(authData, url, parameters=None):
if parameters is None: parameters = {}
parameters["access_token"] = authData.accessToken
resp = postRequest("rawAPI", fullUrl, parameters)

return resp["body"] if "body" in resp else resp

def filter_home_data(rawData, home):
Expand Down
31 changes: 16 additions & 15 deletions samples/weather2file.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,9 @@ def _to_dataframe(self, module_data_body, module_data, station_name, station_mac

def get_module_df(self, newest_utctime, station_name, station_mac, module_data_overview, end_date_timestamp, dtype={}, time_z=None):
logging.info(f'Processing {module_data_overview["module_name"]}...')



module_name = module_data_overview["module_name"]

# We start by collecting new data
keep_collecting_module_data = True

Expand All @@ -461,9 +460,11 @@ def get_module_df(self, newest_utctime, station_name, station_mac, module_data_o
keep_collecting_module_data = False
else:
logging.info(f'Collecting data for {module_name}...')

while(keep_collecting_module_data):

if (module_data_overview['data_type'] == 'wind'):
module_data_overview['data_type'] = ['WindStrength', 'WindAngle', 'GustStrength', 'GustAngle']

# Get new data from Netatmo
d = self._get_field_dict(station_mac,
module_data_overview['_id'],
Expand Down Expand Up @@ -500,7 +501,7 @@ def get_module_df(self, newest_utctime, station_name, station_mac, module_data_o
logging.error(e)
keep_collecting_module_data = False
logging.error(f'Something fishy is going on... Aborting collection for module {module_name}')


if data:
df_module = pd.concat(data,ignore_index=True)
Expand Down Expand Up @@ -595,11 +596,11 @@ def main():
else:
logging.basicConfig(format=" %(levelname)s: %(message)s", level=verbose_dict[args.verbose])


# Handle dataframes (loading, appending, saving).
df_handler = df_handler_dict[args.format](file_name=args.file_name, output_path=args.output_path)


# Rate handler to make sure that we don't exceed Netatmos user rate limits
rate_limit_handler = RateLimitHandler(
user_request_limit_per_ten_seconds=args.ten_second_rate_limit,
Expand All @@ -608,12 +609,12 @@ def main():


for station_name, station_data_overview in rate_limit_handler.get_stations():

station_mac = station_data_overview['_id']

station_timezone = timezone(station_data_overview['place']['timezone'])
logging.info(f'Timezone {station_timezone} extracted from data.')

end_datetime_timestamp = np.floor(datetime.timestamp(station_timezone.localize(args.end_datetime)))
newest_utc = df_handler.get_newest_timestamp(station_data_overview['_id'])
df_handler.append(
Expand All @@ -627,7 +628,7 @@ def main():
station_timezone))

for module_data_overview in station_data_overview['modules']:

df_handler.append(
rate_limit_handler.get_module_df(
df_handler.get_newest_timestamp(module_data_overview['_id']),
Expand All @@ -636,8 +637,8 @@ def main():
module_data_overview,
end_datetime_timestamp,
df_handler.dtype_dict,
station_timezone))
station_timezone))




Expand All @@ -646,4 +647,4 @@ def main():

if __name__ == "__main__":
main()