Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pygatt: use handle in place of uuid #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions trionesControl/trionesControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import pygatt.exceptions

MAIN_CHARACTERISTIC_UUID = "0000ffd9-0000-1000-8000-00805f9b34fb"
MAIN_CHARACTERISTIC_HANDLE = 0x0007

log = logging.getLogger(__name__)

Expand All @@ -24,15 +24,15 @@ def connect(MAC, reset_on_start=True):
adapter.start(reset_on_start=reset_on_start)
device = adapter.connect(MAC)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
raise pygatt.exceptions.NotConnectedError("Device not connected!")
log.info("Device connected")
return device

def disconnect(device):
try:
device.disconnect()
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
raise pygatt.exceptions.NotConnectedError("Device not connected!")
log.info("Device disconnected")

def powerOn(device, wait_for_response=False):
Expand All @@ -43,9 +43,9 @@ def powerOn(device, wait_for_response=False):
"""

try:
device.char_write(MAIN_CHARACTERISTIC_UUID, b'\xcc\x23\x33', wait_for_response=wait_for_response)
device.char_write_handle(MAIN_CHARACTERISTIC_HANDLE, b'\xcc\x23\x33', wait_for_response=wait_for_response)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
raise pygatt.exceptions.NotConnectedError("Device not connected!")
log.info("Device powered on")

def powerOff(device, wait_for_response=False):
Expand All @@ -56,9 +56,9 @@ def powerOff(device, wait_for_response=False):
"""

try:
device.char_write(MAIN_CHARACTERISTIC_UUID, b'\xcc\x24\x33', wait_for_response=wait_for_response)
device.char_write_handle(MAIN_CHARACTERISTIC_HANDLE, b'\xcc\x24\x33', wait_for_response=wait_for_response)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
raise pygatt.exceptions.NotConnectedError("Device not connected!")
log.info("Device powered off")

def setRGB(r: int, g: int, b: int, device, wait_for_response=False):
Expand All @@ -84,9 +84,9 @@ def setRGB(r: int, g: int, b: int, device, wait_for_response=False):
payload.append(0xF0)
payload.append(0xAA)
try:
device.char_write(MAIN_CHARACTERISTIC_UUID, payload, wait_for_response=wait_for_response)
device.char_write_handle(MAIN_CHARACTERISTIC_HANDLE, payload, wait_for_response=wait_for_response)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
raise pygatt.exceptions.NotConnectedError("Device not connected!")
log.info("RGB set -- R: %d, G: %d, B: %d", r, g, b)

def setWhite(intensity: int, device, wait_for_response=False):
Expand All @@ -107,9 +107,9 @@ def setWhite(intensity: int, device, wait_for_response=False):
payload.append(0x0F)
payload.append(0xAA)
try:
device.char_write(MAIN_CHARACTERISTIC_UUID, payload, wait_for_response=wait_for_response)
device.char_write_handle(MAIN_CHARACTERISTIC_HANDLE, payload, wait_for_response=wait_for_response)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
raise pygatt.exceptions.NotConnectedError("Device not connected!")
log.info("White color set -- Intensity: %d", intensity)

def setBuiltIn(mode: int, speed: int, device, wait_for_response=False):
Expand All @@ -129,8 +129,8 @@ def setBuiltIn(mode: int, speed: int, device, wait_for_response=False):
payload.append(speed)
payload.append(0x44)
try:
device.char_write(MAIN_CHARACTERISTIC_UUID, payload, wait_for_response=wait_for_response)
device.char_write_handle(MAIN_CHARACTERISTIC_HANDLE, payload, wait_for_response=wait_for_response)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
raise pygatt.exceptions.NotConnectedError("Device not connected!")
log.info("Default mode %d set -- Speed %d", mode, speed)