mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use shorthand attributes in Omnilogic (#99626)
This commit is contained in:
parent
58af0ab0cd
commit
3c82045289
@ -66,7 +66,7 @@ class OmnilogicSensor(OmniLogicEntity, SensorEntity):
|
|||||||
coordinator: OmniLogicUpdateCoordinator,
|
coordinator: OmniLogicUpdateCoordinator,
|
||||||
kind: str,
|
kind: str,
|
||||||
name: str,
|
name: str,
|
||||||
device_class: str,
|
device_class: SensorDeviceClass | None,
|
||||||
icon: str,
|
icon: str,
|
||||||
unit: str,
|
unit: str,
|
||||||
item_id: tuple,
|
item_id: tuple,
|
||||||
@ -85,20 +85,10 @@ class OmnilogicSensor(OmniLogicEntity, SensorEntity):
|
|||||||
unit_type = coordinator.data[backyard_id].get("Unit-of-Measurement")
|
unit_type = coordinator.data[backyard_id].get("Unit-of-Measurement")
|
||||||
|
|
||||||
self._unit_type = unit_type
|
self._unit_type = unit_type
|
||||||
self._device_class = device_class
|
self._attr_device_class = device_class
|
||||||
self._unit = unit
|
self._attr_native_unit_of_measurement = unit
|
||||||
self._state_key = state_key
|
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):
|
class OmniLogicTemperatureSensor(OmnilogicSensor):
|
||||||
"""Define an OmniLogic Temperature (Air/Water) Sensor."""
|
"""Define an OmniLogic Temperature (Air/Water) Sensor."""
|
||||||
@ -123,7 +113,7 @@ class OmniLogicTemperatureSensor(OmnilogicSensor):
|
|||||||
self._attrs["hayward_temperature"] = hayward_state
|
self._attrs["hayward_temperature"] = hayward_state
|
||||||
self._attrs["hayward_unit_of_measure"] = hayward_unit_of_measure
|
self._attrs["hayward_unit_of_measure"] = hayward_unit_of_measure
|
||||||
|
|
||||||
self._unit = UnitOfTemperature.FAHRENHEIT
|
self._attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
|
||||||
@ -143,10 +133,10 @@ class OmniLogicPumpSpeedSensor(OmnilogicSensor):
|
|||||||
pump_speed = self.coordinator.data[self._item_id][self._state_key]
|
pump_speed = self.coordinator.data[self._item_id][self._state_key]
|
||||||
|
|
||||||
if pump_type == "VARIABLE":
|
if pump_type == "VARIABLE":
|
||||||
self._unit = PERCENTAGE
|
self._attr_native_unit_of_measurement = PERCENTAGE
|
||||||
state = pump_speed
|
state = pump_speed
|
||||||
elif pump_type == "DUAL":
|
elif pump_type == "DUAL":
|
||||||
self._unit = None
|
self._attr_native_unit_of_measurement = None
|
||||||
if pump_speed == 0:
|
if pump_speed == 0:
|
||||||
state = "off"
|
state = "off"
|
||||||
elif pump_speed == self.coordinator.data[self._item_id].get(
|
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."""
|
"""Return the state for the salt level sensor."""
|
||||||
|
|
||||||
salt_return = self.coordinator.data[self._item_id][self._state_key]
|
salt_return = self.coordinator.data[self._item_id][self._state_key]
|
||||||
unit_of_measurement = self._unit
|
|
||||||
|
|
||||||
if self._unit_type == "Metric":
|
if self._unit_type == "Metric":
|
||||||
salt_return = round(int(salt_return) / 1000, 2)
|
salt_return = round(int(salt_return) / 1000, 2)
|
||||||
unit_of_measurement = f"{UnitOfMass.GRAMS}/{UnitOfVolume.LITERS}"
|
self._attr_native_unit_of_measurement = (
|
||||||
|
f"{UnitOfMass.GRAMS}/{UnitOfVolume.LITERS}"
|
||||||
self._unit = unit_of_measurement
|
)
|
||||||
|
|
||||||
return salt_return
|
return salt_return
|
||||||
|
|
||||||
@ -188,9 +177,7 @@ class OmniLogicChlorinatorSensor(OmnilogicSensor):
|
|||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
"""Return the state for the chlorinator sensor."""
|
"""Return the state for the chlorinator sensor."""
|
||||||
state = self.coordinator.data[self._item_id][self._state_key]
|
return self.coordinator.data[self._item_id][self._state_key]
|
||||||
|
|
||||||
return state
|
|
||||||
|
|
||||||
|
|
||||||
class OmniLogicPHSensor(OmnilogicSensor):
|
class OmniLogicPHSensor(OmnilogicSensor):
|
||||||
@ -224,7 +211,7 @@ class OmniLogicORPSensor(OmnilogicSensor):
|
|||||||
name: str,
|
name: str,
|
||||||
kind: str,
|
kind: str,
|
||||||
item_id: tuple,
|
item_id: tuple,
|
||||||
device_class: str,
|
device_class: SensorDeviceClass | None,
|
||||||
icon: str,
|
icon: str,
|
||||||
unit: str,
|
unit: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user