Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions custom_components/simple_pid_controller/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry, desc: dict) -> None:
if self._key == "setpoint":
min_val, max_val = range_min, range_max
elif self._key == "output_min":
min_val, max_val = -abs(range_max), 0.0
min_val, max_val = -abs(range_max), range_min
elif self._key == "output_max":
min_val, max_val = 0.0, range_max
min_val, max_val = range_min, range_max
else:
_LOGGER.error("Unexpected PID parameter key: %s", self._key)
min_val, max_val = DEFAULT_RANGE_MIN, DEFAULT_RANGE_MAX
Expand Down
14 changes: 13 additions & 1 deletion custom_components/simple_pid_controller/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging

from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import SensorEntity, SensorStateClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -125,6 +125,7 @@ async def start_refresh(_: Any) -> None:
PIDContributionSensor(
hass, entry, "pid_d_contrib", "D contribution", coordinator
),
PIDContributionSensor(hass, entry, "error", "Error", coordinator),
]
)

Expand Down Expand Up @@ -170,6 +171,7 @@ def __init__(
BasePIDEntity.__init__(self, hass, entry, key, name)

self._attr_native_unit_of_measurement = "%"
self._attr_state_class = SensorStateClass.MEASUREMENT

@property
def native_value(self) -> float | None:
Expand All @@ -195,14 +197,24 @@ def __init__(

self._attr_entity_category = EntityCategory.DIAGNOSTIC
self._attr_entity_registry_enabled_default = False
self._attr_state_class = SensorStateClass.MEASUREMENT
self._key = key

@property
def native_value(self):
contributions = self._handle.last_contributions
input_value = self._handle.get_input_sensor_value()
setpoint = self._handle.get_number("setpoint")

if input_value is None or setpoint is None:
error = 0
else:
error = input_value - setpoint

value = {
"p": contributions[0],
"i": contributions[1],
"d": contributions[2],
"error": error,
}.get(self._key)
return round(value, 2) if value is not None else None
Loading