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 authored and Pascal Vizeli committed 2017-06-14 14:39:18 +02:00
1 parent 8c0967a190
commit 02f7eb9675
2 files changed
+37 -15

No files matched your search

@@ -122,15 +122,10 @@ def async_setup(hass: HomeAssistantType, config: ConfigType):
"""Set up the device tracker."""
yaml_path = hass.config.path(YAML_DEVICES)
try:
conf = config.get(DOMAIN, [])
except vol.Invalid as ex:
async_log_exception(ex, DOMAIN, config, hass)
return False
else:
conf = conf[0] if conf else {}
consider_home = conf.get(CONF_CONSIDER_HOME, DEFAULT_CONSIDER_HOME)
track_new = conf.get(CONF_TRACK_NEW, DEFAULT_TRACK_NEW)
conf = config.get(DOMAIN, [])
conf = conf[0] if conf else {}
consider_home = conf.get(CONF_CONSIDER_HOME, DEFAULT_CONSIDER_HOME)
track_new = conf.get(CONF_TRACK_NEW, DEFAULT_TRACK_NEW)
devices = yield from async_load_config(yaml_path, hass, consider_home)
tracker = DeviceTracker(hass, consider_home, track_new, devices)
@@ -246,18 +241,21 @@ class DeviceTracker(object):
def see(self, mac: str=None, dev_id: str=None, host_name: str=None,
location_name: str=None, gps: GPSType=None, gps_accuracy=None,
battery: str=None, attributes: dict=None,
source_type: str=SOURCE_TYPE_GPS):
source_type: str=SOURCE_TYPE_GPS, picture: str=None,
icon: str=None):
"""Notify the device tracker that you see a device."""
self.hass.add_job(
self.async_see(mac, dev_id, host_name, location_name, gps,
gps_accuracy, battery, attributes, source_type)
gps_accuracy, battery, attributes, source_type,
picture, icon)
)
@asyncio.coroutine
def async_see(self, mac: str=None, dev_id: str=None, host_name: str=None,
location_name: str=None, gps: GPSType=None,
gps_accuracy=None, battery: str=None, attributes: dict=None,
source_type: str=SOURCE_TYPE_GPS):
source_type: str=SOURCE_TYPE_GPS, picture: str=None,
icon: str=None):
"""Notify the device tracker that you see a device.
This method is a coroutine.
@@ -285,7 +283,8 @@ class DeviceTracker(object):
dev_id = util.ensure_unique_string(dev_id, self.devices.keys())
device = Device(
self.hass, self.consider_home, self.track_new,
dev_id, mac, (host_name or dev_id).replace('_', ' '))
dev_id, mac, (host_name or dev_id).replace('_', ' '),
picture=picture, icon=icon)
self.devices[dev_id] = device
if mac is not None:
self.mac_to_dev[mac] = device