Cleanup and simplitfy the async state update (#9390)

* Cleanup and simplitfy the async state update

* Update test_entity.py
This commit is contained in:
Pascal Vizeli authored and GitHub committed 2017-09-12 10:01:03 +02:00
1 parent c84a099b0f
commit 90f9a6bc0a
47 files changed
+128 -102

No files matched your search

@@ -50,7 +50,7 @@ class AlarmDecoderSensor(Entity):
def _message_callback(self, message):
if self._display != message.text:
self._display = message.text
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
@property
def icon(self):
+1 -1
View File
@@ -123,7 +123,7 @@ class ArwnSensor(Entity):
"""Update the sensor with the most recent event."""
self.event = {}
self.event.update(event)
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
@property
def state(self):
@@ -77,4 +77,4 @@ class EnvisalinkSensor(EnvisalinkDevice, Entity):
def _update_callback(self, partition):
"""Update the partition state in HA, if needed."""
if partition is None or int(partition) == self._partition_number:
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
+2 -2
View File
@@ -100,7 +100,7 @@ class MqttSensor(Entity):
payload = self._template.async_render_with_possible_json_value(
payload, self._state)
self._state = payload
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
return mqtt.async_subscribe(
self.hass, self._state_topic, message_received, self._qos)
@@ -110,7 +110,7 @@ class MqttSensor(Entity):
"""Triggered when value is expired."""
self._expiration_trigger = None
self._state = STATE_UNKNOWN
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
@property
def should_poll(self):
+1 -1
View File
@@ -96,7 +96,7 @@ class MQTTRoomSensor(Entity):
self._distance = distance
self._updated = dt.utcnow()
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
@callback
def message_received(topic, payload, qos):
+1 -1
View File
@@ -62,7 +62,7 @@ class TOTPSensor(Entity):
@callback
def _call_loop(self):
self._state = self._otp.now()
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
# Update must occur at even TIME_STEP, e.g. 12:00:00, 12:00:30,
# 12:01:00, etc. in order to have synced time (see RFC6238)
+2 -2
View File
@@ -100,7 +100,7 @@ class SensorTemplate(Entity):
@callback
def template_sensor_state_listener(entity, old_state, new_state):
"""Handle device state changes."""
self.hass.async_add_job(self.async_update_ha_state(True))
self.async_schedule_update_ha_state(True)
@callback
def template_sensor_startup(event):
@@ -108,7 +108,7 @@ class SensorTemplate(Entity):
async_track_state_change(
self.hass, self._entities, template_sensor_state_listener)
self.hass.async_add_job(self.async_update_ha_state(True))
self.async_schedule_update_ha_state(True)
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_START, template_sensor_startup)
+1 -1
View File
@@ -129,6 +129,6 @@ class TimeDateSensor(Entity):
def point_in_time_listener(self, time_date):
"""Get the latest data and update state."""
self._update_internal_state(time_date)
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
async_track_point_in_utc_time(
self.hass, self.point_in_time_listener, self.get_next_interval())
+1 -1
View File
@@ -141,4 +141,4 @@ class TorqueSensor(Entity):
def async_on_update(self, value):
"""Receive an update."""
self._state = value
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()