Browse Source

Reformat code and add test function for get_device_id

Nicolas 2 years ago
parent
commit
3606912ae4

+ 11 - 3
custom_components/tuya_local/device.py

@@ -24,7 +24,7 @@ from .const import (
     CONF_POLL_ONLY,
     CONF_PROTOCOL_VERSION,
     DOMAIN,
-    CONF_DEVICE_CID
+    CONF_DEVICE_CID,
 )
 from .helpers.config import get_device_id
 from .helpers.device_config import possible_matches
@@ -68,9 +68,17 @@ class TuyaLocalDevice(object):
         self._api_protocol_working = False
         try:
             if dev_cid is not None:
-                self._api = tinytuya.Device(dev_id, cid=dev_cid, parent=tinytuya.Device(dev_id, address, local_key, version=protocol_version))
+                self._api = tinytuya.Device(
+                    dev_id,
+                    cid=dev_cid,
+                    parent=tinytuya.Device(
+                        dev_id, address, local_key, version=protocol_version
+                    ),
+                )
             else:
-                self._api = tinytuya.Device(dev_id, address, local_key, version=protocol_version)
+                self._api = tinytuya.Device(
+                    dev_id, address, local_key, version=protocol_version
+                )
             self.dev_cid = dev_cid
         except Exception as e:
             _LOGGER.error(

+ 5 - 1
custom_components/tuya_local/helpers/config.py

@@ -46,4 +46,8 @@ async def async_tuya_setup_platform(
 
 
 def get_device_id(config: dict):
-    return config[CONF_DEVICE_CID] if CONF_DEVICE_CID in config and config[CONF_DEVICE_CID] != "" else config[CONF_DEVICE_ID]
+    return (
+        config[CONF_DEVICE_CID]
+        if CONF_DEVICE_CID in config and config[CONF_DEVICE_CID] != ""
+        else config[CONF_DEVICE_ID]
+    )

File diff suppressed because it is too large
+ 0 - 0
tests/test_device_config.py


Some files were not shown because too many files changed in this diff