소스 검색

Fix unit tests

Unit test mocking was not able to work with previous change, so revert to importing all of tinytuya instead of only required portions.
Jason Rumney 4 년 전
부모
커밋
e356b48be8
2개의 변경된 파일5개의 추가작업 그리고 4개의 파일을 삭제
  1. 3 3
      custom_components/tuya_local/device.py
  2. 2 1
      tests/test_device.py

+ 3 - 3
custom_components/tuya_local/device.py

@@ -4,9 +4,9 @@ API for Tuya Local devices.
 
 
 import json
 import json
 import logging
 import logging
+import tinytuya
 from threading import Lock, Timer
 from threading import Lock, Timer
 from time import time
 from time import time
-from tinytuya import CONTROL, Device as TuyaDevice
 
 
 
 
 from homeassistant.const import TEMP_CELSIUS
 from homeassistant.const import TEMP_CELSIUS
@@ -44,7 +44,7 @@ class TuyaLocalDevice(object):
         self._name = name
         self._name = name
         self._api_protocol_version_index = None
         self._api_protocol_version_index = None
         self._api_protocol_working = False
         self._api_protocol_working = False
-        self._api = TuyaDevice(dev_id, address, local_key)
+        self._api = tinytuya.Device(dev_id, address, local_key)
         self._refresh_task = None
         self._refresh_task = None
         self._rotate_api_protocol_version()
         self._rotate_api_protocol_version()
 
 
@@ -207,7 +207,7 @@ class TuyaLocalDevice(object):
 
 
     def _send_pending_updates(self):
     def _send_pending_updates(self):
         pending_properties = self._get_pending_properties()
         pending_properties = self._get_pending_properties()
-        payload = self._api.generate_payload(CONTROL, pending_properties)
+        payload = self._api.generate_payload(tinytuya.CONTROL, pending_properties)
 
 
         _LOGGER.debug(f"sending dps update: {json.dumps(pending_properties)}")
         _LOGGER.debug(f"sending dps update: {json.dumps(pending_properties)}")
 
 

+ 2 - 1
tests/test_device.py

@@ -1,4 +1,5 @@
 import threading
 import threading
+import tinytuya
 from datetime import datetime, timedelta
 from datetime import datetime, timedelta
 from time import sleep, time
 from time import sleep, time
 from unittest import IsolatedAsyncioTestCase
 from unittest import IsolatedAsyncioTestCase
@@ -337,7 +338,7 @@ class TestDevice(IsolatedAsyncioTestCase):
             self.subject._api.generate_payload.return_value = "payload"
             self.subject._api.generate_payload.return_value = "payload"
             self.subject._send_pending_updates()
             self.subject._send_pending_updates()
             self.subject._api.generate_payload.assert_called_once_with(
             self.subject._api.generate_payload.assert_called_once_with(
-                "set", {"1": True, "2": False}
+                tinytuya.CONTROL, {"1": True, "2": False}
             )
             )
             self.subject._api._send_receive.assert_called_once_with("payload")
             self.subject._api._send_receive.assert_called_once_with("payload")