@@ -103,6 +103,7 @@ def __init__(
103103 )
104104 self .devices = {}
105105 self .deviceList = {}
106+ self .hub_id = None
106107
107108 def openFile (self , file : str ):
108109 """Open a file.
@@ -145,7 +146,7 @@ def addList(self, entityType: str, data: dict, **kwargs: dict):
145146 "hiveType" : data .get ("type" , "" ),
146147 "haType" : entityType ,
147148 "deviceData" : device .get ("props" , data .get ("props" , {})),
148- "parentDevice" : data . get ( "parent" , None ) ,
149+ "parentDevice" : self . hub_id ,
149150 "isGroup" : data .get ("isGroup" , False ),
150151 "device_id" : device ["id" ],
151152 "device_name" : device_name ,
@@ -160,6 +161,7 @@ def addList(self, entityType: str, data: dict, **kwargs: dict):
160161
161162 if data .get ("type" , "" ) == "hub" :
162163 self .deviceList ["parent" ].append (formatted_data )
164+ self .deviceList [entityType ].append (formatted_data )
163165 else :
164166 self .deviceList [entityType ].append (formatted_data )
165167
@@ -532,6 +534,25 @@ async def createDevices(self):
532534 self .deviceList ["switch" ] = []
533535 self .deviceList ["water_heater" ] = []
534536
537+ hive_type = HIVE_TYPES ["Thermo" ] + HIVE_TYPES ["Sensor" ]
538+ for aDevice in self .data ["devices" ]:
539+ if self .data ["devices" ][aDevice ]["type" ] == "hub" :
540+ self .hub_id = aDevice
541+ break
542+ for aDevice in self .data ["devices" ]:
543+ d = self .data .devices [aDevice ]
544+ device_list = DEVICES .get (self .data .devices [aDevice ]["type" ], [])
545+ for code in device_list :
546+ eval ("self." + code )
547+
548+ if self .data ["devices" ][aDevice ]["type" ] in hive_type :
549+ self .config .battery .append (d ["id" ])
550+
551+ if "action" in HIVE_TYPES ["Switch" ]:
552+ for action in self .data ["actions" ]:
553+ a = self .data ["actions" ][action ] # noqa: F841
554+ eval ("self." + ACTIONS )
555+
535556 hive_type = HIVE_TYPES ["Heating" ] + HIVE_TYPES ["Switch" ] + HIVE_TYPES ["Light" ]
536557 for aProduct in self .data .products :
537558 p = self .data .products [aProduct ]
@@ -555,21 +576,6 @@ async def createDevices(self):
555576 if self .data .products [aProduct ]["type" ] in hive_type :
556577 self .config .mode .append (p ["id" ])
557578
558- hive_type = HIVE_TYPES ["Thermo" ] + HIVE_TYPES ["Sensor" ]
559- for aDevice in self .data ["devices" ]:
560- d = self .data .devices [aDevice ]
561- device_list = DEVICES .get (self .data .devices [aDevice ]["type" ], [])
562- for code in device_list :
563- eval ("self." + code )
564-
565- if self .data ["devices" ][aDevice ]["type" ] in hive_type :
566- self .config .battery .append (d ["id" ])
567-
568- if "action" in HIVE_TYPES ["Switch" ]:
569- for action in self .data ["actions" ]:
570- a = self .data ["actions" ][action ] # noqa: F841
571- eval ("self." + ACTIONS )
572-
573579 return self .deviceList
574580
575581 @staticmethod
0 commit comments