Have template platforms never leave the event loop

This commit is contained in:
Paulus Schoutsen committed 2016-10-01 14:11:16 -07:00
1 parent 3e24a35c1e
commit 4198c42736
6 files changed
+56 -17

No files matched your search

@@ -4,6 +4,7 @@ Support for exposing a templated binary sensor.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.template/
"""
import asyncio
import logging
import voluptuous as vol
@@ -81,9 +82,10 @@ class BinarySensorTemplate(BinarySensorDevice):
self.update()
@asyncio.coroutine
def template_bsensor_state_listener(entity, old_state, new_state):
"""Called when the target device changes state."""
self.update_ha_state(True)
yield from self.async_update_ha_state(True)
track_state_change(hass, entity_ids, template_bsensor_state_listener)
@@ -107,10 +109,11 @@ class BinarySensorTemplate(BinarySensorDevice):
"""No polling needed."""
return False
def update(self):
@asyncio.coroutine
def async_update(self):
"""Get the latest data and update the state."""
try:
self._state = self._template.render().lower() == 'true'
self._state = self._template.async_render().lower() == 'true'
except TemplateError as ex:
if ex.args and ex.args[0].startswith(
"UndefinedError: 'None' has no attribute"):