Allow device_tracker platforms to specify picture and icon upon discovery (#8018)

* Allow device tracker platforms to specify picture

* Allow device tracker to specify icon during discovery

* Clean up and add tests

* Fix lint

* Fix test
This commit is contained in:
Andrey
2017-06-14 15:39:18 +03:00
committed by Pascal Vizeli
parent 8c0967a190
commit 02f7eb9675
2 changed files with 37 additions and 15 deletions

View File

@@ -654,14 +654,25 @@ class TestComponentsDeviceTracker(unittest.TestCase):
assert len(config) == 4
@patch('homeassistant.components.device_tracker.async_log_exception')
def test_config_failure(self, mock_ex):
def test_config_failure(self):
"""Test that the device tracker see failures."""
with assert_setup_component(0, device_tracker.DOMAIN):
setup_component(self.hass, device_tracker.DOMAIN,
{device_tracker.DOMAIN: {
device_tracker.CONF_CONSIDER_HOME: -1}})
def test_picture_and_icon_on_see_discovery(self):
"""Test that picture and icon are set in initial see."""
tracker = device_tracker.DeviceTracker(
self.hass, timedelta(seconds=60), False, [])
tracker.see(dev_id=11, picture='pic_url', icon='mdi:icon')
self.hass.block_till_done()
config = device_tracker.load_config(self.yaml_devices, self.hass,
timedelta(seconds=0))
assert len(config) == 1
assert config[0].icon == 'mdi:icon'
assert config[0].entity_picture == 'pic_url'
@asyncio.coroutine
def test_async_added_to_hass(hass):
@@ -691,3 +702,15 @@ def test_async_added_to_hass(hass):
for key, val in attr.items():
atr = state.attributes.get(key)
assert atr == val, "{}={} expected: {}".format(key, atr, val)
@asyncio.coroutine
def test_bad_platform(hass):
"""Test bad platform."""
config = {
'device_tracker': [{
'platform': 'bad_platform'
}]
}
with assert_setup_component(0, device_tracker.DOMAIN):
assert (yield from device_tracker.async_setup(hass, config))