From 3c8204528939d6a1f8b12867b684d591bea216c2 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 5 Sep 2023 15:40:11 +0200 Subject: [PATCH] Use shorthand attributes in Omnilogic (#99626) --- homeassistant/components/omnilogic/sensor.py | 35 ++++++-------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/omnilogic/sensor.py b/homeassistant/components/omnilogic/sensor.py index 5cb7605b854..be082584308 100644 --- a/homeassistant/components/omnilogic/sensor.py +++ b/homeassistant/components/omnilogic/sensor.py @@ -66,7 +66,7 @@ class OmnilogicSensor(OmniLogicEntity, SensorEntity): coordinator: OmniLogicUpdateCoordinator, kind: str, name: str, - device_class: str, + device_class: SensorDeviceClass | None, icon: str, unit: str, item_id: tuple, @@ -85,20 +85,10 @@ class OmnilogicSensor(OmniLogicEntity, SensorEntity): unit_type = coordinator.data[backyard_id].get("Unit-of-Measurement") self._unit_type = unit_type - self._device_class = device_class - self._unit = unit + self._attr_device_class = device_class + self._attr_native_unit_of_measurement = unit self._state_key = state_key - @property - def device_class(self): - """Return the device class of the entity.""" - return self._device_class - - @property - def native_unit_of_measurement(self): - """Return the right unit of measure.""" - return self._unit - class OmniLogicTemperatureSensor(OmnilogicSensor): """Define an OmniLogic Temperature (Air/Water) Sensor.""" @@ -123,7 +113,7 @@ class OmniLogicTemperatureSensor(OmnilogicSensor): self._attrs["hayward_temperature"] = hayward_state self._attrs["hayward_unit_of_measure"] = hayward_unit_of_measure - self._unit = UnitOfTemperature.FAHRENHEIT + self._attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT return state @@ -143,10 +133,10 @@ class OmniLogicPumpSpeedSensor(OmnilogicSensor): pump_speed = self.coordinator.data[self._item_id][self._state_key] if pump_type == "VARIABLE": - self._unit = PERCENTAGE + self._attr_native_unit_of_measurement = PERCENTAGE state = pump_speed elif pump_type == "DUAL": - self._unit = None + self._attr_native_unit_of_measurement = None if pump_speed == 0: state = "off" elif pump_speed == self.coordinator.data[self._item_id].get( @@ -171,13 +161,12 @@ class OmniLogicSaltLevelSensor(OmnilogicSensor): """Return the state for the salt level sensor.""" salt_return = self.coordinator.data[self._item_id][self._state_key] - unit_of_measurement = self._unit if self._unit_type == "Metric": salt_return = round(int(salt_return) / 1000, 2) - unit_of_measurement = f"{UnitOfMass.GRAMS}/{UnitOfVolume.LITERS}" - - self._unit = unit_of_measurement + self._attr_native_unit_of_measurement = ( + f"{UnitOfMass.GRAMS}/{UnitOfVolume.LITERS}" + ) return salt_return @@ -188,9 +177,7 @@ class OmniLogicChlorinatorSensor(OmnilogicSensor): @property def native_value(self): """Return the state for the chlorinator sensor.""" - state = self.coordinator.data[self._item_id][self._state_key] - - return state + return self.coordinator.data[self._item_id][self._state_key] class OmniLogicPHSensor(OmnilogicSensor): @@ -224,7 +211,7 @@ class OmniLogicORPSensor(OmnilogicSensor): name: str, kind: str, item_id: tuple, - device_class: str, + device_class: SensorDeviceClass | None, icon: str, unit: str, ) -> None: