Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use signal dispatcher to invoke plaato state update #24627

Merged
Merged
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
10 changes: 9 additions & 1 deletion homeassistant/components/plaato/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging

from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.entity import Entity

from . import (
Expand Down Expand Up @@ -45,7 +46,8 @@ async def _update_sensor(device_id):
async_add_entities(entities, True)
else:
for entity in devices[device_id]:
entity.async_schedule_update_ha_state()
async_dispatcher_send(hass, "{}_{}".format(PLAATO_DOMAIN,
entity.unique_id))

hass.data[SENSOR_DATA_KEY] = async_dispatcher_connect(
hass, SENSOR_UPDATE, _update_sensor
Expand Down Expand Up @@ -137,3 +139,9 @@ def unit_of_measurement(self):
def should_poll(self):
"""Return the polling state."""
return False

async def async_added_to_hass(self):
"""Register callbacks."""
self.hass.helpers.dispatcher.async_dispatcher_connect(
"{}_{}".format(PLAATO_DOMAIN, self.unique_id),
self.async_schedule_update_ha_state)