sensor.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 (
  6. STATE_UNAVAILABLE, ATTR_TEMPERATURE
  7. )
  8. from custom_components.goldair_climate import GoldairTuyaDevice
  9. from custom_components.goldair_climate.heater.climate import GOLDAIR_PROPERTY_TO_DPS_ID
  10. class GoldairHeaterTemperatureSensor(Entity):
  11. """Representation of a Goldair WiFi-connected heater thermometer."""
  12. def __init__(self, device):
  13. """Initialize the lock.
  14. Args:
  15. device (GoldairTuyaDevice): 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 sensor."""
  24. return self._device.name
  25. @property
  26. def state(self):
  27. """Return the current temperature."""
  28. current_temperature = self._device.get_property(GOLDAIR_PROPERTY_TO_DPS_ID[ATTR_TEMPERATURE])
  29. if current_temperature is None:
  30. return STATE_UNAVAILABLE
  31. else:
  32. return current_temperature
  33. @property
  34. def unit_of_measurement(self):
  35. return self._device.temperature_unit