From aac4160ec7d6ce0ba0af121ae17398f1cc7978d4 Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Sun, 2 Jan 2022 19:29:06 +0100 Subject: [PATCH 1/2] use handle in place of uuid --- trionesControl/trionesControl.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/trionesControl/trionesControl.py b/trionesControl/trionesControl.py index 200518d..b9e0626 100644 --- a/trionesControl/trionesControl.py +++ b/trionesControl/trionesControl.py @@ -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__) @@ -43,7 +43,7 @@ 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!") log.info("Device powered on") @@ -56,7 +56,7 @@ 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!") log.info("Device powered off") @@ -84,7 +84,7 @@ 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!") log.info("RGB set -- R: %d, G: %d, B: %d", r, g, b) @@ -107,7 +107,7 @@ 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!") log.info("White color set -- Intensity: %d", intensity) @@ -129,7 +129,7 @@ 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!") log.info("Default mode %d set -- Speed %d", mode, speed) From ef1c12981f91c927055bf895e3caab67019acd23 Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Sun, 2 Jan 2022 19:29:31 +0100 Subject: [PATCH 2/2] fix typo --- trionesControl/trionesControl.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/trionesControl/trionesControl.py b/trionesControl/trionesControl.py index b9e0626..fd5510b 100644 --- a/trionesControl/trionesControl.py +++ b/trionesControl/trionesControl.py @@ -24,7 +24,7 @@ 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 @@ -32,7 +32,7 @@ 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): @@ -45,7 +45,7 @@ def powerOn(device, wait_for_response=False): try: 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): @@ -58,7 +58,7 @@ def powerOff(device, wait_for_response=False): try: 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): @@ -86,7 +86,7 @@ def setRGB(r: int, g: int, b: int, device, wait_for_response=False): try: 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): @@ -109,7 +109,7 @@ def setWhite(intensity: int, device, wait_for_response=False): try: 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): @@ -131,6 +131,6 @@ def setBuiltIn(mode: int, speed: int, device, wait_for_response=False): try: 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)