Small fix to be able to use mac and vendor in "device_tracker_new_device" event. (#10537)

* Small fix to be able to use mac and vendor in EVENT_NEW_DEVICE event

* Missed device_tracker test
This commit is contained in:
boltgolt 2017-11-16 07:41:39 +01:00 committed by Paulus Schoutsen
parent e20fd3b973
commit f494c32866
2 changed files with 10 additions and 5 deletions

View File

@ -76,6 +76,7 @@ ATTR_LOCATION_NAME = 'location_name'
ATTR_MAC = 'mac'
ATTR_NAME = 'name'
ATTR_SOURCE_TYPE = 'source_type'
ATTR_VENDOR = 'vendor'
SOURCE_TYPE_GPS = 'gps'
SOURCE_TYPE_ROUTER = 'router'
@ -285,11 +286,6 @@ class DeviceTracker(object):
if device.track:
yield from device.async_update_ha_state()
self.hass.bus.async_fire(EVENT_NEW_DEVICE, {
ATTR_ENTITY_ID: device.entity_id,
ATTR_HOST_NAME: device.host_name,
})
# During init, we ignore the group
if self.group and self.track_new:
self.group.async_set_group(
@ -299,6 +295,13 @@ class DeviceTracker(object):
# lookup mac vendor string to be stored in config
yield from device.set_vendor_for_mac()
self.hass.bus.async_fire(EVENT_NEW_DEVICE, {
ATTR_ENTITY_ID: device.entity_id,
ATTR_HOST_NAME: device.host_name,
ATTR_MAC: device.mac,
ATTR_VENDOR: device.vendor,
})
# update known_devices.yaml
self.hass.async_add_job(
self.async_update_config(

View File

@ -481,6 +481,8 @@ class TestComponentsDeviceTracker(unittest.TestCase):
assert test_events[0].data == {
'entity_id': 'device_tracker.hello',
'host_name': 'hello',
'mac': 'MAC_1',
'vendor': 'unknown',
}
# pylint: disable=invalid-name