Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions homeassistant/components/device_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
ATTR_MAC = 'mac'
ATTR_NAME = 'name'
ATTR_SOURCE_TYPE = 'source_type'
ATTR_VENDOR = 'vendor'

SOURCE_TYPE_GPS = 'gps'
SOURCE_TYPE_ROUTER = 'router'
Expand Down Expand Up @@ -285,11 +286,6 @@ def async_see(self, mac: str=None, dev_id: str=None, host_name: str=None,
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(
Expand All @@ -299,6 +295,13 @@ def async_see(self, mac: str=None, dev_id: str=None, host_name: str=None,
# 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(
Expand Down
2 changes: 2 additions & 0 deletions tests/components/device_tracker/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ def listener(event):
assert test_events[0].data == {
'entity_id': 'device_tracker.hello',
'host_name': 'hello',
'mac': 'MAC_1',
'vendor': 'unknown',
}

# pylint: disable=invalid-name
Expand Down