Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -11,15 +11,20 @@ import homeassistant.helpers.config_validation as cv
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# None allows custom config to be created through generate_config
|
||||
HBMQTT_CONFIG_SCHEMA = vol.Any(None, vol.Schema({
|
||||
vol.Optional('auth'): vol.Schema({
|
||||
vol.Optional('password-file'): cv.isfile,
|
||||
}, extra=vol.ALLOW_EXTRA),
|
||||
vol.Optional('listeners'): vol.Schema({
|
||||
vol.Required('default'): vol.Schema(dict),
|
||||
str: vol.Schema(dict)
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA))
|
||||
HBMQTT_CONFIG_SCHEMA = vol.Any(
|
||||
None,
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional("auth"): vol.Schema(
|
||||
{vol.Optional("password-file"): cv.isfile}, extra=vol.ALLOW_EXTRA
|
||||
),
|
||||
vol.Optional("listeners"): vol.Schema(
|
||||
{vol.Required("default"): vol.Schema(dict), str: vol.Schema(dict)}
|
||||
),
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
@ -51,8 +56,7 @@ def async_start(hass, password, server_config):
|
|||
"""Shut down the MQTT server."""
|
||||
yield from broker.shutdown()
|
||||
|
||||
hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP, async_shutdown_mqtt_server)
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_shutdown_mqtt_server)
|
||||
|
||||
return True, client_config
|
||||
|
||||
|
@ -62,43 +66,37 @@ def generate_config(hass, passwd, password):
|
|||
from . import PROTOCOL_311
|
||||
|
||||
config = {
|
||||
'listeners': {
|
||||
'default': {
|
||||
'max-connections': 50000,
|
||||
'bind': '0.0.0.0:1883',
|
||||
'type': 'tcp',
|
||||
},
|
||||
'ws-1': {
|
||||
'bind': '0.0.0.0:8080',
|
||||
'type': 'ws',
|
||||
"listeners": {
|
||||
"default": {
|
||||
"max-connections": 50000,
|
||||
"bind": "0.0.0.0:1883",
|
||||
"type": "tcp",
|
||||
},
|
||||
"ws-1": {"bind": "0.0.0.0:8080", "type": "ws"},
|
||||
},
|
||||
'auth': {
|
||||
'allow-anonymous': password is None
|
||||
},
|
||||
'plugins': ['auth_anonymous'],
|
||||
'topic-check': {
|
||||
'enabled': True,
|
||||
'plugins': ['topic_taboo'],
|
||||
},
|
||||
"auth": {"allow-anonymous": password is None},
|
||||
"plugins": ["auth_anonymous"],
|
||||
"topic-check": {"enabled": True, "plugins": ["topic_taboo"]},
|
||||
}
|
||||
|
||||
if password:
|
||||
username = 'homeassistant'
|
||||
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'))
|
||||
"homeassistant:{}\n".format(custom_app_context.encrypt(password)).encode(
|
||||
"utf-8"
|
||||
)
|
||||
)
|
||||
passwd.flush()
|
||||
|
||||
config['auth']['password-file'] = passwd.name
|
||||
config['plugins'].append('auth_file')
|
||||
config["auth"]["password-file"] = passwd.name
|
||||
config["plugins"].append("auth_file")
|
||||
else:
|
||||
username = None
|
||||
|
||||
client_config = ('localhost', 1883, username, password, None, PROTOCOL_311)
|
||||
client_config = ("localhost", 1883, username, password, None, PROTOCOL_311)
|
||||
|
||||
return config, client_config
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue