Allow update entities on add_entities callback (#4114)

* Allow udpate entities on add_entities callback

* fix wrong position

* update force_update to update_before_add

* add unittest for update_befor_add

* fix unittest

* change mocking
This commit is contained in:
Pascal Vizeli 2016-10-30 00:33:11 +02:00 committed by Paulus Schoutsen
parent 5d43d3eb1c
commit 9c0455e3dc
5 changed files with 50 additions and 31 deletions

View file

@ -63,7 +63,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
_LOGGER.error('No sensors added')
return False
hass.loop.create_task(async_add_devices(sensors))
hass.loop.create_task(async_add_devices(sensors, True))
return True
@ -82,8 +82,6 @@ class BinarySensorTemplate(BinarySensorDevice):
self._template = value_template
self._state = None
self._async_render()
@callback
def template_bsensor_state_listener(entity, old_state, new_state):
"""Called when the target device changes state."""
@ -115,10 +113,6 @@ class BinarySensorTemplate(BinarySensorDevice):
@asyncio.coroutine
def async_update(self):
"""Update the state from the template."""
self._async_render()
def _async_render(self):
"""Render the state from the template."""
try:
self._state = self._template.async_render().lower() == 'true'
except TemplateError as ex: