1515
1616from .containers import (
1717 AuthorizationInfo ,
18+ BabyData ,
1819 SnooData ,
1920 SnooDevice ,
2021 SnooStates ,
2122)
22- from .exceptions import InvalidSnooAuth , SnooAuthException , SnooCommandException , SnooDeviceError
23+ from .exceptions import InvalidSnooAuth , SnooAuthException , SnooBabyError , SnooCommandException , SnooDeviceError
2324from .pubnub_async import SnooPubNub
2425
2526_LOGGER = logging .getLogger (__name__ )
@@ -34,7 +35,7 @@ def __init__(self, email: str, password: str, clientsession: aiohttp.ClientSessi
3435 self .snoo_auth_url = "https://api-us-east-1-prod.happiestbaby.com/us/me/v10/pubnub/authorize"
3536 self .snoo_devices_url = "https://api-us-east-1-prod.happiestbaby.com/hds/me/v11/devices"
3637 self .snoo_data_url = "https://happiestbaby.pubnubapi.com"
37- self .snoo_baby_url = "https://api-us-east-1-prod.happiestbaby.com/us/me/v10/babies/ "
38+ self .snoo_baby_url = "https://api-us-east-1-prod.happiestbaby.com/us/me/v10/babies"
3839 self .aws_auth_hdr = {
3940 "x-amz-target" : "AWSCognitoIdentityProviderService.InitiateAuth" ,
4041 "accept-language" : "US" ,
@@ -326,6 +327,16 @@ async def get_devices(self) -> list[SnooDevice]:
326327 devs = [SnooDevice .from_dict (dev ) for dev in resp ["snoo" ]]
327328 return devs
328329
330+ async def get_babies (self ) -> list [BabyData ]:
331+ hdrs = self .generate_snoo_auth_headers (self .tokens .aws_id )
332+ try :
333+ r = await self .session .get (self .snoo_baby_url , headers = hdrs )
334+ resp = await r .json ()
335+ except Exception as ex :
336+ raise SnooBabyError from ex
337+ babies = [BabyData .from_dict (baby ) for baby in resp ]
338+ return babies
339+
329340 def start_subscribe (self , device : SnooDevice , function : Callable ):
330341 if device .serialNumber in self ._mqtt_tasks and not self ._mqtt_tasks [device .serialNumber ].done ():
331342 _LOGGER .warning (f"Subscription task for device { device .serialNumber } is already running." )
0 commit comments