Python package for controlling Snoo Smart Sleepers from happiestbaby.com
Project description
Introduction
This is a Python 3.8+ module aiming to interact with the Snoo Smart Sleeper from happiestbaby.com API.
Homeassistant
Homeassistant has a custom Snoo component leveraging this package. This can be added into HACS as a custom repository.
Getting Started
Installation
pip install pysnoo
Usage
pysnoo
starts within an aiohttp
ClientSession
:
import asyncio
from aiohttp import ClientSession
async def main() -> None:
"""Create the aiohttp session and run."""
async with ClientSession() as websession:
# YOUR CODE HERE
asyncio.get_event_loop().run_until_complete(main())
To get all Snoo devices associated with an account:
import asyncio
from aiohttp import ClientSession
import pysnooapi
async def main() -> None:
"""Create the aiohttp session and run."""
async with ClientSession() as websession:
snoo = await pysnoo.login('<EMAIL>', '<PASSWORD>', websession)
# Returns snoo devices
devices = snoo.devices
# >>> {"serial_number123": <Device>, "serial_number456": <Device>}
asyncio.get_event_loop().run_until_complete(main())
API Methods
These are coroutines and need to be await
ed – see example.py
for examples.
login
: Login method that authenticates user and also updates device informationauthenticate
: Authenticate (or re-authenticate) to Snoo. Call this to re-authenticate immediately after changing username and/or password otherwise new username/password will only be used when token has to be refreshed.get_account
: Retrieve account detailsupdate_device_info
: Retrieve info and status for devices including account, baby, config and sessionget_session_for_account
: Retrieve session details for the account. Oddly, this is not linked to a device.get_configs_for_device
: Retrieve config details for the devicesget_baby_for_account
: Retrieve baby details associated with the accountget_session_stats_avg_for_account
: Retrieve aggregated session stats for the weekget_session_stats_daily_for_account
: Retrieve aggregated session stats for the given date
Device Methods
All of the routines on the SnooDevice
class are coroutines and need to be
await
ed – see example.py
for examples.
update
: get the latest device info (state, etc.). Note that this runs api.update_device_info and thus all accounts/devices will be updated
API Properties
account
: dictionary with the accountdevices
: dictionary with all deviceslast_state_update
: datetime (in UTC) last state update was retrievedpassword
: password used for authentication. Can only be set, not retrievedusername
: username for authentication.
Account Properties
userId
: User ID for the accountemail
: Email for the accountgivenName
: Name for the accountsurname
: Last name for the accountregion
: Region for the account
Example
{
"email": "abc@xyz.com",
"givenName": "ABC",
"surname": "XYZ",
"userId": "afdgjfhdsgsg",
"region": "US"
}
Session Properties
startTime
: datetime when the current or last session startedendTime
: datetime when the last session ended or None if current session is activelevels
: sequence of levels in current session sorted by time. (Last level is the latest)
Example
{
"startTime": "2021-02-01T01:02:34.456Z",
"endTime": "2021-02-01T04:02:34.456Z",
"levels": [
{
"level": "BASELINE"
},
{
"level": "LEVEL1"
},
{
"level": "BASELINE"
},
{
"level": "ONLINE"
}
]
}
Config Properties
Example
{
"config": "lvl0",
"premieLock": false,
"weaning": false,
"whiteNoiseLevel": "lvl-1",
"motionLimiter": false,
"minimalLevel": "baseline",
"networkStatus": {
"lastPresence": "2021-01-01T11:02:35.160Z",
"lastProvisionSuccess": "2021-01-01T23:45:49.752Z",
"lastSSID": {
"name": "ABC",
"updatedAt": "2021-01-01T06:56:18.364Z"
},
"isOnline": true
}
}
Baby Properties
Example
{
"settings": {
"responsivenessLevel": "lvl0",
"minimalLevelVolume": "lvl-1",
"soothingLevelVolume": "lvl0",
"minimalLevel": "baseline",
"motionLimiter": false,
"weaning": false,
"carRideMode": true,
"offlineLock": false,
"daytimeStart": 8
},
"disabledLimiter": false,
"_id": "asfkhdsgfjsdkhkjdsg",
"pictures": [
{
"id": "sdfsdgkjhihr3r324_dsfh34tjh5kth5k",
"mime": "image/png",
"encoded": false,
"updatedAt": "2020-02-13T01:36:14.717Z"
}
],
"createdAt": "2020-02-12T01:12:12.123Z",
"updatedAt": "2020-02-12T01:12:12.123Z",
"babyName": "Baby",
"birthDate": "2020-02-12T01:12:12.123Z",
"sex": "Female",
"updatedByUserAt": "2020-02-12T01:12:12.123Z"
}
Device Properties
account
: Return account associated with devicedevice_id
: Return the device ID (serial number)device
: Return the device detailsfirmware_version
: Return the family in which this device livesname
: Return the device nameis_online
: Return whether the device is onlineis_on
: Return whether the device is on (in motion)state
: Return the current state of the device (ONLINE, WEANING_BASELINE, BASELINE, LEVEL1, LEVEL2, LEVEL3 and LEVEL4)baby
: Return the baby detailssession
: Return the session detailsconfig
: Return the config detailslast_update
: Returns datetime when the device was last updated
Device Details
The device details from device properties
Example
{
"serialNumber": "243545643656",
"createdAt": "2020-01-02T18:01:42.124Z",
"updatedAt": "2021-02-01T11:00:12.123Z",
"baby": "krgh2354543jhg6jh5gj",
"lastProvisionSuccess": "2020-12-01T01:45:49.752Z",
"firmwareUpdateDate": "2021-01-01T20:53:49.782Z",
"firmwareVersion": "v1.14.12",
"lastSSID": {
"name": "ABC",
"updatedAt": "2020-01-03T06:56:18.364Z"
},
"timezone": "America/Los_Angeles"
}
Session Stats Properties
Daily Session Aggregates
Example
{
"levels": [
{
"sessionId": "1654751546",
"type": "asleep",
"startTime": "2021-01-31 08:00:00.000",
"stateDuration": 1279,
"isActive": false
},
{
"sessionId": "1681977280",
"type": "asleep",
"startTime": "2021-01-31 08:33:43.084",
"stateDuration": 63,
"isActive": false
},
...
],
"detailedLevels": [
{
"sessionId": "1654751546",
"level": "BASELINE",
"hold": false,
"settings": {
"responsivenessLevel": "lvl0",
"minimalLevelVolume": "lvl-1",
"soothingLevelVolume": "lvl0",
"minimalLevel": "baseline",
"motionLimiter": false,
"weaning": false,
"carRideMode": false
},
"isActive": false,
"levelDetails": {
"start": "2021-01-31 06:57:20.894",
"duration": 5038
},
"sessionDetails": {
"start": "2021-01-31 06:57:20.894",
"duration": 5038
},
"type": "asleep",
"startTime": "2021-01-31 08:00:00.000",
"stateDuration": 1279
},
...
],
"naps": 2,
"longestSleep": 10032,
"totalSleep": 18096,
"daySleep": 3434,
"nightSleep": 14662,
"nightWakings": 4,
"timezone": null
}
Weekly Session Aggregate
Example
{
"totalSleepAVG": 18670,
"daySleepAVG": 3268,
"nightSleepAVG": 16802,
"longestSleepAVG": 9497,
"nightWakingsAVG": 6.286,
"days": {
"totalSleep": [
18096,
19966,
29070,
15408,
18880,
17171,
12096
],
"daySleep": [
3434,
2012,
5463,
2161,
0,
0,
0
],
"nightSleep": [
14662,
17954,
23607,
13247,
18880,
17171,
12096
],
"longestSleep": [
10032,
10932,
11028,
9954,
8717,
8979,
6837
],
"nightWakings": [
4,
7,
4,
7,
6,
7,
9
]
}
}
Acknowledgement
The structure of this project is inspired by pymyq
Disclaimer
The code here is based off of an unsupported API from happiestbaby.com and is subject to change without notice. The authors claim no responsibility for damages to your garage door or property by use of the code within.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pysnooapi-0.0.3.tar.gz
.
File metadata
- Download URL: pysnooapi-0.0.3.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1a52f58af9ae658fb614b2b767ad0bc93fa518d093a256615a6abaa87d426e6 |
|
MD5 | 55559ee7425c32caf1e759e2b5eff455 |
|
BLAKE2b-256 | 6f4bb7a8422eda3df906553a91d41c2da235ef549e1086619a18ea52f206f239 |
File details
Details for the file pysnooapi-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: pysnooapi-0.0.3-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78c61bb0a97236cff420e22c5bae8015c4b64ea4912a382b395e2cbe3e71107c |
|
MD5 | ecbc6aaddb30b28028d09d12bafb0e05 |
|
BLAKE2b-256 | 02a52077ae368ecada5d3136a518fe2b88803d56953f5b5e5af4d11a6562c820 |