Move imports in mqtt component (#27835)

* move imports to top-level in mqtt server

* move imports to top-level in mqtt configflow

* move imports to top-level in mqtt init

* move imports to top-level in mqtt vacuum

* move imports to top-level in mqtt light
This commit is contained in:
Malte Franken 2019-10-18 11:04:27 +11:00 committed by Paulus Schoutsen
parent 7637ceb880
commit 1a5b4c105a
19 changed files with 130 additions and 144 deletions

View file

@ -4,10 +4,14 @@ import logging
import tempfile
import voluptuous as vol
from hbmqtt.broker import Broker, BrokerException
from passlib.apps import custom_app_context
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
import homeassistant.helpers.config_validation as cv
from .const import PROTOCOL_311
_LOGGER = logging.getLogger(__name__)
# None allows custom config to be created through generate_config
@ -33,8 +37,6 @@ def async_start(hass, password, server_config):
This method is a coroutine.
"""
from hbmqtt.broker import Broker, BrokerException
passwd = tempfile.NamedTemporaryFile()
gen_server_config, client_config = generate_config(hass, passwd, password)
@ -63,8 +65,6 @@ def async_start(hass, password, server_config):
def generate_config(hass, passwd, password):
"""Generate a configuration based on current Home Assistant instance."""
from . import PROTOCOL_311
config = {
"listeners": {
"default": {
@ -83,8 +83,6 @@ def generate_config(hass, passwd, password):
username = "homeassistant"
# Encrypt with what hbmqtt uses to verify
from passlib.apps import custom_app_context
passwd.write(
"homeassistant:{}\n".format(custom_app_context.encrypt(password)).encode(
"utf-8"