@@ -932,10 +932,10 @@ class HomeCoach:
932
932
authData (clientAuth): Authentication information with a working access Token
933
933
home : Home name or id of the home who's HomeCoach belongs to
934
934
"""
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
938
935
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
939
939
# warnings.warn("The HomeCoach code is not tested due to the lack of test environment.\n", RuntimeWarning )
940
940
# "As Netatmo is continuously breaking API compatibility, risk that current bindings are wrong is high.\n" \
941
941
# "Please report found issues (https://github.com/philippelt/netatmo-api-python/issues)"
@@ -949,34 +949,40 @@ def __init__(self, authData, home=None):
949
949
# homecoach data
950
950
if not self .rawData : raise NoDevice ("No HomeCoach available" )
951
951
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
959
957
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
963
964
964
- # FIXME: Exclusion of outdated info is not handled (exclude parameter unused)
965
965
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 }
971
977
972
- def checkNotUpdated (self , res , _id , delay = 3600 ):
978
+ def checkNotUpdated (self , res , hid , delay = 3600 ):
973
979
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' })
975
981
return ret if ret else None
976
982
977
- def checkUpdated (self , res , _id , delay = 3600 ):
983
+ def checkUpdated (self , res , hid , delay = 3600 ):
978
984
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' })
980
986
return ret if ret else None
981
987
982
988
0 commit comments