lock.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """
  2. Platform to control the child lock on Goldair 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 custom_components.tuya_local import TuyaLocalDevice
  7. from custom_components.tuya_local.heater.climate import (
  8. ATTR_CHILD_LOCK, PROPERTY_TO_DPS_ID
  9. )
  10. class GoldairHeaterChildLock(LockDevice):
  11. """Representation of a Goldair WiFi-connected heater child lock."""
  12. def __init__(self, device):
  13. """Initialize the lock.
  14. Args:
  15. device (TuyaLocalDevice): The device API instance."""
  16. self._device = device
  17. @property
  18. def should_poll(self):
  19. """Return the polling state."""
  20. return True
  21. @property
  22. def name(self):
  23. """Return the name of the lock."""
  24. return self._device.name
  25. @property
  26. def state(self):
  27. """Return the current state."""
  28. if self.is_locked is None:
  29. return STATE_UNAVAILABLE
  30. else:
  31. return STATE_LOCKED if self.is_locked else STATE_UNLOCKED
  32. @property
  33. def is_locked(self):
  34. """Return the a boolean representing whether the child lock is on or not."""
  35. return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK])
  36. def lock(self, **kwargs):
  37. """Turn on the child lock."""
  38. self._device.set_property(PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK], True)
  39. def unlock(self, **kwargs):
  40. """Turn off the child lock."""
  41. self._device.set_property(PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK], False)