Skip to content

Commit 375ba63

Browse files
authored
change Homecoach
1 parent 47bc528 commit 375ba63

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

lnetatmo.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -932,10 +932,10 @@ class HomeCoach:
932932
authData (clientAuth): Authentication information with a working access Token
933933
home : Home name or id of the home who's HomeCoach belongs to
934934
"""
935-
# FIXME: home parameter not used, unpredictible behavior
936-
def __init__(self, authData, home=None):
937-
# I don't own a HomeCoach thus I am not able to test the HomeCoach support
938935

936+
def __init__(self, authData):
937+
# I don't own a HomeCoach thus I am not able to test the HomeCoach support
938+
# Homecoach does not need or use HomeID parameter
939939
# warnings.warn("The HomeCoach code is not tested due to the lack of test environment.\n", RuntimeWarning )
940940
# "As Netatmo is continuously breaking API compatibility, risk that current bindings are wrong is high.\n" \
941941
# "Please report found issues (https://github.com/philippelt/netatmo-api-python/issues)"
@@ -949,34 +949,40 @@ def __init__(self, authData, home=None):
949949
# homecoach data
950950
if not self.rawData : raise NoDevice("No HomeCoach available")
951951

952-
for h in self.rawData:
953-
# FIXME: This loop is nonsense (always end with the last value)
954-
self.HomecoachDevice = h
955-
# print ('Homecoach = ', self.HomecoachDevice)
956-
# print (' ')
957-
# print ('Homecoach_data = ', self.rawData[i]['dashboard_data'])
958-
# print (' ')
952+
def HomecoachDevice(self, id=""):
953+
for device in self.rawData:
954+
if id in device['_id']:
955+
return device
956+
self.HomecoachDevice = device
959957

960-
def Dashboard(self):
961-
D = self.HomecoachDevice['dashboard_data']
962-
return D
958+
def Dashboard(self, id=""):
959+
#D = self.HomecoachDevice['dashboard_data']
960+
for device in self.rawData:
961+
if id in device['_id']:
962+
D = device['dashboard_data']
963+
return D
963964

964-
# FIXME: Exclusion of outdated info is not handled (exclude parameter unused)
965965
def lastData(self, hid=None, exclude=0):
966-
if hid is not None:
967-
s = self.HomecoachDevice['dashboard_data']['time_utc']
968-
_id = self.HomecoachDevice[hid]
969-
return {'When':s}, {'_id':_id}
970-
return {'When': 0 }, {'_id': hid}
966+
for device in self.rawData:
967+
if id == device['_id']:
968+
#s = self.HomecoachDevice['dashboard_data']['time_utc']
969+
# Define oldest acceptable sensor measure event
970+
limit = (time.time() - exclude) if exclude else 0
971+
ds = self.HomecoachDevice['dashboard_data']
972+
if ds.get('time_utc',limit+10) > limit :
973+
_id = s[id]
974+
return {'When':s, '_id':_id}
975+
else:
976+
return {'When': 0, 'id': id}
971977

972-
def checkNotUpdated(self, res, _id, delay=3600):
978+
def checkNotUpdated(self, res, hid, delay=3600):
973979
ret = []
974-
if time.time()-res['When'] > delay : ret.append({_id: 'Device Not Updated'})
980+
if time.time()-res['When'] > delay : ret.append({hid: 'Device Not Updated'})
975981
return ret if ret else None
976982

977-
def checkUpdated(self, res, _id, delay=3600):
983+
def checkUpdated(self, res, hid, delay=3600):
978984
ret = []
979-
if time.time()-res['When'] < delay : ret.append({_id: 'Device up-to-date'})
985+
if time.time()-res['When'] < delay : ret.append({hid: 'Device up-to-date'})
980986
return ret if ret else None
981987

982988

0 commit comments

Comments
 (0)