Skip to main content

Hatch Baby Rest Python Bindings

This library will allow you to control a Hatch Baby Rest device (note, /not/ the Hatch Baby Rest+, which is Wi-Fi enabled) over BLE.

Requirements

The pygatt backend was tested on a Raspberry Pi 3 Model B Rev 1.2, but should work on any Unix system that is compatible with the GATTToolBackend of pygatt.

The bleak (async) backend was tested on a 2019 MacBook Pro, but should work on any system that bleak is compatible with.

Installation

pip install pyhatchbabyrest

Examples

pygatt backend (synchronous)

In [1]: from pyhatchbabyrest import PyHatchBabyRest

In [2]: rest = PyHatchBabyRest()

In [3]: rest.power
Out[3]: False

In [4]: rest.power_on()

In [5]: rest.volume
Out[5]: 30

In [6]: rest.set_volume(10)

In [7]: rest.volume
Out[7]: 10

In [8]: rest.set_color(255, 0, 0)

In [9]: rest.color
Out[9]: (255, 0, 0)

In [10]: rest.set_brightness(100)

In [11]: rest.set_sound(PyHatchBabyRestSound.stream)

In [12]: rest.sound
Out[12]: <PyHatchBabyRestSound.stream: 2>

In [13]: rest.set_color(*PyHatchBabyRest.COLOR_GRADIENT)
    
In [14]: rest.connected
Out[14]: True

In [15]: rest.disconnect()

In [16]: rest.connected
Out[16]: False

bleak backend (async and a little more portable)

In [1]: from pyhatchbabyrest import PyHatchBabyRestAsync

In [2]: rest = PyHatchBabyRestAsync()

In [3]: import asyncio

In [4]: loop = asyncio.get_event_loop()

In [5]: r = loop.run_until_complete

In [6]: r(rest.power_on())

In [7]: r(rest.set_volume(100))

In [8]: r(rest.set_volume(10))

In [9]: r(rest.power_off())

In [10]: rest.sound
Out[10]: <PyHatchBabyRestSound.noise: 3>

NOTE: Using PyHatchBabyRestAsync from async code

The constructor, by default, executes directly against the event loop. This doesn't work if it is executed within an already running coroutine. To construct the client, all async calls must be done outside of the constructor.

This has been all wrapped up in a function for ease of use.

import asyncio

from pyhatchbabyrest import connect_async


async def main():
    rest = await connect_async()
    await rest.power_on()


rest = asyncio.run(main())

Credits

Huge thanks to @Marcus-L for their repo at GitHub - Marcus-L/m4rcus.HatchBaby.Rest: Control Hatch Baby Rest devices using Bluetooth LE which did all the hard work of finding the right characteristics, commands, etc.

Metadata

Release files for pyhatchbabyrest-hass 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyhatchbabyrest-hass 2.3.0
File Size Uploaded
pyhatchbabyrest-hass-2.3.0.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyhatchbabyrest-hass 2.3.0
File Interpreter ABI Platform
pyhatchbabyrest_hass-2.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.1 kB

Release files / pyhatchbabyrest-hass-2.3.0.tar.gz

Download URL pyhatchbabyrest-hass-2.3.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3ad985433c0bd214c4e55a52f0fd110d3650b27095045d64961409f52f725376
BLAKE2b-256 checksum
How to use checksums
4c98dd19e16fbdd6017917ed0284badb492c8606183e7fb30faadb1b151cd79e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / pyhatchbabyrest_hass-2.3.0-py3-none-any.whl

Download URL pyhatchbabyrest_hass-2.3.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ad9df473640aaddb8c0f6aae460280e0b14e6729ce0697a7b8e12fb8ebba6b3
BLAKE2b-256 checksum
How to use checksums
5ab5d5fa1665632f2025ab4f1fd7e346c810e478e8da2a520e73f669127ca564
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

2.3.0 This release

2 release files

2.2.0

2 release files

2.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page