diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py index d695a2b44a0..c7dc2593ddb 100644 --- a/homeassistant/components/device_tracker/__init__.py +++ b/homeassistant/components/device_tracker/__init__.py @@ -335,8 +335,8 @@ def convert_csv_config(csv_path, yaml_path): used_ids = set() with open(csv_path) as inp: for row in csv.DictReader(inp): - dev_id = util.ensure_unique_string(util.slugify(row['name']), - used_ids) + dev_id = util.ensure_unique_string( + util.slugify(row['name']) or DEVICE_DEFAULT_NAME, used_ids) used_ids.add(dev_id) device = Device(None, None, row['track'] == '1', dev_id, row['device'], row['name'], row['picture']) diff --git a/tests/components/device_tracker/test_init.py b/tests/components/device_tracker/test_init.py index 09143f6ead2..40f8a12c2d0 100644 --- a/tests/components/device_tracker/test_init.py +++ b/tests/components/device_tracker/test_init.py @@ -15,7 +15,7 @@ from homeassistant.loader import get_component import homeassistant.util.dt as dt_util from homeassistant.const import ( ATTR_ENTITY_ID, ATTR_ENTITY_PICTURE, ATTR_FRIENDLY_NAME, ATTR_HIDDEN, - STATE_HOME, STATE_NOT_HOME, CONF_PLATFORM, ) + STATE_HOME, STATE_NOT_HOME, CONF_PLATFORM, DEVICE_DEFAULT_NAME) import homeassistant.components.device_tracker as device_tracker from tests.common import ( @@ -65,7 +65,7 @@ class TestComponentsDeviceTracker(unittest.TestCase): } person2 = { 'mac': 'MN:OP:QR:ST:UV:WX:YZ', - 'name': 'Anne Therese', + 'name': '', 'track': False, 'picture': None, } @@ -87,9 +87,11 @@ class TestComponentsDeviceTracker(unittest.TestCase): self.assertEqual(2, len(yaml_config)) for pers, yaml_pers in zip( - (person2, person1), sorted(yaml_config.values(), - key=lambda pers: pers['name'])): + (person1, person2), sorted(yaml_config.values(), + key=lambda pers: pers['mac'])): for key, value in pers.items(): + if key == 'name' and value == '': + value = DEVICE_DEFAULT_NAME self.assertEqual(value, yaml_pers.get(key)) finally: