mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
commit
c98b56a807
@ -22,6 +22,7 @@ from homeassistant.const import (
|
|||||||
CONF_CUSTOMIZE, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME,
|
CONF_CUSTOMIZE, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME,
|
||||||
CONF_TEMPERATURE_UNIT, CONF_TIME_ZONE, EVENT_COMPONENT_LOADED,
|
CONF_TEMPERATURE_UNIT, CONF_TIME_ZONE, EVENT_COMPONENT_LOADED,
|
||||||
TEMP_CELCIUS, TEMP_FAHRENHEIT, PLATFORM_FORMAT, __version__)
|
TEMP_CELCIUS, TEMP_FAHRENHEIT, PLATFORM_FORMAT, __version__)
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
event_decorators, service, config_per_platform, extract_domain_configs)
|
event_decorators, service, config_per_platform, extract_domain_configs)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
@ -293,7 +294,10 @@ def from_config_file(config_path, hass=None, verbose=False, daemon=False,
|
|||||||
|
|
||||||
enable_logging(hass, verbose, daemon, log_rotate_days)
|
enable_logging(hass, verbose, daemon, log_rotate_days)
|
||||||
|
|
||||||
config_dict = config_util.load_yaml_config_file(config_path)
|
try:
|
||||||
|
config_dict = config_util.load_yaml_config_file(config_path)
|
||||||
|
except HomeAssistantError:
|
||||||
|
return None
|
||||||
|
|
||||||
return from_config_dict(config_dict, hass, enable_log=False,
|
return from_config_dict(config_dict, hass, enable_log=False,
|
||||||
skip_pip=skip_pip)
|
skip_pip=skip_pip)
|
||||||
|
@ -204,6 +204,7 @@ class DeviceTracker(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# If no device can be found, create it
|
# If no device can be found, create it
|
||||||
|
dev_id = util.ensure_unique_string(dev_id, self.devices.keys())
|
||||||
device = Device(
|
device = Device(
|
||||||
self.hass, self.consider_home, self.home_range, self.track_new,
|
self.hass, self.consider_home, self.home_range, self.track_new,
|
||||||
dev_id, mac, (host_name or dev_id).replace('_', ' '))
|
dev_id, mac, (host_name or dev_id).replace('_', ' '))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
"""Constants used by Home Assistant components."""
|
"""Constants used by Home Assistant components."""
|
||||||
|
|
||||||
__version__ = "0.17.1"
|
__version__ = "0.17.2"
|
||||||
REQUIRED_PYTHON_VER = (3, 4)
|
REQUIRED_PYTHON_VER = (3, 4)
|
||||||
|
|
||||||
PLATFORM_FORMAT = '{}.{}'
|
PLATFORM_FORMAT = '{}.{}'
|
||||||
|
@ -29,10 +29,9 @@ def load_yaml(fname):
|
|||||||
# If configuration file is empty YAML returns None
|
# If configuration file is empty YAML returns None
|
||||||
# We convert that to an empty dict
|
# We convert that to an empty dict
|
||||||
return yaml.load(conf_file, Loader=SafeLineLoader) or {}
|
return yaml.load(conf_file, Loader=SafeLineLoader) or {}
|
||||||
except yaml.YAMLError:
|
except yaml.YAMLError as exc:
|
||||||
error = 'Error reading YAML configuration file {}'.format(fname)
|
_LOGGER.error(exc)
|
||||||
_LOGGER.exception(error)
|
raise HomeAssistantError(exc)
|
||||||
raise HomeAssistantError(error)
|
|
||||||
|
|
||||||
|
|
||||||
def _include_yaml(loader, node):
|
def _include_yaml(loader, node):
|
||||||
@ -55,9 +54,12 @@ def _ordered_dict(loader, node):
|
|||||||
line = getattr(node, '__line__', 'unknown')
|
line = getattr(node, '__line__', 'unknown')
|
||||||
if key in seen:
|
if key in seen:
|
||||||
fname = getattr(loader.stream, 'name', '')
|
fname = getattr(loader.stream, 'name', '')
|
||||||
raise yaml.YAMLError("ERROR: duplicate key: \"{}\""
|
first_mark = yaml.Mark(fname, 0, seen[key], -1, None, None)
|
||||||
" in {} line {} and {}"
|
second_mark = yaml.Mark(fname, 0, line, -1, None, None)
|
||||||
.format(key, fname, seen[key], line))
|
raise yaml.MarkedYAMLError(
|
||||||
|
context="duplicate key: \"{}\"".format(key),
|
||||||
|
context_mark=first_mark, problem_mark=second_mark,
|
||||||
|
)
|
||||||
seen[key] = line
|
seen[key] = line
|
||||||
|
|
||||||
return OrderedDict(nodes)
|
return OrderedDict(nodes)
|
||||||
|
@ -197,3 +197,16 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
|||||||
mock_see.assert_called_once_with(
|
mock_see.assert_called_once_with(
|
||||||
mac=mac, dev_id=dev_id, host_name=host_name,
|
mac=mac, dev_id=dev_id, host_name=host_name,
|
||||||
location_name=location_name, gps=gps)
|
location_name=location_name, gps=gps)
|
||||||
|
|
||||||
|
def test_not_write_duplicate_yaml_keys(self):
|
||||||
|
"""Test that the device tracker will not generate invalid YAML."""
|
||||||
|
self.assertTrue(device_tracker.setup(self.hass, {}))
|
||||||
|
|
||||||
|
device_tracker.see(self.hass, 'mac_1', host_name='hello')
|
||||||
|
device_tracker.see(self.hass, 'mac_2', host_name='hello')
|
||||||
|
|
||||||
|
self.hass.pool.block_till_done()
|
||||||
|
|
||||||
|
config = device_tracker.load_config(self.yaml_devices, self.hass,
|
||||||
|
timedelta(seconds=0), 0)
|
||||||
|
assert len(config) == 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user