@@ -87,6 +87,7 @@ def getParameter(key, default):
87
87
_GETHOMEDATA_REQ = _BASE_URL + "api/gethomedata"
88
88
_GETCAMERAPICTURE_REQ = _BASE_URL + "api/getcamerapicture"
89
89
_GETEVENTSUNTIL_REQ = _BASE_URL + "api/geteventsuntil"
90
+ _HOME_STATUS = _BASE_URL + "api/homestatus" # Used for Home+ Control Devices
90
91
91
92
92
93
#TODO# Undocumented (but would be very usefull) API : Access currently forbidden (403)
@@ -172,7 +173,7 @@ class ClientAuth:
172
173
def __init__ (self , clientId = _CLIENT_ID ,
173
174
clientSecret = _CLIENT_SECRET ,
174
175
refreshToken = _REFRESH_TOKEN ):
175
-
176
+
176
177
self ._clientId = clientId
177
178
self ._clientSecret = clientSecret
178
179
self ._accessToken = None
@@ -226,6 +227,59 @@ class UserInfo:
226
227
pass
227
228
228
229
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
+
229
283
class ThermostatData :
230
284
"""
231
285
List the Thermostat and temperature modules
@@ -260,7 +314,7 @@ def __init__(self, authData, home=None):
260
314
261
315
def getThermostat (self , name = None ):
262
316
if ['name' ] != name : return None
263
- else : return
317
+ else : return
264
318
return self .thermostat [self .defaultThermostatId ]
265
319
266
320
def moduleNamesList (self , name = None , tid = None ):
@@ -688,7 +742,7 @@ def presenceUrl(self, camera=None, home=None, cid=None, setting=None):
688
742
if camera ["type" ] != "NOC" : return None # Not a presence camera
689
743
vpnUrl , localUrl = self .cameraUrls (cid = camera ["id" ])
690
744
return localUrl
691
-
745
+
692
746
def presenceLight (self , camera = None , home = None , cid = None , setting = None ):
693
747
url = self .presenceUrl (home = home , camera = camera ) or self .cameraById (cid = cid )
694
748
if not url or setting not in ("on" , "off" , "auto" ): return None
@@ -749,7 +803,7 @@ def filter_home_data(rawData, home):
749
803
def cameraCommand (cameraUrl , commande , parameters = None , timeout = 3 ):
750
804
url = cameraUrl + ( commande % parameters if parameters else commande )
751
805
return postRequest ("Camera" , url , timeout = timeout )
752
-
806
+
753
807
def postRequest (topic , url , params = None , timeout = 10 ):
754
808
if PYTHON3 :
755
809
req = urllib .request .Request (url )
@@ -816,7 +870,7 @@ def getStationMinMaxTH(station=None, module=None, home=None):
816
870
result [m ] = (r [0 ], lastD [m ]['Temperature' ], r [1 ])
817
871
else :
818
872
if time .time ()- lastD [module ]['When' ] > 3600 : result = ["-" , "-" ]
819
- else :
873
+ else :
820
874
result = [lastD [module ]['Temperature' ], lastD [module ]['Humidity' ]]
821
875
result .extend (devList .MinMaxTH (module ))
822
876
return result
@@ -827,15 +881,15 @@ def getStationMinMaxTH(station=None, module=None, home=None):
827
881
if __name__ == "__main__" :
828
882
829
883
from sys import exit , stdout , stderr
830
-
884
+
831
885
logging .basicConfig (format = '%(name)s - %(levelname)s: %(message)s' , level = logging .INFO )
832
886
833
887
if not _CLIENT_ID or not _CLIENT_SECRET or not _REFRESH_TOKEN :
834
888
stderr .write ("Library source missing identification arguments to check lnetatmo.py (user/password/etc...)" )
835
889
exit (1 )
836
890
837
891
authorization = ClientAuth () # Test authentication method
838
-
892
+
839
893
try :
840
894
weatherStation = WeatherStationData (authorization ) # Test DEVICELIST
841
895
except NoDevice :
0 commit comments