Axis change how new event is signalled (#23152)

This commit is contained in:
Robert Svensson 2019-04-17 15:21:42 +02:00 committed by GitHub
parent e114ae9b53
commit 0b7e62f737
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 9 deletions

View file

@ -18,8 +18,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
device = hass.data[AXIS_DOMAIN][serial_number]
@callback
def async_add_sensor(event):
def async_add_sensor(event_id):
"""Add binary sensor from Axis device."""
event = device.api.event.events[event_id]
async_add_entities([AxisBinarySensor(event, device)], True)
device.listeners.append(async_dispatcher_connect(
@ -83,12 +84,12 @@ class AxisBinarySensor(BinarySensorDevice):
def name(self):
"""Return the name of the event."""
return '{} {} {}'.format(
self.device.name, self.event.event_type, self.event.id)
self.device.name, self.event.TYPE, self.event.id)
@property
def device_class(self):
"""Return the class of the event."""
return self.event.event_class
return self.event.CLASS
@property
def unique_id(self):

View file

@ -140,10 +140,10 @@ class AxisNetworkDevice:
return 'axis_add_sensor_{}'.format(self.serial)
@callback
def async_event_callback(self, action, event):
def async_event_callback(self, action, event_id):
"""Call to configure events when initialized on event stream."""
if action == 'add':
async_dispatcher_send(self.hass, self.event_new_sensor, event)
async_dispatcher_send(self.hass, self.event_new_sensor, event_id)
@callback
def start(self, fut):

View file

@ -2,7 +2,7 @@
"domain": "axis",
"name": "Axis",
"documentation": "https://www.home-assistant.io/components/axis",
"requirements": ["axis==21"],
"requirements": ["axis==22"],
"dependencies": [],
"codeowners": ["@kane610"]
}

View file

@ -192,7 +192,7 @@ av==6.1.2
# avion==0.10
# homeassistant.components.axis
axis==21
axis==22
# homeassistant.components.baidu
baidu-aip==1.6.6

View file

@ -61,7 +61,7 @@ apns2==0.3.0
av==6.1.2
# homeassistant.components.axis
axis==21
axis==22
# homeassistant.components.zha
bellows-homeassistant==0.7.2

View file

@ -167,7 +167,7 @@ async def test_new_event_sends_signal(hass):
axis_device = device.AxisNetworkDevice(hass, entry)
with patch.object(device, 'async_dispatcher_send') as mock_dispatch_send:
axis_device.async_event_callback(action='add', event='event')
axis_device.async_event_callback(action='add', event_id='event')
await hass.async_block_till_done()
assert len(mock_dispatch_send.mock_calls) == 1