Skip to content

Commit

Permalink
Replace writes to handle with writes to UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
mtttz committed Apr 8, 2021
1 parent eacce0b commit 8bc4e00
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions trionesControl/trionesControl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import pygatt
import logging
import pygatt.exceptions

MAIN_CHARACTERISTIC_UUID = "0000ffd9-0000-1000-8000-00805f9b34fb"

log = logging.getLogger(__name__)
def connect(MAC):
try:
Expand All @@ -20,14 +23,14 @@ def disconnect(device):
log.info("Device disconnected")
def powerOn(device):
try:
device.char_write_handle(0x0009, b'\xcc\x23\x33')
device.char_write(MAIN_CHARACTERISTIC_UUID, b'\xcc\x23\x33')
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
log.info("Device powered on")

def powerOff(device):
try:
device.char_write_handle(0x0009, b'\xcc\x24\x33')
device.char_write(MAIN_CHARACTERISTIC_UUID, b'\xcc\x24\x33')
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
log.info("Device powered off")
Expand All @@ -50,7 +53,7 @@ def setRGB(r: int, g: int, b: int, device):
payload.append(0xF0)
payload.append(0xAA)
try:
device.char_write_handle(0x0009, payload)
device.char_write(MAIN_CHARACTERISTIC_UUID, payload)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
log.info("RGB set -- R: %d, G: %d, B: %d", r, g, b)
Expand All @@ -68,7 +71,7 @@ def setWhite(intensity: int, device):
payload.append(0x0F)
payload.append(0xAA)
try:
device.char_write_handle(0x0009, payload)
device.char_write(MAIN_CHARACTERISTIC_UUID, payload)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
log.info("White color set -- Intensity: %d", intensity)
Expand All @@ -84,7 +87,7 @@ def setBuiltIn(mode: int, speed: int, device):
payload.append(speed)
payload.append(0x44)
try:
device.char_write_handle(0x0009, payload)
device.char_write(MAIN_CHARACTERISTIC_UUID, payload)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
log.info("Default mode %d set -- Speed %d", mode, speed)
Expand Down

0 comments on commit 8bc4e00

Please sign in to comment.