@@ -43,18 +43,16 @@ def _update_children_info(self) -> None:
43
43
for info in child_info ["child_device_list" ]:
44
44
self ._children [info ["device_id" ]]._update_internal_state (info )
45
45
46
- async def _initialize_smart_child (self , info : dict ) -> SmartDevice :
46
+ async def _initialize_smart_child (
47
+ self , info : dict , child_components : dict
48
+ ) -> SmartDevice :
47
49
"""Initialize a smart child device attached to a smartcamera."""
48
50
child_id = info ["device_id" ]
49
51
child_protocol = _ChildCameraProtocolWrapper (child_id , self .protocol )
50
52
try :
51
53
initial_response = await child_protocol .query (
52
- {"component_nego" : None , " get_connect_cloud_state" : None }
54
+ {"get_connect_cloud_state" : None }
53
55
)
54
- child_components = {
55
- item ["id" ]: item ["ver_code" ]
56
- for item in initial_response ["component_nego" ]["component_list" ]
57
- }
58
56
except Exception as ex :
59
57
_LOGGER .exception ("Error initialising child %s: %s" , child_id , ex )
60
58
@@ -68,20 +66,28 @@ async def _initialize_smart_child(self, info: dict) -> SmartDevice:
68
66
69
67
async def _initialize_children (self ) -> None :
70
68
"""Initialize children for hubs."""
71
- if not (
72
- child_info := self . _try_get_response (
73
- self . _last_update , "getChildDeviceList" , {}
74
- )
75
- ):
76
- return
69
+ child_info_query = {
70
+ "getChildDeviceList" : { "childControl" : { "start_index" : 0 }},
71
+ "getChildDeviceComponentList" : { "childControl" : { "start_index" : 0 }},
72
+ }
73
+ resp = await self . protocol . query ( child_info_query )
74
+ self . internal_state . update ( resp )
77
75
76
+ children_components = {
77
+ child ["device_id" ]: {
78
+ comp ["id" ]: int (comp ["ver_code" ]) for comp in child ["component_list" ]
79
+ }
80
+ for child in resp ["getChildDeviceComponentList" ]["child_component_list" ]
81
+ }
78
82
children = {}
79
- for info in child_info ["child_device_list" ]:
83
+ for info in resp [ "getChildDeviceList" ] ["child_device_list" ]:
80
84
if (
81
85
category := info .get ("category" )
82
86
) and category in SmartChildDevice .CHILD_DEVICE_TYPE_MAP :
83
87
child_id = info ["device_id" ]
84
- children [child_id ] = await self ._initialize_smart_child (info )
88
+ children [child_id ] = await self ._initialize_smart_child (
89
+ info , children_components [child_id ]
90
+ )
85
91
else :
86
92
_LOGGER .debug ("Child device type not supported: %s" , info )
87
93
@@ -90,6 +96,11 @@ async def _initialize_children(self) -> None:
90
96
async def _initialize_modules (self ) -> None :
91
97
"""Initialize modules based on component negotiation response."""
92
98
for mod in SmartCameraModule .REGISTERED_MODULES .values ():
99
+ if (
100
+ mod .REQUIRED_COMPONENT
101
+ and mod .REQUIRED_COMPONENT not in self ._components
102
+ ):
103
+ continue
93
104
module = mod (self , mod ._module_name ())
94
105
if await module ._check_supported ():
95
106
self ._modules [module .name ] = module
@@ -126,12 +137,21 @@ async def _negotiate(self) -> None:
126
137
"""
127
138
initial_query = {
128
139
"getDeviceInfo" : {"device_info" : {"name" : ["basic_info" , "info" ]}},
129
- "getChildDeviceList " : {"childControl " : {"start_index " : 0 }},
140
+ "getAppComponentList " : {"app_component " : {"name " : "app_component_list" }},
130
141
}
131
142
resp = await self .protocol .query (initial_query )
132
143
self ._last_update .update (resp )
133
144
self ._update_internal_info (resp )
134
- await self ._initialize_children ()
145
+
146
+ self ._components = {
147
+ comp ["name" ]: int (comp ["version" ])
148
+ for comp in resp ["getAppComponentList" ]["app_component" ][
149
+ "app_component_list"
150
+
629A
]
151
+ }
152
+
153
+ if "childControl" in self ._components and not self .children :
154
+ await self ._initialize_children ()
135
155
136
156
def _map_info (self , device_info : dict ) -> dict :
137
157
basic_info = device_info ["basic_info" ]
0 commit comments