mirror of
https://github.com/home-assistant/core.git
synced 2025-05-01 12:47:53 +00:00
Fix noisy error on startup. Make callbacks code consistent.
This commit is contained in:
parent
b16c17fae5
commit
4e3c8a8697
@ -90,6 +90,8 @@ class BinarySensorTemplate(BinarySensorDevice):
|
|||||||
hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener)
|
hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener)
|
||||||
|
|
||||||
def _event_listener(self, event):
|
def _event_listener(self, event):
|
||||||
|
if not hasattr(self, 'hass'):
|
||||||
|
return
|
||||||
self.update_ha_state(True)
|
self.update_ha_state(True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -86,12 +86,13 @@ class SensorTemplate(Entity):
|
|||||||
self._unit_of_measurement = unit_of_measurement
|
self._unit_of_measurement = unit_of_measurement
|
||||||
self._template = state_template
|
self._template = state_template
|
||||||
self.update()
|
self.update()
|
||||||
|
self.hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener)
|
||||||
|
|
||||||
def _update_callback(_event):
|
def _event_listener(self, event):
|
||||||
""" Called when the target device changes state. """
|
""" Called when the target device changes state. """
|
||||||
self.update_ha_state(True)
|
if not hasattr(self, 'hass'):
|
||||||
|
return
|
||||||
self.hass.bus.listen(EVENT_STATE_CHANGED, _update_callback)
|
self.update_ha_state(True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -100,12 +100,13 @@ class SwitchTemplate(SwitchDevice):
|
|||||||
self._on_action = on_action
|
self._on_action = on_action
|
||||||
self._off_action = off_action
|
self._off_action = off_action
|
||||||
self.update()
|
self.update()
|
||||||
|
self.hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener)
|
||||||
|
|
||||||
def _update_callback(_event):
|
def _event_listener(self, event):
|
||||||
"""Called when the target device changes state."""
|
""" Called when the target device changes state. """
|
||||||
self.update_ha_state(True)
|
if not hasattr(self, 'hass'):
|
||||||
|
return
|
||||||
self.hass.bus.listen(EVENT_STATE_CHANGED, _update_callback)
|
self.update_ha_state(True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user