Check that no configuration is provided (#3553)

This commit is contained in:
Fabian Affolter 2016-09-30 04:02:22 +02:00 committed by Paulus Schoutsen
parent 68028afb98
commit a7266ae6cf
8 changed files with 103 additions and 60 deletions

View file

@ -29,6 +29,10 @@ SERVICE_PROCESS_SCHEMA = vol.Schema({
vol.Required(ATTR_TEXT): vol.All(cv.string, vol.Lower), vol.Required(ATTR_TEXT): vol.All(cv.string, vol.Lower),
}) })
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config): def setup(hass, config):
"""Register the process service.""" """Register the process service."""
@ -48,8 +52,8 @@ def setup(hass, config):
name, command = match.groups() name, command = match.groups()
entities = {state.entity_id: state.name for state in hass.states.all()} entities = {state.entity_id: state.name for state in hass.states.all()}
entity_ids = fuzzyExtract.extractOne(name, entities, entity_ids = fuzzyExtract.extractOne(
score_cutoff=65)[2] name, entities, score_cutoff=65)[2]
if not entity_ids: if not entity_ids:
logger.error( logger.error(
@ -70,6 +74,7 @@ def setup(hass, config):
logger.error('Got unsupported command %s from text %s', logger.error('Got unsupported command %s from text %s',
command, text) command, text)
hass.services.register(DOMAIN, SERVICE_PROCESS, process, hass.services.register(
schema=SERVICE_PROCESS_SCHEMA) DOMAIN, SERVICE_PROCESS, process, schema=SERVICE_PROCESS_SCHEMA)
return True return True

View file

@ -9,6 +9,8 @@ loaded before the EVENT_PLATFORM_DISCOVERED is fired.
import logging import logging
import threading import threading
import voluptuous as vol
from homeassistant.const import EVENT_HOMEASSISTANT_START from homeassistant.const import EVENT_HOMEASSISTANT_START
from homeassistant.helpers.discovery import load_platform, discover from homeassistant.helpers.discovery import load_platform, discover
@ -33,6 +35,10 @@ SERVICE_HANDLERS = {
'directv': ('media_player', 'directv'), 'directv': ('media_player', 'directv'),
} }
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config): def setup(hass, config):
"""Start a discovery service.""" """Start a discovery service."""

View file

@ -6,8 +6,14 @@ https://home-assistant.io/components/introduction/
""" """
import logging import logging
import voluptuous as vol
DOMAIN = 'introduction' DOMAIN = 'introduction'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config=None): def setup(hass, config=None):
"""Setup the introduction component.""" """Setup the introduction component."""

View file

@ -7,27 +7,39 @@ https://home-assistant.io/components/sun/
import logging import logging
from datetime import timedelta from datetime import timedelta
import homeassistant.util as util import voluptuous as vol
from homeassistant.const import CONF_ELEVATION
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import ( from homeassistant.helpers.event import (
track_point_in_utc_time, track_utc_time_change) track_point_in_utc_time, track_utc_time_change)
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from homeassistant.const import CONF_ELEVATION import homeassistant.helpers.config_validation as cv
import homeassistant.util as util
REQUIREMENTS = ['astral==1.2'] REQUIREMENTS = ['astral==1.2']
DOMAIN = "sun"
ENTITY_ID = "sun.sun"
STATE_ABOVE_HORIZON = "above_horizon"
STATE_BELOW_HORIZON = "below_horizon"
STATE_ATTR_NEXT_RISING = "next_rising"
STATE_ATTR_NEXT_SETTING = "next_setting"
STATE_ATTR_ELEVATION = "elevation"
STATE_ATTR_AZIMUTH = "azimuth"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = 'sun'
ENTITY_ID = 'sun.sun'
STATE_ABOVE_HORIZON = 'above_horizon'
STATE_BELOW_HORIZON = 'below_horizon'
STATE_ATTR_AZIMUTH = 'azimuth'
STATE_ATTR_ELEVATION = 'elevation'
STATE_ATTR_NEXT_RISING = 'next_rising'
STATE_ATTR_NEXT_SETTING = 'next_setting'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Optional(CONF_ELEVATION): cv.positive_int,
}),
}, extra=vol.ALLOW_EXTRA)
def is_on(hass, entity_id=None): def is_on(hass, entity_id=None):
"""Test if the sun is currently up based on the statemachine.""" """Test if the sun is currently up based on the statemachine."""

