Skip to content

Commit c229ef7

Browse files
committed
2 parents 7bd29fc + f75c8db commit c229ef7

File tree

2 files changed

+103
-9
lines changed

2 files changed

+103
-9
lines changed

lnetatmo.py

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def getParameter(key, default):
8787
_GETHOMEDATA_REQ = _BASE_URL + "api/gethomedata"
8888
_GETCAMERAPICTURE_REQ = _BASE_URL + "api/getcamerapicture"
8989
_GETEVENTSUNTIL_REQ = _BASE_URL + "api/geteventsuntil"
90+
_HOME_STATUS = _BASE_URL + "api/homestatus" # Used for Home+ Control Devices
9091

9192

9293
#TODO# Undocumented (but would be very usefull) API : Access currently forbidden (403)
@@ -172,7 +173,7 @@ class ClientAuth:
172173
def __init__(self, clientId=_CLIENT_ID,
173174
clientSecret=_CLIENT_SECRET,
174175
refreshToken=_REFRESH_TOKEN):
175-
176+
176177
self._clientId = clientId
177178
self._clientSecret = clientSecret
178179
self._accessToken = None
@@ -226,6 +227,59 @@ class UserInfo:
226227
pass
227228

228229

230+
class HomeStatus:
231+
"""
232+
List all Home+Control devices (Smarther thermostat, Socket, Cable Output, Centralized fan, Micromodules, ......)
233+
234+
Args:
235+
authData (clientAuth): Authentication information with a working access Token
236+
home : Home name or id of the home who's thermostat belongs to
237+
"""
238+
def __init__(self, authData, home_id):
239+
240+
self.getAuthToken = authData.accessToken
241+
postParams = {
242+
"access_token" : self.getAuthToken,
243+
"home_id": home_id
244+
}
245+
resp = postRequest("home_status", _HOME_STATUS, postParams)
246+
self.resp = resp
247+
self.rawData = resp['body']['home']
248+
if not self.rawData : raise NoHome("No home %s found" % home_id)
249+
self.rooms = self.rawData['rooms']
250+
self.modules = self.rawData['modules']
251+
252+
def getRoomsId(self):
253+
return [room['id'] for room in self.rooms]
254+
255+
def getListRoomParam(self, room_id):
256+
for room in self.rooms:
257+
if(room['id'] == room_id):
258+
return [param for param in room]
259+
return None
260+
261+
def getRoomParam(self, room_id, param):
262+
for room in self.rooms:
263+
if(room['id'] == room_id and param in room):
264+
return room[param]
265+
return None
266+
267+
def getModulesId(self):
268+
return [module['id'] for module in self.modules]
269+
270+
def getListModuleParam(self, module_id):
271+
for module in self.modules:
272+
if(module['id'] == module_id):
273+
return [param for param in module]
274+
return None
275+
276+
def getModuleParam(self, module_id, param):
277+
for module in self.modules:
278+
if(module['id'] == module_id and param in module):
279+
return module[param]
280+
return None
281+
282+
229283
class ThermostatData:
230284
"""
231285
List the Thermostat and temperature modules
@@ -260,7 +314,7 @@ def __init__(self, authData, home=None):
260314

261315
def getThermostat(self, name=None):
262316
if ['name'] != name: return None
263-
else: return
317+
else: return
264318
return self.thermostat[self.defaultThermostatId]
265319

266320
def moduleNamesList(self, name=None, tid=None):
@@ -688,7 +742,7 @@ def presenceUrl(self, camera=None, home=None, cid=None, setting=None):
688742
if camera["type"] != "NOC": return None # Not a presence camera
689743
vpnUrl, localUrl = self.cameraUrls(cid=camera["id"])
690744
return localUrl
691-
745+
692746
def presenceLight(self, camera=None, home=None, cid=None, setting=None):
693747
url = self.presenceUrl(home=home, camera=camera) or self.cameraById(cid=cid)
694748
if not url or setting not in ("on", "off", "auto"): return None
@@ -753,7 +807,7 @@ def filter_home_data(rawData, home):
753807
def cameraCommand(cameraUrl, commande, parameters=None, timeout=3):
754808
url = cameraUrl + ( commande % parameters if parameters else commande)
755809
return postRequest("Camera", url, timeout=timeout)
756-
810+
757811
def postRequest(topic, url, params=None, timeout=10):
758812
if PYTHON3:
759813
req = urllib.request.Request(url)
@@ -824,7 +878,7 @@ def getStationMinMaxTH(station=None, module=None, home=None):
824878
result[m] = (r[0], lastD[m]['Temperature'], r[1])
825879
else:
826880
if time.time()-lastD[module]['When'] > 3600 : result = ["-", "-"]
827-
else :
881+
else :
828882
result = [lastD[module]['Temperature'], lastD[module]['Humidity']]
829883
result.extend(devList.MinMaxTH(module))
830884
return result
@@ -835,15 +889,15 @@ def getStationMinMaxTH(station=None, module=None, home=None):
835889
if __name__ == "__main__":
836890

837891
from sys import exit, stdout, stderr
838-
892+
839893
logging.basicConfig(format='%(name)s - %(levelname)s: %(message)s', level=logging.INFO)
840894

841895
if not _CLIENT_ID or not _CLIENT_SECRET or not _REFRESH_TOKEN :
842896
stderr.write("Library source missing identification arguments to check lnetatmo.py (user/password/etc...)")
843897
exit(1)
844898

845899
authorization = ClientAuth() # Test authentication method
846-
900+
847901
try:
848902
weatherStation = WeatherStationData(authorization) # Test DEVICELIST
849903
except NoDevice:

usage.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,49 @@ Methods :
424424
* **getLiveSnapshot** (camera=None, home=None, cid=None) : Get a jpeg of current live view of the camera
425425
* Input : camera name and optional home name or cameraID to lookup (str)
426426
* Output : jpeg binary content
427+
428+
429+
#### 4-6 HomeStatus class ####
430+
431+
432+
Constructor
433+
434+
```python
435+
homeStatus = lnetatmo.HomeStatus( authorization, home_id )
436+
```
437+
438+
Requires :
439+
- an authorization object (ClientAuth instance)
440+
- home_id which can be found in https://dev.netatmo.com/apidocumentation/control by using "GET homesdata"
441+
442+
Return : a homeStatus object. This object contains most administration properties of Home+ Control devices such as Smarther thermostat, Socket, Cable Output, Centralized fan, Micromodules, ...
443+
444+
Methods :
445+
446+
* **getRoomsId** : return all room ID
447+
* Output : list of IDs of every single room (only the one with Smarther thermostat)
448+
449+
* **getListRoomParam** : return every parameters of a room
450+
* Input : room ID
451+
* Output : list of parameters of a room
452+
453+
* **getRoomParam** : return a specific parameter for a specific room
454+
* Input : room ID and parameter
455+
* Output : value
456+
457+
* **getModulesId** : return all module IDs
458+
* Output : list of IDs of every single module (socket, cable outlet, ...)
459+
460+
* **getListModuleParam** : return every parameters of a module
461+
* Input : module ID
462+
* Output : list of parameters of a module
463+
464+
* **getModuleParam** : return a specific parameter for a specific module
465+
* Input : module ID and parameter
466+
* Output : value
427467

428468

429-
#### 4-5 Utilities functions ####
469+
#### 4-7 Utilities functions ####
430470

431471

432472
* **rawAPI** (authentication, APIkeyword, parameters) : Direct call an APIkeyword from Netatmo and return a dictionary with the raw response the APIkeywork is the path without the / before as specified in the documentation (eg. "gethomesdata" or "homestatus")
@@ -435,7 +475,7 @@ Methods :
435475
* **todayStamps**() : Return a couple of epoch time (start, end) for the current day
436476

437477

438-
#### 4-6 All-in-One function ####
478+
#### 4-8 All-in-One function ####
439479

440480

441481
If you just need the current temperature and humidity reported by a sensor with associated min and max values on the last 24 hours, you can get it all with only one call that handle all required steps including authentication :

0 commit comments

Comments
 (0)