Migrate callbacks to use schedule_update_ha_state (#4426)
* Migrate callbacks to use schedule_update_ha_state * Migrate MQTT sensor callback to async * Migrate wemo to not update inside schedule_update_ha_state * Make MQTT switch async * Fix nx584 test * Migrate tellstick callback * Migrate vera callback * Alarm control panel - manual: use async callbacks * Run the switch rest tests that work
This commit is contained in:
parent
38d201a54a
commit
0f59bb208c
19 changed files with 54 additions and 43 deletions
|
@ -8,6 +8,7 @@ import logging
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.core import callback
|
||||
import homeassistant.components.mqtt as mqtt
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDevice, SENSOR_CLASSES)
|
||||
|
@ -66,17 +67,18 @@ class MqttBinarySensor(BinarySensorDevice):
|
|||
self._payload_off = payload_off
|
||||
self._qos = qos
|
||||
|
||||
@callback
|
||||
def message_received(topic, payload, qos):
|
||||
"""A new MQTT message has been received."""
|
||||
if value_template is not None:
|
||||
payload = value_template.render_with_possible_json_value(
|
||||
payload = value_template.async_render_with_possible_json_value(
|
||||
payload)
|
||||
if payload == self._payload_on:
|
||||
self._state = True
|
||||
self.update_ha_state()
|
||||
hass.async_add_job(self.async_update_ha_state())
|
||||
elif payload == self._payload_off:
|
||||
self._state = False
|
||||
self.update_ha_state()
|
||||
hass.async_add_job(self.async_update_ha_state())
|
||||
|
||||
mqtt.subscribe(hass, self._state_topic, message_received, self._qos)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue