diff --git a/.coveragerc b/.coveragerc index 619b8468a07..bee0555d865 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1094,6 +1094,7 @@ omit = homeassistant/components/tolo/__init__.py homeassistant/components/tolo/climate.py homeassistant/components/tolo/light.py + homeassistant/components/tolo/sensor.py homeassistant/components/tomato/device_tracker.py homeassistant/components/toon/__init__.py homeassistant/components/toon/binary_sensor.py diff --git a/homeassistant/components/tolo/__init__.py b/homeassistant/components/tolo/__init__.py index 5151449f1fd..978bfe64ebb 100644 --- a/homeassistant/components/tolo/__init__.py +++ b/homeassistant/components/tolo/__init__.py @@ -22,7 +22,7 @@ from homeassistant.helpers.update_coordinator import ( from .const import DEFAULT_RETRY_COUNT, DEFAULT_RETRY_TIMEOUT, DOMAIN -PLATFORMS = ["climate", "light"] +PLATFORMS = ["climate", "light", "sensor"] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/tolo/manifest.json b/homeassistant/components/tolo/manifest.json index 4aa84f3f2d2..63e87ebf876 100644 --- a/homeassistant/components/tolo/manifest.json +++ b/homeassistant/components/tolo/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/tolo", "requirements": [ - "tololib==0.1.0b2" + "tololib==0.1.0b3" ], "codeowners": [ "@MatthiasLohr" diff --git a/homeassistant/components/tolo/sensor.py b/homeassistant/components/tolo/sensor.py new file mode 100644 index 00000000000..23533f68784 --- /dev/null +++ b/homeassistant/components/tolo/sensor.py @@ -0,0 +1,76 @@ +"""TOLO Sauna (non-binary, general) sensors.""" + +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import ( + DEVICE_CLASS_TEMPERATURE, + ENTITY_CATEGORY_DIAGNOSTIC, + PERCENTAGE, + TEMP_CELSIUS, +) +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from . import ToloSaunaCoordinatorEntity, ToloSaunaUpdateCoordinator +from .const import DOMAIN + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up (non-binary, general) sensors for TOLO Sauna.""" + coordinator = hass.data[DOMAIN][entry.entry_id] + async_add_entities( + [ + ToloWaterLevelSensor(coordinator, entry), + ToloTankTemperatureSensor(coordinator, entry), + ] + ) + + +class ToloWaterLevelSensor(ToloSaunaCoordinatorEntity, SensorEntity): + """Sensor for tank water level.""" + + _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC + _attr_name = "Water Level" + _attr_icon = "mdi:waves-arrow-up" + _attr_state_class = STATE_CLASS_MEASUREMENT + _attr_native_unit_of_measurement = PERCENTAGE + + def __init__( + self, coordinator: ToloSaunaUpdateCoordinator, entry: ConfigEntry + ) -> None: + """Initialize TOLO Sauna tank water level sensor entity.""" + super().__init__(coordinator, entry) + + self._attr_unique_id = f"{entry.entry_id}_water_level" + + @property + def native_value(self) -> int: + """Return current tank water level.""" + return self.coordinator.data.status.water_level_percent + + +class ToloTankTemperatureSensor(ToloSaunaCoordinatorEntity, SensorEntity): + """Sensor for tank temperature.""" + + _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC + _attr_name = "Tank Temperature" + _attr_device_class = DEVICE_CLASS_TEMPERATURE + _attr_state_class = STATE_CLASS_MEASUREMENT + _attr_native_unit_of_measurement = TEMP_CELSIUS + + def __init__( + self, coordinator: ToloSaunaUpdateCoordinator, entry: ConfigEntry + ) -> None: + """Initialize TOLO Sauna tank temperature sensor entity.""" + super().__init__(coordinator, entry) + + self._attr_unique_id = f"{entry.entry_id}_tank_temperature" + + @property + def native_value(self) -> int: + """Return current tank temperature.""" + return self.coordinator.data.status.tank_temperature diff --git a/requirements_all.txt b/requirements_all.txt index ad49c6cb0c5..d51a8a3257e 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2317,7 +2317,7 @@ tmb==0.0.4 todoist-python==8.0.0 # homeassistant.components.tolo -tololib==0.1.0b2 +tololib==0.1.0b3 # homeassistant.components.toon toonapi==0.2.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 3fd29d7f6b6..30e3fd0b7e7 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1351,7 +1351,7 @@ tellduslive==0.10.11 tesla-powerwall==0.3.12 # homeassistant.components.tolo -tololib==0.1.0b2 +tololib==0.1.0b3 # homeassistant.components.toon toonapi==0.2.1