sensor.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. Platform to sense the current temperature at a Goldair WiFi-connected heaters and panels.
  3. """
  4. from homeassistant.helpers.entity import Entity
  5. from homeassistant.const import STATE_UNAVAILABLE
  6. import custom_components.goldair_climate as goldair_climate
  7. def setup_platform(hass, config, add_devices, discovery_info=None):
  8. device = hass.data[goldair_climate.DOMAIN][discovery_info['host']]
  9. add_devices([
  10. GoldairTemperatureSensor(device)
  11. ])
  12. class GoldairTemperatureSensor(Entity):
  13. """Representation of a Goldair WiFi-connected heater thermometer."""
  14. def __init__(self, device):
  15. """Initialize the lock.
  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 sensor."""
  26. return self._device.name
  27. @property
  28. def state(self):
  29. """Return the current state."""
  30. if self._device.current_temperature is None:
  31. return STATE_UNAVAILABLE
  32. else:
  33. return self._device.current_temperature
  34. @property
  35. def unit_of_measurement(self):
  36. return self._device.temperature_unit