Skip to content

Commit

Permalink
Merge pull request #31 from forabi/format-2
Browse files Browse the repository at this point in the history
Format code take 2
  • Loading branch information
PlusPlus-ua authored Jun 12, 2023
2 parents c8b94fb + cf07952 commit d84d24c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
3 changes: 1 addition & 2 deletions custom_components/tuya_ble/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
},
Expand Down Expand Up @@ -136,7 +136,6 @@
"invalid_auth": "Invalid authentication",
"login_error": "Login error ({code}): {msg}"
},
"flow_title": "{name}",
"step": {
"login": {
"data": {
Expand Down
4 changes: 2 additions & 2 deletions custom_components/tuya_ble/tuya_ble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_ble/tuya_ble/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand All @@ -34,7 +34,6 @@ def __str__(self):
self.product_name,
)


class AbstaractTuyaBLEDeviceManager(ABC):
"""Abstaract manager of the Tuya BLE devices credentials."""

Expand All @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_ble/tuya_ble/tuya_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1275,15 +1275,20 @@ 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,
dp.id,
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)

Expand Down

0 comments on commit d84d24c

Please sign in to comment.