@@ -230,9 +230,11 @@ async def structure_systems(self, system_data):
230230 systems [this_system ["id" ]] = this_system
231231
232232 system_status = await self .get_status (this_system ["id" ])
233+ system_metrics = await self .get_realtime_metrics (this_system ["id" ])
233234
234235 try :
235236 systems [this_system ["id" ]]["status" ] = system_status ["wanConnectionStatus" ]
237+ systems [this_system ["id" ]]["groupTraffic" ] = system_metrics .get ("groupTraffic" ,None )
236238 except KeyError as error :
237239 raise GoogleWifiException (error )
238240
@@ -261,10 +263,12 @@ async def structure_systems(self, system_data):
261263 devices_list = await self .get_devices (this_system ["id" ])
262264
263265 devices = {}
266+ station_ids = []
264267
265268 try :
266269 for this_device in devices_list ["stations" ]:
267270 devices [this_device ["id" ]] = this_device
271+ station_ids .append (this_device ["id" ])
268272 device_paused = False
269273
270274 if blocking_policies .get (this_device ["id" ]):
@@ -277,6 +281,15 @@ async def structure_systems(self, system_data):
277281 except KeyError as error :
278282 raise GoogleWifiException (error )
279283
284+ sensitive_info = await self .get_sensitive_info (system_id = this_system ["id" ], station_ids = station_ids )
285+ for this_station in sensitive_info :
286+ if this_station ["stationId" ] in devices :
287+ devices [this_station ["stationId" ]]["macAddress" ] = this_station ["macAddress" ]
288+
289+ for this_station in system_metrics ["stationMetrics" ]:
290+ if this_station ["station" ]["id" ] in devices :
291+ devices [this_station ["station" ]["id" ]]["traffic" ] = this_station ["traffic" ]
292+
280293 systems [this_system ["id" ]]["devices" ] = devices
281294
282295 return systems
@@ -558,6 +571,73 @@ async def run_speed_test(self, system_id:str):
558571 results = await self .speed_test_results (system_id = system_id )
559572 return results [0 ]
560573
574+ async def start_retrieve_sensitive_info (self , system_id :str , station_ids :list ):
575+ """Start the request to return the device sensitive information."""
576+ if await self .connect ():
577+ url = f"https://googlehomefoyer-pa.googleapis.com/v2/groups/{ system_id } /stations/operations/sensitiveInfo"
578+
579+ headers = {
580+ "Content-Type" : "application/json; charset=utf-8" ,
581+ "Authorization" : f"Bearer { self ._api_token } "
582+ }
583+ json_payload = {"stationIds" :station_ids }
584+ params = (
585+ ('prettyPrint' , 'false' ),
586+ )
587+
588+ response = await self .post_api (url = url ,headers = headers ,json_payload = json_payload ,params = params )
589+ operation_id = response ["operation" ]["operationId" ]
590+
591+ return operation_id
592+
593+ async def sensitive_info_results (self , operation_id :str ):
594+ """Return the results of the sensitive info request."""
595+ if await self .connect ():
596+ url = f"https://googlehomefoyer-pa.googleapis.com/v2/operations/{ operation_id } /sensitiveInfo"
597+ params = (
598+ ('prettyPrint' , 'false' ),
599+ )
600+ headers = {
601+ "Content-Type" : "application/json; charset=utf-8" ,
602+ "Authorization" : f"Bearer { self ._api_token } "
603+ }
604+ payload = {}
605+
606+ return await self .get_api (url = url , headers = headers , payload = payload , params = params )
607+
608+ async def get_sensitive_info (self , system_id :str , station_ids :list ):
609+ """Return a full set of sensitive info on the system."""
610+ if await self .connect ():
611+ operation_id = await self .start_retrieve_sensitive_info (
612+ system_id = system_id ,station_ids = station_ids
613+ )
614+
615+ status = await self .check_operation (operation_id )
616+ status = status ["operationState" ]
617+
618+ while status != "DONE" :
619+ status = await self .check_operation (operation_id )
620+ status = status ["operationState" ]
621+ await asyncio .sleep (5 )
622+
623+ results = await self .sensitive_info_results (operation_id = operation_id )
624+ return results ["stationSensitiveInfos" ]
625+
626+ async def get_realtime_metrics (self , system_id :str ):
627+ """Return real-time metrics from the system."""
628+ if await self .connect ():
629+ url = f"https://googlehomefoyer-pa.googleapis.com/v2/groups/{ system_id } /realtimeMetrics"
630+ params = (
631+ ('prettyPrint' , 'false' ),
632+ )
633+ headers = {
634+ "Content-Type" : "application/json; charset=utf-8" ,
635+ "Authorization" : f"Bearer { self ._api_token } "
636+ }
637+ payload = {}
638+
639+ return await self .get_api (url = url , headers = headers , payload = payload , params = params )
640+
561641
562642class GoogleWifiException (Exception ):
563643 """Platform not ready exception."""
0 commit comments