Fix broken platform components (#22943)

* Fix broken platform components

* Lint
This commit is contained in:
Paulus Schoutsen 2019-04-09 15:42:44 -07:00 committed by GitHub
parent 8582e390f8
commit e48ef7f441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 51 deletions

View File

@ -18,7 +18,6 @@ from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.loader import bind_hass
from homeassistant.setup import async_prepare_setup_platform
from homeassistant.util.dt import utcnow
DOMAIN = 'automation'
@ -416,11 +415,8 @@ async def _async_process_trigger(hass, config, trigger_configs, name, action):
}
for conf in trigger_configs:
platform = await async_prepare_setup_platform(
hass, config, DOMAIN, conf.get(CONF_PLATFORM))
if platform is None:
return None
platform = importlib.import_module('.{}'.format(conf[CONF_PLATFORM]),
__name__)
remove = await platform.async_trigger(hass, conf, action, info)

View File

@ -30,15 +30,15 @@ from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import (
ConfigType, HomeAssistantType, ServiceDataType)
from homeassistant.loader import bind_hass
from homeassistant.setup import async_prepare_setup_platform
from homeassistant.util.async_ import (
run_callback_threadsafe, run_coroutine_threadsafe)
from homeassistant.util.logging import catch_log_exception
# Loading the config flow file will register the flow
from . import config_flow # noqa pylint: disable=unused-import
from .const import CONF_BROKER, CONF_DISCOVERY, DEFAULT_DISCOVERY
from .server import HBMQTT_CONFIG_SCHEMA
from . import config_flow, discovery, server # noqa pylint: disable=unused-import
from .const import (
CONF_BROKER, CONF_DISCOVERY, DEFAULT_DISCOVERY, CONF_STATE_TOPIC,
ATTR_DISCOVERY_HASH)
REQUIREMENTS = ['paho-mqtt==1.4.0']
@ -66,7 +66,6 @@ CONF_TLS_VERSION = 'tls_version'
CONF_BIRTH_MESSAGE = 'birth_message'
CONF_WILL_MESSAGE = 'will_message'
CONF_STATE_TOPIC = 'state_topic'
CONF_COMMAND_TOPIC = 'command_topic'
CONF_AVAILABILITY_TOPIC = 'availability_topic'
CONF_PAYLOAD_AVAILABLE = 'payload_available'
@ -101,7 +100,6 @@ ATTR_PAYLOAD = 'payload'
ATTR_PAYLOAD_TEMPLATE = 'payload_template'
ATTR_QOS = CONF_QOS
ATTR_RETAIN = CONF_RETAIN
ATTR_DISCOVERY_HASH = 'discovery_hash'
MAX_RECONNECT_WAIT = 300 # seconds
@ -209,7 +207,7 @@ CONFIG_SCHEMA = vol.Schema({
vol.Optional(CONF_PROTOCOL, default=DEFAULT_PROTOCOL):
vol.All(cv.string, vol.In([PROTOCOL_31, PROTOCOL_311])),
vol.Optional(CONF_EMBEDDED):
vol.All(HBMQTT_CONFIG_SCHEMA, embedded_broker_deprecated),
vol.All(server.HBMQTT_CONFIG_SCHEMA, embedded_broker_deprecated),
vol.Optional(CONF_WILL_MESSAGE): MQTT_WILL_BIRTH_SCHEMA,
vol.Optional(CONF_BIRTH_MESSAGE): MQTT_WILL_BIRTH_SCHEMA,
vol.Optional(CONF_DISCOVERY, default=DEFAULT_DISCOVERY): cv.boolean,
@ -408,13 +406,6 @@ async def _async_setup_server(hass: HomeAssistantType, config: ConfigType):
"""
conf = config.get(DOMAIN, {}) # type: ConfigType
server = await async_prepare_setup_platform(
hass, config, DOMAIN, 'server')
if server is None:
_LOGGER.error("Unable to load embedded server")
return None
success, broker_config = \
await server.async_start(
hass, conf.get(CONF_PASSWORD), conf.get(CONF_EMBEDDED))
@ -432,9 +423,6 @@ async def _async_setup_discovery(hass: HomeAssistantType, conf: ConfigType,
This method is a coroutine.
"""
discovery = await async_prepare_setup_platform(
hass, hass_config, DOMAIN, 'discovery')
if discovery is None:
_LOGGER.error("Unable to load MQTT discovery")
return False

View File

@ -2,3 +2,6 @@
CONF_BROKER = 'broker'
CONF_DISCOVERY = 'discovery'
DEFAULT_DISCOVERY = False
ATTR_DISCOVERY_HASH = 'discovery_hash'
CONF_STATE_TOPIC = 'state_topic'

View File

@ -10,7 +10,7 @@ from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.typing import HomeAssistantType
from . import ATTR_DISCOVERY_HASH, CONF_STATE_TOPIC
from .const import ATTR_DISCOVERY_HASH, CONF_STATE_TOPIC
_LOGGER = logging.getLogger(__name__)

View File

@ -1,6 +1,7 @@
"""Support to send and receive Telegram messages."""
import io
from functools import partial
import importlib
import logging
import requests
@ -14,7 +15,6 @@ from homeassistant.const import (
CONF_PLATFORM, CONF_TIMEOUT, HTTP_DIGEST_AUTHENTICATION)
import homeassistant.helpers.config_validation as cv
from homeassistant.exceptions import TemplateError
from homeassistant.setup import async_prepare_setup_platform
REQUIREMENTS = ['python-telegram-bot==11.1.0']
@ -76,7 +76,7 @@ PARSER_HTML = 'html'
PARSER_MD = 'markdown'
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
vol.Required(CONF_PLATFORM): cv.string,
vol.Required(CONF_PLATFORM): vol.In(('broadcast', 'polling', 'webhooks')),
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_ALLOWED_CHAT_IDS):
vol.All(cv.ensure_list, [vol.Coerce(int)]),
@ -219,11 +219,8 @@ async def async_setup(hass, config):
p_type = p_config.get(CONF_PLATFORM)
platform = await async_prepare_setup_platform(
hass, config, DOMAIN, p_type)
if platform is None:
return
platform = importlib.import_module('.{}'.format(config[CONF_PLATFORM]),
__name__)
_LOGGER.info("Setting up %s.%s", DOMAIN, p_type)
try:

View File

@ -5,6 +5,6 @@
"requirements": [
"python-telegram-bot==11.1.0"
],
"dependencies": [],
"dependencies": ["http"],
"codeowners": []
}

