diff --git a/changelog.txt b/changelog.txt index 17c25343..a7884223 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Version 0.32.3 (2022-02-12) - Add state to HmIP-MOD-HO +- Use enum value for actions Version 0.32.2 (2022-02-11) - Fix HmIP-MOD-HO diff --git a/hahomematic/devices/cover.py b/hahomematic/devices/cover.py index 99dd870e..3b91e9da 100644 --- a/hahomematic/devices/cover.py +++ b/hahomematic/devices/cover.py @@ -35,11 +35,11 @@ HM_OPENING = "UP" HM_CLOSING = "DOWN" -GARAGE_DOOR_COMMAND_NOP = 0 -GARAGE_DOOR_COMMAND_OPEN = 1 -GARAGE_DOOR_COMMAND_STOP = 2 -GARAGE_DOOR_COMMAND_CLOSE = 3 -GARAGE_DOOR_COMMAND_PARTIAL_OPEN = 4 +GARAGE_DOOR_COMMAND_NOP = "NOP" +GARAGE_DOOR_COMMAND_OPEN = "OPEN" +GARAGE_DOOR_COMMAND_STOP = "STOP" +GARAGE_DOOR_COMMAND_CLOSE = "CLOSE" +GARAGE_DOOR_COMMAND_PARTIAL_OPEN = "PARTIAL_OPEN" GARAGE_DOOR_STATE_CLOSED = "CLOSED" GARAGE_DOOR_STATE_OPEN = "OPEN" diff --git a/hahomematic/devices/lock.py b/hahomematic/devices/lock.py index 30e3c119..a7b4390e 100644 --- a/hahomematic/devices/lock.py +++ b/hahomematic/devices/lock.py @@ -24,10 +24,13 @@ _LOGGER = logging.getLogger(__name__) -HM_LOCKED_TEXT = "LOCKED" -HM_LOCKED = 0 -HM_UNLOCKED = 1 -HM_OPEN = 2 +LOCK_STATE_UNKNOWN = "UNKNOWN" +LOCK_STATE_LOCKED = "LOCKED" +LOCK_STATE_UNLOCKED = "UNLOCKED" + +LOCK_TARGET_LEVEL_LOCKED = "LOCKED" +LOCK_TARGET_LEVEL_UNLOCKED = "UNLOCKED" +LOCK_TARGET_LEVEL_OPEN = "OPEN" class BaseLock(CustomEntity): @@ -109,7 +112,7 @@ def _error(self) -> bool | None: @property def is_locked(self) -> bool: """Return true if lock is on.""" - return self._lock_state == HM_LOCKED_TEXT + return self._lock_state == LOCK_STATE_LOCKED @property def is_jammed(self) -> bool: @@ -118,15 +121,15 @@ def is_jammed(self) -> bool: async def lock(self) -> None: """Lock the lock.""" - await self._e_lock_target_level.send_value(HM_LOCKED) + await self._e_lock_target_level.send_value(LOCK_TARGET_LEVEL_LOCKED) async def unlock(self) -> None: """Unlock the lock.""" - await self._e_lock_target_level.send_value(HM_UNLOCKED) + await self._e_lock_target_level.send_value(LOCK_TARGET_LEVEL_UNLOCKED) async def open(self) -> None: """Open the lock.""" - await self._e_lock_target_level.send_value(HM_OPEN) + await self._e_lock_target_level.send_value(LOCK_TARGET_LEVEL_OPEN) class CeRfLock(BaseLock): diff --git a/hahomematic/internal/action.py b/hahomematic/internal/action.py index 25d4611c..c842446e 100644 --- a/hahomematic/internal/action.py +++ b/hahomematic/internal/action.py @@ -35,3 +35,15 @@ def __init__( parameter_data=parameter_data, platform=HmPlatform.ACTION, ) + + async def send_value(self, value: Any) -> None: + """Set the value of the entity.""" + # We allow setting the value via index as well, just in case. + if ( + value is not None + and self._value_list + and isinstance(value, str) + ): + await super().send_value(self._value_list.index(value)) + else: + await super().send_value(value) diff --git a/tests/conftest.py b/tests/conftest.py index 4ad82710..eeb5d2e9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -133,7 +133,7 @@ async def get_hm_custom_entity( for custom_entity in hm_device.custom_entities.values(): if custom_entity.channel_no == channel_no: if do_load: - await custom_entity.load_data() + await custom_entity.load_entity_value() return custom_entity return None diff --git a/tests/test_central.py b/tests/test_central.py index 67dbd13f..5e9949c8 100644 --- a/tests/test_central.py +++ b/tests/test_central.py @@ -10,6 +10,7 @@ from hahomematic.const import HmEntityUsage from hahomematic.devices.climate import ATTR_TEMPERATURE, CeRfThermostat +from hahomematic.devices.lock import LOCK_TARGET_LEVEL_OPEN @pytest.mark.asyncio @@ -99,6 +100,18 @@ async def test_device_set_data(central, pydev_ccu, loop) -> None: assert new_value == 19.0 +@pytest.mark.asyncio +async def test_action_on_lock(central, pydev_ccu, loop) -> None: + """Test callback.""" + assert central + assert pydev_ccu + lock = await get_hm_custom_entity(central_unit=central, address="VCU9724704", channel_no=1, do_load=True) + assert lock + assert lock.is_locked is False + await lock.lock() + assert lock + + @pytest.mark.asyncio async def test_device_export(central, pydev_ccu, loop) -> None: """Test device export."""