mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Axis change how new event is signalled (#23152)
This commit is contained in:
parent
e114ae9b53
commit
0b7e62f737
@ -18,8 +18,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
device = hass.data[AXIS_DOMAIN][serial_number]
|
device = hass.data[AXIS_DOMAIN][serial_number]
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_sensor(event):
|
def async_add_sensor(event_id):
|
||||||
"""Add binary sensor from Axis device."""
|
"""Add binary sensor from Axis device."""
|
||||||
|
event = device.api.event.events[event_id]
|
||||||
async_add_entities([AxisBinarySensor(event, device)], True)
|
async_add_entities([AxisBinarySensor(event, device)], True)
|
||||||
|
|
||||||
device.listeners.append(async_dispatcher_connect(
|
device.listeners.append(async_dispatcher_connect(
|
||||||
@ -83,12 +84,12 @@ class AxisBinarySensor(BinarySensorDevice):
|
|||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the event."""
|
"""Return the name of the event."""
|
||||||
return '{} {} {}'.format(
|
return '{} {} {}'.format(
|
||||||
self.device.name, self.event.event_type, self.event.id)
|
self.device.name, self.event.TYPE, self.event.id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the class of the event."""
|
"""Return the class of the event."""
|
||||||
return self.event.event_class
|
return self.event.CLASS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
|
@ -140,10 +140,10 @@ class AxisNetworkDevice:
|
|||||||
return 'axis_add_sensor_{}'.format(self.serial)
|
return 'axis_add_sensor_{}'.format(self.serial)
|
||||||
|
|
||||||
@callback
|
@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."""
|
"""Call to configure events when initialized on event stream."""
|
||||||
if action == 'add':
|
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
|
@callback
|
||||||
def start(self, fut):
|
def start(self, fut):
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "axis",
|
"domain": "axis",
|
||||||
"name": "Axis",
|
"name": "Axis",
|
||||||
"documentation": "https://www.home-assistant.io/components/axis",
|
"documentation": "https://www.home-assistant.io/components/axis",
|
||||||
"requirements": ["axis==21"],
|
"requirements": ["axis==22"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@kane610"]
|
"codeowners": ["@kane610"]
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ av==6.1.2
|
|||||||
# avion==0.10
|
# avion==0.10
|
||||||
|
|
||||||
# homeassistant.components.axis
|
# homeassistant.components.axis
|
||||||
axis==21
|
axis==22
|
||||||
|
|
||||||
# homeassistant.components.baidu
|
# homeassistant.components.baidu
|
||||||
baidu-aip==1.6.6
|
baidu-aip==1.6.6
|
||||||
|
@ -61,7 +61,7 @@ apns2==0.3.0
|
|||||||
av==6.1.2
|
av==6.1.2
|
||||||
|
|
||||||
# homeassistant.components.axis
|
# homeassistant.components.axis
|
||||||
axis==21
|
axis==22
|
||||||
|
|
||||||
# homeassistant.components.zha
|
# homeassistant.components.zha
|
||||||
bellows-homeassistant==0.7.2
|
bellows-homeassistant==0.7.2
|
||||||
|
@ -167,7 +167,7 @@ async def test_new_event_sends_signal(hass):
|
|||||||
axis_device = device.AxisNetworkDevice(hass, entry)
|
axis_device = device.AxisNetworkDevice(hass, entry)
|
||||||
|
|
||||||
with patch.object(device, 'async_dispatcher_send') as mock_dispatch_send:
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(mock_dispatch_send.mock_calls) == 1
|
assert len(mock_dispatch_send.mock_calls) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user