Skip to content

Repository files navigation

python-toothbrush

stability-wipCode style: black

python-toothbrush is a package that provides a simple interface to connect to electric toothbrushes via Bluetooth.

Help Wanted

Any help is appreciated. I'd love to see support for more toothbrushes in the future!

How to add another toothbrush?

The package assumes that a toothbrush has certain attributes (like routine, intensity, etc.). These attributes are read via Bluetooth from the toothbrush. The toothbrush exposes these attributes in form of certain characteristics. Characteristics can be read via a certain handle (or address).

The package is trying to take care of the communication with the toothbrush, so you can focus on providing the correct handles:

fromtoothbrush.baseimportToothbrushfromtoothbrush.constantsimportROUTINE, INTENSITYclassFancyToothbrush(Toothbrush):
attributes= [ROUTINE, INTENSITY] # defines which attributes are availablehandles= { # defines under which handle the attributes can be readINTENSITY: 0x11,
ROUTINE: 0x12
}

That's pretty much it. Let's test the implementation!

>>>fromtoothbrush.fancyimportFancyToothbrush>>>fancy=FancyToothbrush("00:11:22:33:44:55")
>>>fancy.show_attributes()
routine: b'\x01'intensity: b'\x01'

You may have noticed the output of the attribute values is not human readable. So let's change that! Just add a parse_{attribute} method for every attribute you'd like to parse.

importbinasciifromtoothbrush.baseimportToothbrushfromtoothbrush.constantsimportROUTINE, INTENSITYclassFancyToothbrush(Toothbrush):
attributes= [ROUTINE, INTENSITY] # defines which attributes are availablehandles= { # defines under which handle the attributes can be readINTENSITY: 0x11,
ROUTINE: 0x12
}
ROUTINE_MAP= {
0: "simple",
1: "gum",
2: "deep clean"
}
defparse_intensity(self, raw_data):
returnint(binascii.hexlify(raw_data))
defparse_routine(self, raw_data):
returnself.ROUTINE_MAP[int(binascii.hexlify(raw_data))]
>>>fromtoothbrush.fancyimportFancyToothbrush>>>fancy=FancyToothbrush("00:11:22:33:44:55")
>>>fancy.show_attributes()
routine: 'simple'intensity: 1

That's it!

Todos

  • CLI capabilities for better debugging
  • JSON / XML output for toothbrush

Supported toothbrushes

About

python package to read data from bluetooth toothbrushes

Topics

Resources

Stars

8 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages