mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
commit
c9a88322d6
@ -38,7 +38,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
for device_name, device_config in devices.items():
|
for device_name, device_config in devices.items():
|
||||||
value_template = device_config.get(CONF_VALUE_TEMPLATE)
|
value_template = device_config.get(CONF_VALUE_TEMPLATE)
|
||||||
value_template.hass = hass
|
if value_template is not None:
|
||||||
|
value_template.hass = hass
|
||||||
|
|
||||||
covers.append(
|
covers.append(
|
||||||
CommandCover(
|
CommandCover(
|
||||||
|
@ -46,6 +46,7 @@ CONF_TRACK_NEW = 'track_new_devices'
|
|||||||
DEFAULT_TRACK_NEW = True
|
DEFAULT_TRACK_NEW = True
|
||||||
|
|
||||||
CONF_CONSIDER_HOME = 'consider_home'
|
CONF_CONSIDER_HOME = 'consider_home'
|
||||||
|
DEFAULT_CONSIDER_HOME = 180
|
||||||
|
|
||||||
CONF_SCAN_INTERVAL = 'interval_seconds'
|
CONF_SCAN_INTERVAL = 'interval_seconds'
|
||||||
DEFAULT_SCAN_INTERVAL = 12
|
DEFAULT_SCAN_INTERVAL = 12
|
||||||
@ -119,8 +120,9 @@ def setup(hass: HomeAssistantType, config: ConfigType):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
conf = conf[0] if len(conf) > 0 else {}
|
conf = conf[0] if len(conf) > 0 else {}
|
||||||
consider_home = conf[CONF_CONSIDER_HOME]
|
consider_home = conf.get(CONF_CONSIDER_HOME,
|
||||||
track_new = conf[CONF_TRACK_NEW]
|
timedelta(seconds=DEFAULT_CONSIDER_HOME))
|
||||||
|
track_new = conf.get(CONF_TRACK_NEW, DEFAULT_TRACK_NEW)
|
||||||
|
|
||||||
devices = load_config(yaml_path, hass, consider_home)
|
devices = load_config(yaml_path, hass, consider_home)
|
||||||
|
|
||||||
@ -415,7 +417,7 @@ def load_config(path: str, hass: HomeAssistantType, consider_home: timedelta):
|
|||||||
for dev_id, device in devices.items():
|
for dev_id, device in devices.items():
|
||||||
try:
|
try:
|
||||||
device = dev_schema(device)
|
device = dev_schema(device)
|
||||||
device['dev_id'] = cv.slug(dev_id)
|
device['dev_id'] = cv.slugify(dev_id)
|
||||||
except vol.Invalid as exp:
|
except vol.Invalid as exp:
|
||||||
log_exception(exp, dev_id, devices)
|
log_exception(exp, dev_id, devices)
|
||||||
else:
|
else:
|
||||||
|
@ -41,7 +41,7 @@ def get_status():
|
|||||||
|
|
||||||
def get_unit_status(code):
|
def get_unit_status(code):
|
||||||
"""Get on/off status for given unit."""
|
"""Get on/off status for given unit."""
|
||||||
unit = int(code[1])
|
unit = int(code[1:])
|
||||||
return get_status()[16 - int(unit)] == '1'
|
return get_status()[16 - int(unit)] == '1'
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"""Constants used by Home Assistant components."""
|
"""Constants used by Home Assistant components."""
|
||||||
MAJOR_VERSION = 0
|
MAJOR_VERSION = 0
|
||||||
MINOR_VERSION = 30
|
MINOR_VERSION = 30
|
||||||
PATCH_VERSION = '0'
|
PATCH_VERSION = '1'
|
||||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
||||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
||||||
REQUIRED_PYTHON_VER = (3, 4, 2)
|
REQUIRED_PYTHON_VER = (3, 4, 2)
|
||||||
|
@ -17,7 +17,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import valid_entity_id
|
from homeassistant.core import valid_entity_id
|
||||||
from homeassistant.exceptions import TemplateError
|
from homeassistant.exceptions import TemplateError
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify as util_slugify
|
||||||
from homeassistant.helpers import template as template_helper
|
from homeassistant.helpers import template as template_helper
|
||||||
|
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
@ -218,12 +218,22 @@ def slug(value):
|
|||||||
if value is None:
|
if value is None:
|
||||||
raise vol.Invalid('Slug should not be None')
|
raise vol.Invalid('Slug should not be None')
|
||||||
value = str(value)
|
value = str(value)
|
||||||
slg = slugify(value)
|
slg = util_slugify(value)
|
||||||
if value == slg:
|
if value == slg:
|
||||||
return value
|
return value
|
||||||
raise vol.Invalid('invalid slug {} (try {})'.format(value, slg))
|
raise vol.Invalid('invalid slug {} (try {})'.format(value, slg))
|
||||||
|
|
||||||
|
|
||||||
|
def slugify(value):
|
||||||
|
"""Coerce a value to a slug."""
|
||||||
|
if value is None:
|
||||||
|
raise vol.Invalid('Slug should not be None')
|
||||||
|
slg = util_slugify(str(value))
|
||||||
|
if len(slg) > 0:
|
||||||
|
return slg
|
||||||
|
raise vol.Invalid('Unable to slugify {}'.format(value))
|
||||||
|
|
||||||
|
|
||||||
def string(value: Any) -> str:
|
def string(value: Any) -> str:
|
||||||
"""Coerce value to string, except for None."""
|
"""Coerce value to string, except for None."""
|
||||||
if value is not None:
|
if value is not None:
|
||||||
|
@ -60,12 +60,27 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
|||||||
"""Test when known devices contains invalid data."""
|
"""Test when known devices contains invalid data."""
|
||||||
files = {'empty.yaml': '',
|
files = {'empty.yaml': '',
|
||||||
'nodict.yaml': '100',
|
'nodict.yaml': '100',
|
||||||
'allok.yaml': 'my_device:\n name: Device'}
|
'badkey.yaml': '@:\n name: Device',
|
||||||
|
'noname.yaml': 'my_device:\n',
|
||||||
|
'allok.yaml': 'My Device:\n name: Device',
|
||||||
|
'oneok.yaml': ('My Device!:\n name: Device\n'
|
||||||
|
'bad_device:\n nme: Device')}
|
||||||
args = {'hass': self.hass, 'consider_home': timedelta(seconds=60)}
|
args = {'hass': self.hass, 'consider_home': timedelta(seconds=60)}
|
||||||
with patch_yaml_files(files):
|
with patch_yaml_files(files):
|
||||||
assert device_tracker.load_config('empty.yaml', **args) == []
|
assert device_tracker.load_config('empty.yaml', **args) == []
|
||||||
assert device_tracker.load_config('nodict.yaml', **args) == []
|
assert device_tracker.load_config('nodict.yaml', **args) == []
|
||||||
assert len(device_tracker.load_config('allok.yaml', **args)) == 1
|
assert device_tracker.load_config('noname.yaml', **args) == []
|
||||||
|
assert device_tracker.load_config('badkey.yaml', **args) == []
|
||||||
|
|
||||||
|
res = device_tracker.load_config('allok.yaml', **args)
|
||||||
|
assert len(res) == 1
|
||||||
|
assert res[0].name == 'Device'
|
||||||
|
assert res[0].dev_id == 'my_device'
|
||||||
|
|
||||||
|
res = device_tracker.load_config('oneok.yaml', **args)
|
||||||
|
assert len(res) == 1
|
||||||
|
assert res[0].name == 'Device'
|
||||||
|
assert res[0].dev_id == 'my_device'
|
||||||
|
|
||||||
def test_reading_yaml_config(self):
|
def test_reading_yaml_config(self):
|
||||||
"""Test the rendering of the YAML configuration."""
|
"""Test the rendering of the YAML configuration."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user