Skip to content

Commit

Permalink
Fix events so they work with multiple devices (#22477)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 authored and balloob committed Mar 28, 2019
1 parent d13c892 commit 8f3434c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/axis/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def async_add_sensor(event):
"""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):
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/axis/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,16 @@ async def async_setup(self):

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):
Expand Down

0 comments on commit 8f3434c

Please sign in to comment.