Python library to control Hatch Baby Rest devices
Hatch Baby Rest Python Bindings
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.
pip install pyhatchbabyrest
pygatt backend (synchronous)
In : from pyhatchbabyrest import PyHatchBabyRest In : rest = PyHatchBabyRest() In : rest.power Out: False In : rest.power_on() In : rest.volume Out: 30 In : rest.set_volume(10) In : rest.volume Out: 10 In : rest.set_color(255, 0, 0) In : rest.color Out: (255, 0, 0) In : rest.set_brightness(100) In : rest.set_sound(PyHatchBabyRestSound.stream) In : rest.sound Out: <PyHatchBabyRestSound.stream: 2> In : rest.set_color(*PyHatchBabyRest.COLOR_GRADIENT) In : rest.connected Out: True In : rest.disconnect() In : rest.connected Out: False
bleak backend (async and a little more portable)
In : from pyhatchbabyrest import PyHatchBabyRestAsync In : rest = PyHatchBabyRestAsync() In : import asyncio In : loop = asyncio.get_event_loop() In : r = loop.run_until_complete In : r(rest.power_on()) In : r(rest.set_volume(100)) In : r(rest.set_volume(10)) In : r(rest.power_off()) In : rest.sound Out: <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())
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.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for pyhatchbabyrest-2.1.0-py3-none-any.whl