lock.py 2.1 KB

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