lock.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """
  2. Platform to control the child lock on Goldair WiFi-connected dehumidifiers.
  3. """
  4. from homeassistant.components.lock import LockEntity
  5. from homeassistant.components.lock import STATE_LOCKED, STATE_UNLOCKED
  6. from homeassistant.const import STATE_UNAVAILABLE
  7. from ..device import TuyaLocalDevice
  8. from .const import ATTR_CHILD_LOCK, PROPERTY_TO_DPS_ID
  9. class GoldairDehumidifierChildLock(LockEntity):
  10. """Representation of a Goldair WiFi-connected dehumidifier child lock."""
  11. def __init__(self, device):
  12. """Initialize the lock.
  13. Args:
  14. device (TuyaLocalDevice): The device API instance."""
  15. self._device = device
  16. @property
  17. def should_poll(self):
  18. """Return the polling state."""
  19. return True
  20. @property
  21. def name(self):
  22. """Return the name of the lock."""
  23. return self._device.name
  24. @property
  25. def unique_id(self):
  26. """Return the unique id for this dehumidifier child lock."""
  27. return self._device.unique_id
  28. @property
  29. def device_info(self):
  30. """Return device information about this dehumidifier child lock."""
  31. return self._device.device_info
  32. @property
  33. def state(self):
  34. """Return the current state."""
  35. if self.is_locked is None:
  36. return STATE_UNAVAILABLE
  37. else:
  38. return STATE_LOCKED if self.is_locked else STATE_UNLOCKED
  39. @property
  40. def is_locked(self):
  41. """Return the a boolean representing whether the child lock is on or not."""
  42. return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK])
  43. async def async_lock(self, **kwargs):
  44. """Turn on the child lock."""
  45. await self._device.async_set_property(PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK], True)
  46. async def async_unlock(self, **kwargs):
  47. """Turn off the child lock."""
  48. await self._device.async_set_property(
  49. PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK], False
  50. )
  51. async def async_update(self):
  52. await self._device.async_refresh()