Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vsternbach/yeelightble
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: vsternbach/yeelightble
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 4 commits
  • 6 files changed
  • 2 contributors

Commits on Nov 1, 2023

  1. fix update state

    vladsternbach committed Nov 1, 2023
    Copy the full SHA
    1207f7b View commit details

Commits on Nov 5, 2023

  1. docs: Update README.md

    vsternbach authored Nov 5, 2023
    Copy the full SHA
    beeca0a View commit details
  2. fix: fix install

    vladsternbach committed Nov 5, 2023
    Copy the full SHA
    4a9d615 View commit details
  3. Merge branch 'test'

    vladsternbach committed Nov 5, 2023
    Copy the full SHA
    9b3aa4d View commit details
Showing with 27 additions and 23 deletions.
  1. +8 −3 README.md
  2. +0 −3 yeelightble/__init__.py
  3. +2 −2 yeelightble/cli.py
  4. +0 −1 yeelightble/lamp.py
  5. +16 −13 yeelightble/server.py
  6. +1 −1 yeelightble/version.py
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -17,16 +17,21 @@ Currently supported features (Candelas support only On/Off and Brightness):
```
sudo pip3 install git+https://github.com/vsternbach/yeelightble
```
In case you are getting "No such file or directory" error for bluepy-helper, you have to go into bluepy's directory and run make there.
It is also a good idea to let the helper have the capabilities for accessing the bluetooth devices without being root, e.g., by doing the following:
Check that it's working correctly by running scan:
```
yeelightble scan -t 1
```
If you're getting an error you need to let the helper have the capabilities for accessing the bluetooth devices without being root by running the following:
```
sudo setcap 'cap_net_raw,cap_net_admin+eip' bluepy-helper
```
if you get: `Failed to set capabilities on file 'bluepy-helper' (No such file or directory)`, provide the full path to `bluepy-helper`, for example on RPI:
```
sudo setcap 'cap_net_raw,cap_net_admin+eip' /usr/local/lib/python3.7/dist-packages/bluepy/bluepy-helper
```
And then simply try if the scanning works. You can use pass '-dd' as option to the command to see the debug messages from bluepy in case it is not working.
And then try again if the scanning works.

If you intend to use it with [homebridge-yeelight-ble](https://github.com/vsternbach/homebridge-yeelight-ble) you need to install it as a systemd service daemon, see [below](#service-daemon)

## Service daemon
Running this script will install, enable and run `yeelightble` as a systemd service:
3 changes: 0 additions & 3 deletions yeelightble/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
# flake8: noqa
from .lamp import Lamp
from .structures import LampMode
4 changes: 2 additions & 2 deletions yeelightble/cli.py
Original file line number Diff line number Diff line change
@@ -41,8 +41,8 @@ def cli(ctx, mac, debug):
def daemon(host, port):
"""Runs yeelightble as a daemon"""
logger.info(f'Starting yeelightble service daemon v{__version__}')
server = Server(host=host, port=port)
asyncio.run(server.start())
server = Server()
asyncio.run(server.start(host=host, port=port))


@cli.command()
1 change: 0 additions & 1 deletion yeelightble/lamp.py
Original file line number Diff line number Diff line change
@@ -70,7 +70,6 @@ def __init__(self, mac, status_cb=state_cb, paired_cb=pair_cb, keep_connection=T
def connect(self):
logger.debug('connect')
self._dev.connect()
# self.pair()
# self._dev.write_characteristic(self.REGISTER_NOTIFY_HANDLE, struct.pack("<BB", 0x01, 0x00))

def disconnect(self):
29 changes: 16 additions & 13 deletions yeelightble/server.py
Original file line number Diff line number Diff line change
@@ -17,22 +17,21 @@ class Command:


class Server:
def __init__(self, host: str, port: int):
self.host = host
self.port = port
self.ws = None
def __init__(self):
self._lamps = {}
self.ws = None
self.server = None

async def start(self):
async def start(self, host: str, port: int):
signal.signal(signal.SIGINT, self.stop)
signal.signal(signal.SIGTERM, self.stop)
async with websockets.serve(self.handle_message, self.host, self.port):
await asyncio.Future()
self.server = await websockets.serve(self.handle_message, host, port)
await self.server.wait_closed()

def stop(self, signum, frame):
logger.info(f"Received {signum} signal. Cleaning up and exiting gracefully.")
self.ws = None
asyncio.get_event_loop().stop()
logger.info(f"Received {signum} signal")
if self.server:
self.server.close()

async def handle_message(self, websocket):
self.ws = websocket
@@ -70,11 +69,15 @@ def process_command(self, uuid, command: Command, payload=None):
logger.warning(f"Unsupported command: {command}")
return

async def send_state(self, uuid, lamp: Lamp):
def send_state(self, uuid, lamp: Lamp):
logger.debug("Received notification from %s" % uuid)
message = json.dumps({"uuid": uuid, "state": lamp.state})
asyncio.get_event_loop().create_task(self.send_message(message))

async def send_message(self, message):
if self.ws:
logger.debug("Send ws message with state: %s" % (uuid, lamp.state))
await self.ws.send(json.dumps({"uuid": uuid, "state": lamp.state}))
logger.debug("Send ws message: %s" % message)
await self.ws.send(message)
else:
logger.warning("No open websocket")

2 changes: 1 addition & 1 deletion yeelightble/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.0"
__version__ = "2.0.2"