Fix events so they work with multiple devices (#22477)

pull/22430/head^2
Robert Svensson 2019-03-28 03:54:27 +01:00 committed by Paulus Schoutsen
parent d13c892b28
commit 8f3434c2ab
2 changed files with 8 additions and 3 deletions

View File

@ -24,8 +24,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add binary sensor from Axis device."""
async_add_entities([AxisBinarySensor(event, device)], True)
device.listeners.append(
async_dispatcher_connect(hass, 'axis_add_sensor', async_add_sensor))
device.listeners.append(async_dispatcher_connect(
hass, device.event_new_sensor, async_add_sensor))
class AxisBinarySensor(BinarySensorDevice):

View File

@ -99,11 +99,16 @@ class AxisNetworkDevice:
return True
@property
def event_new_sensor(self):
"""Device specific event to signal new sensor available."""
return 'axis_add_sensor_{}'.format(self.serial)
@callback
def async_signal_callback(self, action, event):
"""Call to configure events when initialized on event stream."""
if action == 'add':
async_dispatcher_send(self.hass, 'axis_add_sensor', event)
async_dispatcher_send(self.hass, self.event_new_sensor, event)
@callback
def shutdown(self, event):