Skip to main content

Python library to control Hatch Baby Rest devices

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhatchbabyrest-2.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhatchbabyrest-2.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pyhatchbabyrest-2.1.0.tar.gz.

File metadata

  • Download URL: pyhatchbabyrest-2.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for pyhatchbabyrest-2.1.0.tar.gz
Algorithm Hash digest
SHA256 b5823648663dac22ea9a97bb7366c2afb449dbf9fa6c17772dc5f4d267bb72b0
MD5 da4caf61399e18cf7a1e1aaf1c356986
BLAKE2b-256 9711f5fd8ba8bab44f5a4ea884dc8d48a15dc5383de3ab4d0ac1b55d2b4e9794

See more details on using hashes here.

File details

Details for the file pyhatchbabyrest-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyhatchbabyrest-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc3c22a276b03d9c75c4754b9aad036525d1ef7fcb30a16560f6e45a82b9f3a6
MD5 fab99bdfaa34c07afae54a6c81d0ae2e
BLAKE2b-256 ee590d3051adce4cff3be71bf63c8018e0c725c57dd5a0a170ac814d00ec2fa4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page