From cf07952af5811e101db078e1b1d4f1c2b39959d8 Mon Sep 17 00:00:00 2001 From: Muhammad Fawwaz Orabi Date: Fri, 9 Jun 2023 22:43:02 +0000 Subject: [PATCH] Format take 2 --- custom_components/tuya_ble/translations/en.json | 3 +-- custom_components/tuya_ble/tuya_ble/__init__.py | 4 ++-- custom_components/tuya_ble/tuya_ble/manager.py | 11 ++++++++--- custom_components/tuya_ble/tuya_ble/tuya_ble.py | 11 ++++++++--- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/custom_components/tuya_ble/translations/en.json b/custom_components/tuya_ble/translations/en.json index 4fdedf43..3b6124a4 100644 --- a/custom_components/tuya_ble/translations/en.json +++ b/custom_components/tuya_ble/translations/en.json @@ -12,7 +12,7 @@ "step": { "device": { "data": { - "address": "Bluetooth address" + "address": "Tuya BLE device" }, "description": "Select Tuya BLE device to setup. Device must be registered in the cloud using the mobile application. It's better to unbind the device from Tuya Bluetooth gateway, if any." }, @@ -136,7 +136,6 @@ "invalid_auth": "Invalid authentication", "login_error": "Login error ({code}): {msg}" }, - "flow_title": "{name}", "step": { "login": { "data": { diff --git a/custom_components/tuya_ble/tuya_ble/__init__.py b/custom_components/tuya_ble/tuya_ble/__init__.py index 6ec09ab7..fb97169d 100644 --- a/custom_components/tuya_ble/tuya_ble/__init__.py +++ b/custom_components/tuya_ble/tuya_ble/__init__.py @@ -5,13 +5,13 @@ from .const import ( SERVICE_UUID, - TuyaBLEDataPointType, + TuyaBLEDataPointType, ) from .manager import ( AbstaractTuyaBLEDeviceManager, TuyaBLEDeviceCredentials, ) -from .tuya_ble import TuyaBLEDataPoint, TuyaBLEDevice +from .tuya_ble import TuyaBLEDataPoint, TuyaBLEDevice __all__ = [ "AbstaractTuyaBLEDeviceManager", diff --git a/custom_components/tuya_ble/tuya_ble/manager.py b/custom_components/tuya_ble/tuya_ble/manager.py index c25ca4dc..db6407b8 100644 --- a/custom_components/tuya_ble/tuya_ble/manager.py +++ b/custom_components/tuya_ble/tuya_ble/manager.py @@ -16,7 +16,7 @@ class TuyaBLEDeviceCredentials: product_name: str | None def __str__(self): - print("str called") + print('str called') return ( "uuid: xxxxxxxxxxxxxxxx, " "local_key: xxxxxxxxxxxxxxxx, " @@ -34,7 +34,6 @@ def __str__(self): self.product_name, ) - class AbstaractTuyaBLEDeviceManager(ABC): """Abstaract manager of the Tuya BLE devices credentials.""" @@ -60,7 +59,13 @@ def check_and_create_device_credentials( product_name: str | None, ) -> TuyaBLEDeviceCredentials | None: """Checks and creates credentials of the Tuya BLE device.""" - if uuid and local_key and device_id and category and product_id: + if ( + uuid and + local_key and + device_id and + category and + product_id + ): return TuyaBLEDeviceCredentials( uuid, local_key, diff --git a/custom_components/tuya_ble/tuya_ble/tuya_ble.py b/custom_components/tuya_ble/tuya_ble/tuya_ble.py index 0325d0fa..74a04beb 100644 --- a/custom_components/tuya_ble/tuya_ble/tuya_ble.py +++ b/custom_components/tuya_ble/tuya_ble/tuya_ble.py @@ -1223,7 +1223,7 @@ def _parse_input(self) -> None: def _notification_handler(self, _sender: int, data: bytearray) -> None: """Handle notification responses.""" - # _LOGGER.debug("%s: Packet received: %s", self.address, data.hex()) + _LOGGER.debug("%s: Packet received: %s", self.address, data.hex()) pos: int = 0 packet_num: int @@ -1275,8 +1275,11 @@ async def _send_datapoints_v3(self, datapoint_ids: list[int]) -> None: for dp_id in datapoint_ids: dp = self._datapoints[dp_id] value = dp._get_value() - data += pack(">BBB", dp.id, dp.type.value, len(value)) - data += value + print( + "{}: Sending datapoint update, id: {}, type: {}: value: {}".format( + self.address, dp.id, dp.type.name, dp.value + ) + ) _LOGGER.debug( "%s: Sending datapoint update, id: %s, type: %s: value: %s", self.address, @@ -1284,6 +1287,8 @@ async def _send_datapoints_v3(self, datapoint_ids: list[int]) -> None: dp.type.name, dp.value, ) + data += pack(">BBB", dp.id, int(dp.type.value), len(value)) + data += value await self._send_packet(TuyaBLECode.FUN_SENDER_DPS, data)