@@ -341,8 +341,8 @@ def getModuleParam(self, module_id, param):
341
341
342
342
class ThermostatData :
343
343
"""
344
- List the Thermostat and temperature modules
345
-
344
+ List the Relay station and Thermostat modules
345
+ Valves are controlled by HomesData and HomeStatus in new API
346
346
Args:
347
347
authData (clientAuth): Authentication information with a working access Token
348
348
home : Home name or id of the home who's thermostat belongs to
@@ -375,36 +375,72 @@ def __init__(self, authData, home=None):
375
375
# Standard the first Relaystation and Thermostat is returned
376
376
# self.rawData is list all stations
377
377
378
- # FIXME : This code is wrong as it will always return the first Relay
379
- # I don't own a thermostat I can't fix this code, help welcome
380
- def Relay_Plug (self , _id = None ):
378
+ # if no ID is given the Relaystation at index 0 is returned
379
+ def Relay_Plug (self , Rid = "" ):
381
380
for Relay in self .rawData :
382
- if _id in Relay :
383
- return Relay
384
- else :
381
+ if Rid in Relay [ '_id' ] :
382
+ print ( ' Relay ' , Rid , 'in rawData' )
383
+ #print (Relay.keys())
385
384
#print (Relay['_id'])
386
385
return Relay
386
+ #dict_keys(['_id', 'applications', 'cipher_id', 'command', 'config_version', 'd_amount', 'date_creation', 'dev_has_init', 'device_group', 'firmware', 'firmware_private', 'homekit_nb_pairing', 'last_bilan', 'last_day_extremum', 'last_fw_update', 'last_measure_stored', 'last_setup', 'last_status_store', 'last_sync_asked', 'last_time_boiler_on', 'mg_station_name', 'migration_date', 'module_history', 'netcom_transport', 'new_historic_data', 'place', 'plug_connected_boiler', 'recompute_outdoor_time', 'record_storage', 'rf_amb_status', 'setpoint_order_history', 'skip_module_history_creation', 'subtype', 'type', 'u_amount', 'update_device', 'upgrade_record_ts', 'wifi_status', 'room', 'modules', 'station_name', 'udp_conn', 'last_plug_seen'])
387
+
388
+ # if no ID is given the Thermostatmodule at index 0 is returned
389
+ def Thermostat_Data (self , tid = "" ):
390
+ for Relay in self .rawData :
391
+ for thermostat in Relay ['modules' ]:
392
+ if tid in thermostat ['_id' ]:
393
+ print ('Thermostat ' ,tid , 'in Relay' , Relay ['_id' ], Relay ['station_name' ])
394
+ #print (thermostat['_id'])
395
+ #print (thermostat.keys())
396
+ return thermostat
397
+ #dict_keys(['_id', 'module_name', 'type', 'firmware', 'last_message', 'rf_status', 'battery_vp', 'therm_orientation', 'therm_relay_cmd', 'anticipating', 'battery_percent', 'event_history', 'last_therm_seen', 'setpoint', 'therm_program_list', 'measured'])
387
398
388
- # FIXME : Probably wrong again, always returning "first" thermostat ?
389
- def Thermostat_Data (self ):
390
- for thermostat in self .Relay_Plug ()['modules' ]:
391
- #
392
- return thermostat
393
399
394
- def getThermostat (self , name = None , tid = None ):
395
- if self .rawData [0 ]['station_name' ] != name : return None # OLD ['name']
396
- # FIXME: No thermostat property !!
397
- return self .thermostat [self .defaultThermostatId ]
400
+ def getThermostat (self , name = None , id = "" ):
401
+ for Relay in self .rawData :
402
+ for module in Relay ['modules' ]:
403
+ if id == Relay ['_id' ]:
404
+ print ('Relay ' , id , 'found' )
405
+ return Relay
406
+ elif name == Relay ['station_name' ]:
407
+ print ('Relay ' , name , 'found' )
408
+ return Relay
409
+ elif id == module ['_id' ]:
410
+ print ('Thermostat ' , id , 'found in Relay' , Relay ['_id' ], Relay ['station_name' ])
411
+ return module
412
+ elif name == module ['module_name' ]:
413
+ print ('Thermostat ' , name , 'found in Relay' , Relay ['_id' ], Relay ['station_name' ])
414
+ return module
415
+ else :
416
+ #print ('Device NOT Found')
417
+ pass
398
418
399
419
def moduleNamesList (self , name = None , tid = None ):
400
- thermostat = self .getThermostat (name = name , tid = tid )
401
- return [m ['name' ] for m in thermostat ['modules' ]] if thermostat else None
420
+ l = []
421
+ for Relay in self .rawData :
422
+ if id == Relay ['_id' ] or name == Relay ['station_name' ]:
423
+ RL = []
424
+ for module in Relay ['modules' ]:
425
+ RL .append (module ['module_name' ])
426
+ return RL
427
+ else :
428
+ #print ("Cloud Data")
429
+ for module in Relay ['modules' ]:
430
+ l .append (module ['module_name' ])
431
+ #This return a list off all connected Thermostat in the cloud.
432
+ return l
402
433
403
- def getModuleByName (self , name , thermostatId = None ): # ERROR 'NoneType' object is not subscriptable
404
- thermostat = self .getThermostat (tid = thermostatId )
405
- for m in thermostat ['modules' ]:
406
- if m ['name' ] == name : return m
407
- return None
434
+ def getModuleByName (self , name , tid = "" ):
435
+ for Relay in self .rawData :
436
+ for module in Relay ['modules' ]:
437
+ #print (module['module_name'], module['_id'])
438
+ if module ['module_name' ] == name :
439
+ return module
440
+ elif module ['_id' ] == tid :
441
+ return module
442
+ else :
443
+ pass
408
444
409
445
410
446
class WeatherStationData :
0 commit comments