Update dependencies to receive data on webhook callbacks (#21838)

pull/21982/head
Andrew Sayre 2019-03-08 23:20:07 -06:00 committed by Paulus Schoutsen
parent f3e8e34089
commit 39749952ee
5 changed files with 24 additions and 12 deletions

View File

@ -27,7 +27,7 @@ from .smartapp import (
setup_smartapp, setup_smartapp_endpoint, smartapp_sync_subscriptions,
validate_installed_app)
REQUIREMENTS = ['pysmartapp==0.3.0', 'pysmartthings==0.6.3']
REQUIREMENTS = ['pysmartapp==0.3.1', 'pysmartthings==0.6.7']
DEPENDENCIES = ['webhook']
_LOGGER = logging.getLogger(__name__)
@ -290,7 +290,8 @@ class DeviceBroker:
if not device:
continue
device.status.apply_attribute_update(
evt.component_id, evt.capability, evt.attribute, evt.value)
evt.component_id, evt.capability, evt.attribute, evt.value,
data=evt.data)
# Fire events for buttons
if evt.capability == Capability.button and \
@ -300,7 +301,8 @@ class DeviceBroker:
'device_id': evt.device_id,
'location_id': evt.location_id,
'value': evt.value,
'name': device.label
'name': device.label,
'data': evt.data
}
self._hass.bus.async_fire(EVENT_BUTTON, data)
_LOGGER.debug("Fired button event: %s", data)
@ -312,6 +314,7 @@ class DeviceBroker:
'capability': evt.capability,
'attribute': evt.attribute,
'value': evt.value,
'data': evt.data
}
_LOGGER.debug("Push update received: %s", data)

View File

@ -1256,10 +1256,10 @@ pysher==1.0.1
pysma==0.3.1
# homeassistant.components.smartthings
pysmartapp==0.3.0
pysmartapp==0.3.1
# homeassistant.components.smartthings
pysmartthings==0.6.3
pysmartthings==0.6.7
# homeassistant.components.device_tracker.snmp
# homeassistant.components.sensor.snmp

View File

@ -224,10 +224,10 @@ pyps4-homeassistant==0.3.0
pyqwikswitch==0.8
# homeassistant.components.smartthings
pysmartapp==0.3.0
pysmartapp==0.3.1
# homeassistant.components.smartthings
pysmartthings==0.6.3
pysmartthings==0.6.7
# homeassistant.components.sonos
pysonos==0.0.8

View File

@ -326,7 +326,7 @@ def scene_fixture(scene_factory):
def event_factory_fixture():
"""Fixture for creating mock devices."""
def _factory(device_id, event_type="DEVICE_EVENT", capability='',
attribute='Updated', value='Value'):
attribute='Updated', value='Value', data=None):
event = Mock()
event.event_type = event_type
event.device_id = device_id
@ -334,6 +334,7 @@ def event_factory_fixture():
event.capability = capability
event.attribute = attribute
event.value = value
event.data = data
event.location_id = str(uuid4())
return event
return _factory

View File

@ -235,16 +235,21 @@ async def test_broker_regenerates_token(
async def test_event_handler_dispatches_updated_devices(
hass, config_entry, device_factory, event_request_factory):
hass, config_entry, device_factory, event_request_factory,
event_factory):
"""Test the event handler dispatches updated devices."""
devices = [
device_factory('Bedroom 1 Switch', ['switch']),
device_factory('Bathroom 1', ['switch']),
device_factory('Sensor', ['motionSensor']),
device_factory('Lock', ['lock'])
]
device_ids = [devices[0].device_id, devices[1].device_id,
devices[2].device_id]
request = event_request_factory(device_ids)
devices[2].device_id, devices[3].device_id]
event = event_factory(devices[3].device_id, capability='lock',
attribute='lock', value='locked',
data={'codeId': '1'})
request = event_request_factory(device_ids=device_ids, events=[event])
config_entry.data[CONF_INSTALLED_APP_ID] = request.installed_app_id
called = False
@ -265,6 +270,8 @@ async def test_event_handler_dispatches_updated_devices(
assert called
for device in devices:
assert device.status.values['Updated'] == 'Value'
assert devices[3].status.attributes['lock'].value == 'locked'
assert devices[3].status.attributes['lock'].data == {'codeId': '1'}
async def test_event_handler_ignores_other_installed_app(
@ -308,7 +315,8 @@ async def test_event_handler_fires_button_events(
'device_id': device.device_id,
'location_id': event.location_id,
'value': 'pushed',
'name': device.label
'name': device.label,
'data': None
}
hass.bus.async_listen(EVENT_BUTTON, handler)
broker = smartthings.DeviceBroker(