goldair_heater.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. import custom_components.goldair_heater as goldair_heater
  7. def setup_platform(hass, config, add_devices, discovery_info=None):
  8. device = hass.data[goldair_heater.DOMAIN][discovery_info['host']]
  9. add_devices([
  10. GoldairChildLock(device)
  11. ])
  12. class GoldairChildLock(LockDevice):
  13. """Representation of a Goldair WiFi-connected heater child lock."""
  14. def __init__(self, device):
  15. """Initialize the light.
  16. Args:
  17. device (GoldairHeaterDevice): 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 light."""
  26. return self._device.name
  27. @property
  28. def state(self):
  29. """Return the current state."""
  30. if self.is_locked is None:
  31. return STATE_UNAVAILABLE
  32. else:
  33. return STATE_LOCKED if self.is_locked else STATE_UNLOCKED
  34. @property
  35. def is_locked(self):
  36. """Return the current state."""
  37. return self._device.is_child_locked
  38. def lock(self, code):
  39. """Turn on the LED display."""
  40. self._device.enable_child_lock()
  41. def unlock(self, code):
  42. """Turn off the LED display."""
  43. self._device.disable_child_lock()