Skip to content
Open
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
9 changes: 6 additions & 3 deletions custom_components/pid_controller/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from homeassistant.exceptions import TemplateError
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
from homeassistant.helpers.event import async_track_state_change
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.template import result_as_boolean

# pylint: disable=wildcard-import, unused-wildcard-import
Expand Down Expand Up @@ -810,8 +810,11 @@ async def async_added_to_hass(self) -> None:

# pylint: disable=unused-argument
@callback
def sensor_state_listener(entity, old_state, new_state):
def sensor_state_listener(event):
"""Handle device state changes."""
entity = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
last_state = self.state
self._update_sensor(entity=entity)
if last_state != self.state or entity in self._force_update:
Expand All @@ -828,7 +831,7 @@ def sensor_startup(event):

## process listners
for entity in self._entities:
async_track_state_change(self.hass, entity, sensor_state_listener)
async_track_state_change_event(self.hass, entity, sensor_state_listener)

self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, sensor_startup)

Expand Down