Fix device tracker sending invalid event data
parent
4c37ee8884
commit
d774ba46c7
|
@ -31,7 +31,7 @@ from homeassistant.util.yaml import dump
|
||||||
from homeassistant.helpers.event import track_utc_time_change
|
from homeassistant.helpers.event import track_utc_time_change
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_GPS_ACCURACY, ATTR_LATITUDE, ATTR_LONGITUDE,
|
ATTR_GPS_ACCURACY, ATTR_LATITUDE, ATTR_LONGITUDE,
|
||||||
DEVICE_DEFAULT_NAME, STATE_HOME, STATE_NOT_HOME)
|
DEVICE_DEFAULT_NAME, STATE_HOME, STATE_NOT_HOME, ATTR_ENTITY_ID)
|
||||||
|
|
||||||
DOMAIN = 'device_tracker'
|
DOMAIN = 'device_tracker'
|
||||||
DEPENDENCIES = ['zone']
|
DEPENDENCIES = ['zone']
|
||||||
|
@ -242,7 +242,10 @@ class DeviceTracker(object):
|
||||||
if device.track:
|
if device.track:
|
||||||
device.update_ha_state()
|
device.update_ha_state()
|
||||||
|
|
||||||
self.hass.bus.fire(EVENT_NEW_DEVICE, device)
|
self.hass.bus.fire(EVENT_NEW_DEVICE, {
|
||||||
|
ATTR_ENTITY_ID: device.entity_id,
|
||||||
|
ATTR_HOST_NAME: device.host_name,
|
||||||
|
})
|
||||||
|
|
||||||
# During init, we ignore the group
|
# During init, we ignore the group
|
||||||
if self.group is not None:
|
if self.group is not None:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""The tests for the device tracker component."""
|
"""The tests for the device tracker component."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import call, patch
|
from unittest.mock import call, patch
|
||||||
|
@ -15,6 +16,7 @@ from homeassistant.const import (
|
||||||
STATE_HOME, STATE_NOT_HOME, CONF_PLATFORM)
|
STATE_HOME, STATE_NOT_HOME, CONF_PLATFORM)
|
||||||
import homeassistant.components.device_tracker as device_tracker
|
import homeassistant.components.device_tracker as device_tracker
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
from homeassistant.remote import JSONEncoder
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
get_test_home_assistant, fire_time_changed, fire_service_discovered,
|
get_test_home_assistant, fire_time_changed, fire_service_discovered,
|
||||||
|
@ -324,7 +326,16 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
device_tracker.see(self.hass, 'mac_1', host_name='hello')
|
device_tracker.see(self.hass, 'mac_1', host_name='hello')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(test_events))
|
|
||||||
|
assert len(test_events) == 1
|
||||||
|
|
||||||
|
# Assert we can serialize the event
|
||||||
|
json.dumps(test_events[0].as_dict(), cls=JSONEncoder)
|
||||||
|
|
||||||
|
assert test_events[0].data == {
|
||||||
|
'entity_id': 'device_tracker.hello',
|
||||||
|
'host_name': 'hello',
|
||||||
|
}
|
||||||
|
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
def test_not_write_duplicate_yaml_keys(self):
|
def test_not_write_duplicate_yaml_keys(self):
|
||||||
|
|
Loading…
Reference in New Issue