Add worker for Oral-B connected toothbrush (#55)
* create toothbrush.py add oral-b connected toothbrushs (based on https://github.com/rfaelens/domotica/blob/master/mqtt-toothbrush.py, see https://community.home-assistant.io/t/oral-b-bluetooth-connected-toothbrush/) * add configuration example for oral-b toothbrush * Update README.md
This commit is contained in:
@@ -22,6 +22,7 @@ See [Wiki](https://github.com/zewelor/bt-mqtt-gateway/wiki) for more information
|
|||||||
* [Xiaomi Mi Flora plant sensor](https://xiaomi-mi.com/sockets-and-sensors/xiaomi-huahuacaocao-flower-care-smart-monitor/) via [miflora](https://github.com/open-homeautomation/miflora)
|
* [Xiaomi Mi Flora plant sensor](https://xiaomi-mi.com/sockets-and-sensors/xiaomi-huahuacaocao-flower-care-smart-monitor/) via [miflora](https://github.com/open-homeautomation/miflora)
|
||||||
* Xiaomi Aqara thermometer via [mithermometer](https://github.com/hobbypunk90/mithermometer)
|
* Xiaomi Aqara thermometer via [mithermometer](https://github.com/hobbypunk90/mithermometer)
|
||||||
* Bluetooth Low Power devices (BLE)
|
* Bluetooth Low Power devices (BLE)
|
||||||
|
* Oral-B connected toothbrushs
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
|
|||||||
@@ -55,3 +55,10 @@ manager:
|
|||||||
smartwath: 00:11:22:33:44:55
|
smartwath: 00:11:22:33:44:55
|
||||||
topic_prefix: blescan
|
topic_prefix: blescan
|
||||||
update_interval: 60
|
update_interval: 60
|
||||||
|
toothbrush:
|
||||||
|
args:
|
||||||
|
devices:
|
||||||
|
ix: 00:11:22:33:44:55
|
||||||
|
ia: 11:22:33:44:55:66
|
||||||
|
topic_prefix: toothbrush
|
||||||
|
update_interval: 10
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import time
|
||||||
|
from interruptingcow import timeout
|
||||||
|
from bluepy.btle import Scanner, DefaultDelegate
|
||||||
|
from mqtt import MqttMessage
|
||||||
|
from workers.base import BaseWorker
|
||||||
|
from logger import _LOGGER
|
||||||
|
|
||||||
|
REQUIREMENTS = ['bluepy']
|
||||||
|
|
||||||
|
class ScanDelegate(DefaultDelegate):
|
||||||
|
def __init__(self):
|
||||||
|
DefaultDelegate.__init__(self)
|
||||||
|
|
||||||
|
def handleDiscovery(self, dev, isNewDev, isNewData):
|
||||||
|
if isNewDev:
|
||||||
|
_LOGGER.debug("Discovered new device: %s" % dev.addr)
|
||||||
|
|
||||||
|
class ToothbrushWorker(BaseWorker):
|
||||||
|
def searchmac(self, devices, mac):
|
||||||
|
for dev in devices:
|
||||||
|
if dev.addr == mac.lower():
|
||||||
|
return dev
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def status_update(self):
|
||||||
|
scanner = Scanner().withDelegate(ScanDelegate())
|
||||||
|
devices = scanner.scan(5.0)
|
||||||
|
ret = []
|
||||||
|
|
||||||
|
for name, mac in self.devices.items():
|
||||||
|
device = self.searchmac(devices, mac)
|
||||||
|
if device is None:
|
||||||
|
ret.append(MqttMessage(topic=self.format_topic(name+'/presence'), payload="0"))
|
||||||
|
else:
|
||||||
|
ret.append(MqttMessage(topic=self.format_topic(name+'/presence/rssi'), payload=device.rssi))
|
||||||
|
ret.append(MqttMessage(topic=self.format_topic(name+'/presence'), payload="1"))
|
||||||
|
_LOGGER.debug("text: %s" % device.getValueText(255) )
|
||||||
|
bytes_ = bytearray(bytes.fromhex(device.getValueText(255)))
|
||||||
|
ret.append(MqttMessage(topic=self.format_topic(name+'/running'), payload=bytes_[5] ))
|
||||||
|
ret.append(MqttMessage(topic=self.format_topic(name+'/pressure'), payload=bytes_[6] ))
|
||||||
|
ret.append(MqttMessage(topic=self.format_topic(name+'/time'), payload=bytes_[7]*60 + bytes_[8] ))
|
||||||
|
ret.append(MqttMessage(topic=self.format_topic(name+'/mode'), payload=bytes_[9] ))
|
||||||
|
ret.append(MqttMessage(topic=self.format_topic(name+'/quadrant'), payload=bytes_[10] ))
|
||||||
|
|
||||||
|
return ret
|
||||||
Reference in New Issue
Block a user