diff --git a/python_snoo/containers.py b/python_snoo/containers.py index a43b1e0..53972a5 100644 --- a/python_snoo/containers.py +++ b/python_snoo/containers.py @@ -150,15 +150,15 @@ class BabySettings(DataClassJSONMixin): class BabyData(DataClassJSONMixin): _id: str babyName: str - birthDate: str breathSettingHistory: list createdAt: str disabledLimiter: bool - expectedBirthDate: str pictures: list settings: BabySettings sex: str preemie: Any | None = None # Not sure what datatype this is yet & may not be supplied - boolean? + birthDate: str | None = None + expectedBirthDate: str | None = None startedUsingSnooAt: str | None = None updatedAt: str | None = None diff --git a/python_snoo/snoo.py b/python_snoo/snoo.py index c1b93ab..b78add9 100644 --- a/python_snoo/snoo.py +++ b/python_snoo/snoo.py @@ -15,11 +15,12 @@ from .containers import ( AuthorizationInfo, + BabyData, SnooData, SnooDevice, SnooStates, ) -from .exceptions import InvalidSnooAuth, SnooAuthException, SnooCommandException, SnooDeviceError +from .exceptions import InvalidSnooAuth, SnooAuthException, SnooBabyError, SnooCommandException, SnooDeviceError from .pubnub_async import SnooPubNub _LOGGER = logging.getLogger(__name__) @@ -34,7 +35,7 @@ def __init__(self, email: str, password: str, clientsession: aiohttp.ClientSessi self.snoo_auth_url = "https://api-us-east-1-prod.happiestbaby.com/us/me/v10/pubnub/authorize" self.snoo_devices_url = "https://api-us-east-1-prod.happiestbaby.com/hds/me/v11/devices" self.snoo_data_url = "https://happiestbaby.pubnubapi.com" - self.snoo_baby_url = "https://api-us-east-1-prod.happiestbaby.com/us/me/v10/babies/" + self.snoo_baby_url = "https://api-us-east-1-prod.happiestbaby.com/us/me/v10/babies" self.aws_auth_hdr = { "x-amz-target": "AWSCognitoIdentityProviderService.InitiateAuth", "accept-language": "US", @@ -326,6 +327,16 @@ async def get_devices(self) -> list[SnooDevice]: devs = [SnooDevice.from_dict(dev) for dev in resp["snoo"]] return devs + async def get_babies(self) -> list[BabyData]: + hdrs = self.generate_snoo_auth_headers(self.tokens.aws_id) + try: + r = await self.session.get(self.snoo_baby_url, headers=hdrs) + resp = await r.json() + except Exception as ex: + raise SnooBabyError from ex + babies = [BabyData.from_dict(baby) for baby in resp] + return babies + def start_subscribe(self, device: SnooDevice, function: Callable): if device.serialNumber in self._mqtt_tasks and not self._mqtt_tasks[device.serialNumber].done(): _LOGGER.warning(f"Subscription task for device {device.serialNumber} is already running.")