Skip to content

Commit f96667f

Browse files
authored
feat: add get_babies function (#45)
* Added get_babies function * Fixed linting
1 parent 6915a93 commit f96667f

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

python_snoo/containers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ class BabySettings(DataClassJSONMixin):
150150
class BabyData(DataClassJSONMixin):
151151
_id: str
152152
babyName: str
153-
birthDate: str
154153
breathSettingHistory: list
155154
createdAt: str
156155
disabledLimiter: bool
157-
expectedBirthDate: str
158156
pictures: list
159157
settings: BabySettings
160158
sex: str
161159
preemie: Any | None = None # Not sure what datatype this is yet & may not be supplied - boolean?
160+
birthDate: str | None = None
161+
expectedBirthDate: str | None = None
162162
startedUsingSnooAt: str | None = None
163163
updatedAt: str | None = None
164164

python_snoo/snoo.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
from .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
2324
from .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

Comments
 (0)