Skip to content

Commit

Permalink
Remove PyBluez dependency, use Python socket instead
Browse files Browse the repository at this point in the history
  • Loading branch information
mathoudebine committed Sep 16, 2022
1 parent eae9957 commit b4c490b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ If you try to control another Divoom device, the connection to the first device

## Requirements
### Bluetooth Hardware
This component uses PyBluez library for Bluetooth communication. PyBluez is based on BlueZ official Linux Bluetooth stack.
This component uses Python sockets for Bluetooth communication.

Any Bluetooth hardware supported by your operating system should work. The Bluetooth interface built in to the Raspberry Pi 3 probably works, but hasn't yet been tested.
Any Bluetooth hardware supported by your operating system should work. The Bluetooth interface built in to the Raspberry Pi 3 probably works, but hasn't been tested yet.

To check if your Bluetooth hardware is supported, run the following command on your system:
```bash
Expand All @@ -57,9 +57,6 @@ Your Bluetooth interface should be listed as "hciX". If you have more than one,
### Home Assistant installation
Any Home assistant installation should be supported: OS, Container, Core, Supervised.

**Notes for Home Assistant Core Installations**: This platform requires pybluez to be installed. On Debian based installs, run
`sudo apt install bluetooth libbluetooth-dev python3-bluez`

If you run Home Assistant in a virtual machine, you have to connect your computer Bluetooth hardware to the VM:
- On VMWare: VM > Removable devices > (Your Bluetooth device i.e. Intel Wireless Bluetooth) > Connect
- On VirtualBox: Devices > USB devices > (Your Bluetooth device i.e. Intel Wireless Bluetooth)
Expand Down
5 changes: 2 additions & 3 deletions custom_components/timebox_mini/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from homeassistant.util import slugify
from itertools import product
from .timebox import Timebox
import bluetooth
import datetime
import logging
import math
Expand Down Expand Up @@ -250,8 +249,8 @@ def handle_action(call):
dev = Timebox(mac)
dev.connect()
_LOGGER.debug('Connected to %s' % mac)
except bluetooth.BluetoothError as be:
_LOGGER.error('Error connecting to %s : %s' % (mac, be))
except Exception as e:
_LOGGER.error('Error connecting to %s : %s' % (mac, e))
return

c = color_convert(Color("white").get_rgb())
Expand Down
5 changes: 2 additions & 3 deletions custom_components/timebox_mini/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"domain": "timebox_mini",
"name": "Timebox Mini",
"version": "1.0.1",
"version": "1.0.2",
"documentation": "https://github.com/mathoudebine/homeassistant-timebox-mini",
"issue_tracker": "https://github.com/mathoudebine/homeassistant-timebox-mini/issues",
"requirements": [
"colour",
"pillow",
"python-dateutil",
"pybluez"
"python-dateutil"
],
"dependencies": [],
"codeowners": [
Expand Down
8 changes: 5 additions & 3 deletions custom_components/timebox_mini/timebox.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import bluetooth
import logging
import socket

_LOGGER = logging.getLogger(__name__)

BTPROTO_RFCOMM = 3

class Timebox:
debug = False

def __init__(self, target):
if (isinstance(target, bluetooth.BluetoothSocket)):
if isinstance(target, socket.socket):
self.sock = target
self.addr, _ = self.sock.getpeername()
else:
self.sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
self.sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, BTPROTO_RFCOMM)
self.addr = target
self.sock.connect((self.addr, 4))

Expand Down

0 comments on commit b4c490b

Please sign in to comment.