Skip to content

Commit 63f4e96

Browse files
authored
Update lnetatmo.py
class HomeStatus in order to list all Home+Control devices (Smarther thermostat, Socket, Cable Output, Centralized fan, Micromodules, ......)
1 parent 73e5ea4 commit 63f4e96

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
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
@@ -749,7 +803,7 @@ def filter_home_data(rawData, home):
749803
def cameraCommand(cameraUrl, commande, parameters=None, timeout=3):
750804
url = cameraUrl + ( commande % parameters if parameters else commande)
751805
return postRequest("Camera", url, timeout=timeout)
752-
806+
753807
def postRequest(topic, url, params=None, timeout=10):
754808
if PYTHON3:
755809
req = urllib.request.Request(url)
@@ -816,7 +870,7 @@ def getStationMinMaxTH(station=None, module=None, home=None):
816870
result[m] = (r[0], lastD[m]['Temperature'], r[1])
817871
else:
818872
if time.time()-lastD[module]['When'] > 3600 : result = ["-", "-"]
819-
else :
873+
else :
820874
result = [lastD[module]['Temperature'], lastD[module]['Humidity']]
821875
result.extend(devList.MinMaxTH(module))
822876
return result
@@ -827,15 +881,15 @@ def getStationMinMaxTH(station=None, module=None, home=None):
827881
if __name__ == "__main__":
828882

829883
from sys import exit, stdout, stderr
830-
884+
831885
logging.basicConfig(format='%(name)s - %(levelname)s: %(message)s', level=logging.INFO)
832886

833887
if not _CLIENT_ID or not _CLIENT_SECRET or not _REFRESH_TOKEN :
834888
stderr.write("Library source missing identification arguments to check lnetatmo.py (user/password/etc...)")
835889
exit(1)
836890

837891
authorization = ClientAuth() # Test authentication method
838-
892+
839893
try:
840894
weatherStation = WeatherStationData(authorization) # Test DEVICELIST
841895
except NoDevice:

0 commit comments

Comments
 (0)