Device tracker: remove support for old config
This commit is contained in:
parent
1159360281
commit
fb46eff5f8
3 changed files with 13 additions and 87 deletions
|
@ -8,7 +8,6 @@ https://home-assistant.io/components/device_tracker/
|
|||
"""
|
||||
# pylint: disable=too-many-instance-attributes, too-many-arguments
|
||||
# pylint: disable=too-many-locals
|
||||
import csv
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import os
|
||||
|
@ -36,7 +35,6 @@ ENTITY_ID_ALL_DEVICES = group.ENTITY_ID_FORMAT.format('all_devices')
|
|||
|
||||
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
||||
|
||||
CSV_DEVICES = "known_devices.csv"
|
||||
YAML_DEVICES = 'known_devices.yaml'
|
||||
|
||||
CONF_TRACK_NEW = "track_new_devices"
|
||||
|
@ -93,10 +91,6 @@ def see(hass, mac=None, dev_id=None, host_name=None, location_name=None,
|
|||
def setup(hass, config):
|
||||
""" Setup device tracker """
|
||||
yaml_path = hass.config.path(YAML_DEVICES)
|
||||
csv_path = hass.config.path(CSV_DEVICES)
|
||||
if os.path.isfile(csv_path) and not os.path.isfile(yaml_path) and \
|
||||
convert_csv_config(csv_path, yaml_path):
|
||||
os.remove(csv_path)
|
||||
|
||||
conf = config.get(DOMAIN, {})
|
||||
if isinstance(conf, list):
|
||||
|
@ -370,21 +364,6 @@ class Device(Entity):
|
|||
self.last_update_home = True
|
||||
|
||||
|
||||
def convert_csv_config(csv_path, yaml_path):
|
||||
""" Convert CSV config file format to YAML. """
|
||||
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']) or DEVICE_DEFAULT_NAME).lower(),
|
||||
used_ids)
|
||||
used_ids.add(dev_id)
|
||||
device = Device(None, None, None, row['track'] == '1', dev_id,
|
||||
row['device'], row['name'], row['picture'])
|
||||
update_config(yaml_path, dev_id, device)
|
||||
return True
|
||||
|
||||
|
||||
def load_config(path, hass, consider_home, home_range):
|
||||
""" Load devices from YAML config file. """
|
||||
if not os.path.isfile(path):
|
||||
|
|
|
@ -51,55 +51,6 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
|||
|
||||
self.assertFalse(device_tracker.is_on(self.hass, entity_id))
|
||||
|
||||
def test_migrating_config(self):
|
||||
csv_devices = self.hass.config.path(device_tracker.CSV_DEVICES)
|
||||
|
||||
self.assertFalse(os.path.isfile(csv_devices))
|
||||
self.assertFalse(os.path.isfile(self.yaml_devices))
|
||||
|
||||
person1 = {
|
||||
'mac': 'AB:CD:EF:GH:IJ:KL',
|
||||
'name': 'Paulus',
|
||||
'track': True,
|
||||
'picture': 'http://placehold.it/200x200',
|
||||
}
|
||||
person2 = {
|
||||
'mac': 'MN:OP:QR:ST:UV:WX:YZ',
|
||||
'name': '',
|
||||
'track': False,
|
||||
'picture': None,
|
||||
}
|
||||
|
||||
try:
|
||||
with open(csv_devices, 'w') as fil:
|
||||
fil.write('device,name,track,picture\n')
|
||||
for pers in (person1, person2):
|
||||
fil.write('{},{},{},{}\n'.format(
|
||||
pers['mac'], pers['name'],
|
||||
'1' if pers['track'] else '0', pers['picture'] or ''))
|
||||
|
||||
self.assertTrue(device_tracker.setup(self.hass, {}))
|
||||
self.assertFalse(os.path.isfile(csv_devices))
|
||||
self.assertTrue(os.path.isfile(self.yaml_devices))
|
||||
|
||||
yaml_config = load_yaml_config_file(self.yaml_devices)
|
||||
|
||||
self.assertEqual(2, len(yaml_config))
|
||||
|
||||
for pers, yaml_pers in zip(
|
||||
(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:
|
||||
try:
|
||||
os.remove(csv_devices)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
def test_reading_yaml_config(self):
|
||||
dev_id = 'test'
|
||||
device = device_tracker.Device(
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
"""
|
||||
tests.test_component_device_sun_light_trigger
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests device sun light trigger component.
|
||||
"""
|
||||
"""Tests device sun light trigger component."""
|
||||
# pylint: disable=too-many-public-methods,protected-access
|
||||
import os
|
||||
import unittest
|
||||
|
@ -19,25 +14,26 @@ from tests.common import (
|
|||
ensure_sun_set)
|
||||
|
||||
|
||||
KNOWN_DEV_CSV_PATH = os.path.join(get_test_config_dir(),
|
||||
device_tracker.CSV_DEVICES)
|
||||
KNOWN_DEV_YAML_PATH = os.path.join(get_test_config_dir(),
|
||||
device_tracker.YAML_DEVICES)
|
||||
|
||||
|
||||
def setUpModule(): # pylint: disable=invalid-name
|
||||
""" Initalizes a Home Assistant server. """
|
||||
with open(KNOWN_DEV_CSV_PATH, 'w') as fil:
|
||||
fil.write('device,name,track,picture\n')
|
||||
fil.write('DEV1,device 1,1,http://example.com/dev1.jpg\n')
|
||||
fil.write('DEV2,device 2,1,http://example.com/dev2.jpg\n')
|
||||
"""Write a device tracker known devices file to be used."""
|
||||
device_tracker.update_config(
|
||||
KNOWN_DEV_YAML_PATH, 'device_1', device_tracker.Device(
|
||||
None, None, None, True, 'device_1', 'DEV1',
|
||||
picture='http://example.com/dev1.jpg'))
|
||||
|
||||
device_tracker.update_config(
|
||||
KNOWN_DEV_YAML_PATH, 'device_2', device_tracker.Device(
|
||||
None, None, None, True, 'device_2', 'DEV2',
|
||||
picture='http://example.com/dev2.jpg'))
|
||||
|
||||
|
||||
def tearDownModule(): # pylint: disable=invalid-name
|
||||
""" Stops the Home Assistant server. """
|
||||
for fil in (KNOWN_DEV_CSV_PATH, KNOWN_DEV_YAML_PATH):
|
||||
if os.path.isfile(fil):
|
||||
os.remove(fil)
|
||||
"""Remove device tracker known devices file."""
|
||||
os.remove(KNOWN_DEV_YAML_PATH)
|
||||
|
||||
|
||||
class TestDeviceSunLightTrigger(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue