Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python_snoo/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 13 additions & 2 deletions python_snoo/snoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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",
Expand Down Expand Up @@ -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.")
Expand Down
Loading