View File

@ -49,7 +49,6 @@ DATA_INTEGRATIONS = 'integrations'
PACKAGE_CUSTOM_COMPONENTS = 'custom_components'
PACKAGE_BUILTIN = 'homeassistant.components'
LOOKUP_PATHS = [PACKAGE_CUSTOM_COMPONENTS, PACKAGE_BUILTIN]
COMPONENTS_WITH_BAD_PLATFORMS = ['automation', 'mqtt', 'telegram_bot']
_UNDEF = object()
@ -224,11 +223,7 @@ def get_platform(hass, # type: HomeAssistant
"""
# If the platform has a component, we will limit the platform loading path
# to be the same source (custom/built-in).
if domain not in COMPONENTS_WITH_BAD_PLATFORMS:
component = _load_file(hass, platform_name, LOOKUP_PATHS)
else:
# avoid load component for legacy platform
component = None
# Until we have moved all platforms under their component/own folder, it
# can be that the component is None.
@ -244,14 +239,6 @@ def get_platform(hass, # type: HomeAssistant
if platform is not None:
return platform
# Legacy platform check for automation: components/automation/event.py
if component is None and domain in COMPONENTS_WITH_BAD_PLATFORMS:
platform = _load_file(
hass,
PLATFORM_FORMAT.format(domain=platform_name, platform=domain),
base_paths
)
# Legacy platform check for custom: custom_components/light/hue.py
# Only check if the component was also in custom components.
if component is None or base_paths[0] == PACKAGE_CUSTOM_COMPONENTS:
@ -270,7 +257,6 @@ def get_platform(hass, # type: HomeAssistant
_LOGGER.error("Unable to find platform %s.%s", platform_name, extra)
return None
if domain not in COMPONENTS_WITH_BAD_PLATFORMS:
_LOGGER.error(
"Integrations need to be in their own folder. Change %s/%s.py to "
"%s/%s.py. This will stop working soon.",

View File

@ -1,8 +1,17 @@
"""The tests for the webhook automation trigger."""
import pytest
from homeassistant.core import callback
from homeassistant.setup import async_setup_component
@pytest.fixture(autouse=True)
async def setup_http(hass):
"""Set up http."""
assert await async_setup_component(hass, 'http', {})
assert await async_setup_component(hass, 'webhook', {})
async def test_webhook_json(hass, aiohttp_client):
"""Test triggering with a JSON webhook."""
events = []