Pārlūkot izejas kodu

Use the generic lock component instead of separate classes for each device.

Jason Rumney 4 gadi atpakaļ
vecāks
revīzija
ef68755274
2 mainītis faili ar 3 papildinājumiem un 7 dzēšanām
  1. 2 4
      custom_components/tuya_local/lock.py
  2. 1 3
      tests/test_lock.py

+ 2 - 4
custom_components/tuya_local/lock.py

@@ -10,6 +10,7 @@ from .const import (
     CONF_TYPE,
     CONF_TYPE_AUTO,
 )
+from .generic.lock import TuyaLocalLock
 from .helpers.device_config import config_for_legacy_use
 
 _LOGGER = logging.getLogger(__name__)
@@ -36,10 +37,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
         if ecfg.entity != "lock":
             raise ValueError(f"{device.name} does not support use as a lock device.")
 
-    legacy_class = ecfg.legacy_class
-    # Instantiate it: Sonarcloud thinks this is a blocker bug, and legacy_class
-    # is not callable, but the unit tests show the object is created...
-    data[CONF_CHILD_LOCK] = legacy_class(device)
+    data[CONF_CHILD_LOCK] = TuyaLocalLock(device, ecfg)
     async_add_entities([data[CONF_CHILD_LOCK]])
     _LOGGER.debug(f"Adding lock for {discovery_info[CONF_TYPE]}")
 

+ 1 - 3
tests/test_lock.py

@@ -1,5 +1,4 @@
 """Tests for the lock entity."""
-import pytest
 from pytest_homeassistant_custom_component.common import MockConfigEntry
 from unittest import IsolatedAsyncioTestCase
 from unittest.mock import AsyncMock, Mock, patch
@@ -16,7 +15,6 @@ from custom_components.tuya_local.const import (
     DOMAIN,
 )
 from custom_components.tuya_local.generic.lock import TuyaLocalLock
-from custom_components.tuya_local.heater.lock import GoldairHeaterChildLock
 from custom_components.tuya_local.helpers.device_config import config_for_legacy_use
 from custom_components.tuya_local.lock import async_setup_entry
 
@@ -45,7 +43,7 @@ async def test_init_entry(hass):
     hass.data[DOMAIN]["dummy"]["device"] = m_device
 
     await async_setup_entry(hass, entry, m_add_entities)
-    assert type(hass.data[DOMAIN]["dummy"][CONF_CHILD_LOCK]) == GoldairHeaterChildLock
+    assert type(hass.data[DOMAIN]["dummy"][CONF_CHILD_LOCK]) == TuyaLocalLock
     m_add_entities.assert_called_once()