View file

@ -1,28 +1,35 @@
""" """
Support to check for available updates. Support to check for available updates.
For more details about this platform, please refer to the documentation at For more details about this component, please refer to the documentation at
at https://home-assistant.io/components/updater/ https://home-assistant.io/components/updater/
""" """
import logging import logging
import requests import requests
import voluptuous as vol
from homeassistant.const import __version__ as CURRENT_VERSION from homeassistant.const import __version__ as CURRENT_VERSION
from homeassistant.const import ATTR_FRIENDLY_NAME from homeassistant.const import ATTR_FRIENDLY_NAME
from homeassistant.helpers import event from homeassistant.helpers import event
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
PYPI_URL = 'https://pypi.python.org/pypi/homeassistant/json'
DOMAIN = 'updater' DOMAIN = 'updater'
ENTITY_ID = 'updater.updater' ENTITY_ID = 'updater.updater'
PYPI_URL = 'https://pypi.python.org/pypi/homeassistant/json'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config): def setup(hass, config):
"""Setup the updater component.""" """Setup the updater component."""
if 'dev' in CURRENT_VERSION: if 'dev' in CURRENT_VERSION:
# This component only makes sense in release versions _LOGGER.warning("Updater not supported in development version")
_LOGGER.warning('Updater not supported in development version')
return False return False
def check_newest_version(_=None): def check_newest_version(_=None):
@ -31,10 +38,10 @@ def setup(hass, config):
if newest != CURRENT_VERSION and newest is not None: if newest != CURRENT_VERSION and newest is not None:
hass.states.set( hass.states.set(
ENTITY_ID, newest, {ATTR_FRIENDLY_NAME: 'Update Available'}) ENTITY_ID, newest, {ATTR_FRIENDLY_NAME: 'Update available'})
event.track_time_change(hass, check_newest_version, event.track_time_change(
hour=[0, 12], minute=0, second=0) hass, check_newest_version, hour=[0, 12], minute=0, second=0)
check_newest_version() check_newest_version()
@ -48,11 +55,11 @@ def get_newest_version():
return req.json()['info']['version'] return req.json()['info']['version']
except requests.RequestException: except requests.RequestException:
_LOGGER.exception('Could not contact PyPI to check for updates') _LOGGER.exception("Could not contact PyPI to check for updates")
return None return None
except ValueError: except ValueError:
_LOGGER.exception('Received invalid response from PyPI') _LOGGER.exception("Received invalid response from PyPI")
return None return None
except KeyError: except KeyError:
_LOGGER.exception('Response from PyPI did not include version') _LOGGER.exception("Response from PyPI did not include version")
return None return None

View file

@ -6,39 +6,41 @@ https://home-assistant.io/components/upnp/
""" """
import logging import logging
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP) import voluptuous as vol
DEPENDENCIES = ["api"] from homeassistant.const import (EVENT_HOMEASSISTANT_STOP)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = "upnp" DEPENDENCIES = ['api']
DOMAIN = 'upnp'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({}),
}, extra=vol.ALLOW_EXTRA)
# pylint: disable=import-error, no-member, broad-except
def setup(hass, config): def setup(hass, config):
"""Register a port mapping for Home Assistant via UPnP.""" """Register a port mapping for Home Assistant via UPnP."""
# pylint: disable=import-error
import miniupnpc import miniupnpc
# pylint: disable=no-member
upnp = miniupnpc.UPnP() upnp = miniupnpc.UPnP()
upnp.discoverdelay = 200 upnp.discoverdelay = 200
upnp.discover() upnp.discover()
try: try:
upnp.selectigd() upnp.selectigd()
# pylint: disable=broad-except
except Exception: except Exception:
_LOGGER.exception("Error when attempting to discover a UPnP IGD") _LOGGER.exception("Error when attempting to discover a UPnP IGD")
return False return False
upnp.addportmapping(hass.config.api.port, "TCP", upnp.addportmapping(hass.config.api.port, 'TCP', hass.config.api.host,
hass.config.api.host, hass.config.api.port, hass.config.api.port, 'Home Assistant', '')
"Home Assistant", "")
def deregister_port(event): def deregister_port(event):
"""De-register the UPnP port mapping.""" """De-register the UPnP port mapping."""
upnp.deleteportmapping(hass.config.api.port, "TCP") upnp.deleteportmapping(hass.config.api.port, 'TCP')
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, deregister_port) hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, deregister_port)

