From 8f3434c2ab7140592de45454a7bf00526941c610 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Thu, 28 Mar 2019 03:54:27 +0100 Subject: [PATCH] Fix events so they work with multiple devices (#22477) --- homeassistant/components/axis/binary_sensor.py | 4 ++-- homeassistant/components/axis/device.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/axis/binary_sensor.py b/homeassistant/components/axis/binary_sensor.py index 3a9583f6419..6d373dd638f 100644 --- a/homeassistant/components/axis/binary_sensor.py +++ b/homeassistant/components/axis/binary_sensor.py @@ -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): diff --git a/homeassistant/components/axis/device.py b/homeassistant/components/axis/device.py index 0d7d9348870..ffe48e5f733 100644 --- a/homeassistant/components/axis/device.py +++ b/homeassistant/components/axis/device.py @@ -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):