lock.py 2.0 KB

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