Fix events so they work with multiple devices (#22477)
parent
d13c892b28
commit
8f3434c2ab
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue