Selaa lähdekoodia

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 vuotta sitten
vanhempi
commit
e356b48be8
2 muutettua tiedostoa jossa 5 lisäystä ja 4 poistoa
  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 logging
+import tinytuya
 from threading import Lock, Timer
 from time import time
-from tinytuya import CONTROL, Device as TuyaDevice
 
 
 from homeassistant.const import TEMP_CELSIUS
@@ -44,7 +44,7 @@ class TuyaLocalDevice(object):
         self._name = name
         self._api_protocol_version_index = None
         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._rotate_api_protocol_version()
 
@@ -207,7 +207,7 @@ class TuyaLocalDevice(object):
 
     def _send_pending_updates(self):
         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)}")
 

+ 2 - 1
tests/test_device.py

@@ -1,4 +1,5 @@
 import threading
+import tinytuya
 from datetime import datetime, timedelta
 from time import sleep, time
 from unittest import IsolatedAsyncioTestCase
@@ -337,7 +338,7 @@ class TestDevice(IsolatedAsyncioTestCase):
             self.subject._api.generate_payload.return_value = "payload"
             self.subject._send_pending_updates()
             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")