mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Fix events so they work with multiple devices (#22477)
This commit is contained in:
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."""
|
"""Add binary sensor from Axis device."""
|
||||||
async_add_entities([AxisBinarySensor(event, device)], True)
|
async_add_entities([AxisBinarySensor(event, device)], True)
|
||||||
|
|
||||||
device.listeners.append(
|
device.listeners.append(async_dispatcher_connect(
|
||||||
async_dispatcher_connect(hass, 'axis_add_sensor', async_add_sensor))
|
hass, device.event_new_sensor, async_add_sensor))
|
||||||
|
|
||||||
|
|
||||||
class AxisBinarySensor(BinarySensorDevice):
|
class AxisBinarySensor(BinarySensorDevice):
|
||||||
|
@ -99,11 +99,16 @@ class AxisNetworkDevice:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def event_new_sensor(self):
|
||||||
|
"""Device specific event to signal new sensor available."""
|
||||||
|
return 'axis_add_sensor_{}'.format(self.serial)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_signal_callback(self, action, event):
|
def async_signal_callback(self, action, event):
|
||||||
"""Call to configure events when initialized on event stream."""
|
"""Call to configure events when initialized on event stream."""
|
||||||
if action == 'add':
|
if action == 'add':
|
||||||
async_dispatcher_send(self.hass, 'axis_add_sensor', event)
|
async_dispatcher_send(self.hass, self.event_new_sensor, event)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def shutdown(self, event):
|
def shutdown(self, event):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user