View file

@ -1,25 +1,28 @@
""" """
This module exposes Home Assistant via Zeroconf. This module exposes Home Assistant via Zeroconf.
Zeroconf is also known as Bonjour, Avahi or Multicast DNS (mDNS). For more details about this component, please refer to the documentation at
For more details about Zeroconf, please refer to the documentation at
https://home-assistant.io/components/zeroconf/ https://home-assistant.io/components/zeroconf/
""" """
import logging import logging
import socket import socket
import voluptuous as vol
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__) from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__)
REQUIREMENTS = ["zeroconf==0.17.6"]
DEPENDENCIES = ["api"]
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = "zeroconf" DEPENDENCIES = ['api']
DOMAIN = 'zeroconf'
ZEROCONF_TYPE = "_home-assistant._tcp.local." REQUIREMENTS = ['zeroconf==0.17.6']
ZEROCONF_TYPE = '_home-assistant._tcp.local.'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config): def setup(hass, config):
@ -28,12 +31,14 @@ def setup(hass, config):
zeroconf = Zeroconf() zeroconf = Zeroconf()
zeroconf_name = "{}.{}".format(hass.config.location_name, zeroconf_name = '{}.{}'.format(hass.config.location_name, ZEROCONF_TYPE)
ZEROCONF_TYPE)
requires_api_password = (hass.config.api.api_password is not None) requires_api_password = hass.config.api.api_password is not None
params = {"version": __version__, "base_url": hass.config.api.base_url, params = {
"requires_api_password": requires_api_password} 'version': __version__,
'base_url': hass.config.api.base_url,
'requires_api_password': requires_api_password,
}
info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name,
socket.inet_aton(hass.config.api.host), socket.inet_aton(hass.config.api.host),

View file

@ -33,11 +33,11 @@ class TestUpdater(unittest.TestCase):
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION updater.CURRENT_VERSION = MOCK_CURRENT_VERSION
self.assertTrue(setup_component(self.hass, updater.DOMAIN, { self.assertTrue(setup_component(self.hass, updater.DOMAIN, {
'updater': None 'updater': {}
})) }))
self.assertTrue(self.hass.states.is_state(updater.ENTITY_ID, self.assertTrue(self.hass.states.is_state(
NEW_VERSION)) updater.ENTITY_ID, NEW_VERSION))
@patch('homeassistant.components.updater.get_newest_version') @patch('homeassistant.components.updater.get_newest_version')
def test_no_entity_on_same_version(self, mock_get_newest_version): def test_no_entity_on_same_version(self, mock_get_newest_version):
@ -46,20 +46,20 @@ class TestUpdater(unittest.TestCase):
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION updater.CURRENT_VERSION = MOCK_CURRENT_VERSION
self.assertTrue(setup_component(self.hass, updater.DOMAIN, { self.assertTrue(setup_component(self.hass, updater.DOMAIN, {
'updater': None 'updater': {}
})) }))
self.assertIsNone(self.hass.states.get(updater.ENTITY_ID)) self.assertIsNone(self.hass.states.get(updater.ENTITY_ID))
mock_get_newest_version.return_value = NEW_VERSION mock_get_newest_version.return_value = NEW_VERSION
fire_time_changed(self.hass, fire_time_changed(
dt_util.utcnow().replace(hour=0, minute=0, second=0)) self.hass, dt_util.utcnow().replace(hour=0, minute=0, second=0))
self.hass.block_till_done() self.hass.block_till_done()
self.assertTrue(self.hass.states.is_state(updater.ENTITY_ID, self.assertTrue(self.hass.states.is_state(
NEW_VERSION)) updater.ENTITY_ID, NEW_VERSION))
@patch('homeassistant.components.updater.requests.get') @patch('homeassistant.components.updater.requests.get')
def test_errors_while_fetching_new_version(self, mock_get): def test_errors_while_fetching_new_version(self, mock_get):
@ -78,5 +78,5 @@ class TestUpdater(unittest.TestCase):
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION + 'dev' updater.CURRENT_VERSION = MOCK_CURRENT_VERSION + 'dev'
self.assertFalse(setup_component(self.hass, updater.DOMAIN, { self.assertFalse(setup_component(self.hass, updater.DOMAIN, {
'updater': None 'updater': {}
})) }))