Since the output sensor can be freely defined. The percentage does not make sense as a unit of measurement.
class PIDOutputSensor(
CoordinatorEntity[PIDDataCoordinator], RestoreEntity, SensorEntity
):
"""Sensor representing the PID output."""
def __init__(
self, hass: HomeAssistant, entry: ConfigEntry, coordinator: PIDDataCoordinator
):
super().__init__(coordinator)
name = "PID Output"
key = "pid_output"
BasePIDEntity.__init__(self, hass, entry, key, name)
**self._attr_native_unit_of_measurement = "%".**
self._attr_state_class = SensorStateClass.MEASUREMENT
async def async_added_to_hass(self):
await super().async_added_to_hass()
if (state := await self.async_get_last_state()) is not None:
try:
value = float(state.state)
self._handle.last_known_output = value
except (ValueError, TypeError):
self._handle.last_known_output = 0.0
@property
def native_value(self) -> float | None:
if self.coordinator.data is None:
return None
return round(self.coordinator.data, 2)
Since the output sensor can be freely defined. The percentage does not make sense as a unit of measurement.