Upgrade paho-mqtt to 1.4.0 (#16688)
This commit is contained in:
parent
d2246d5a4f
commit
cba3a5b055
7 changed files with 52 additions and 65 deletions
|
@ -6,40 +6,40 @@ https://home-assistant.io/components/mqtt/
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
from typing import Optional, Any, Union, Callable, List, cast # noqa: F401
|
|
||||||
from operator import attrgetter
|
|
||||||
import logging
|
import logging
|
||||||
|
from operator import attrgetter
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import time
|
|
||||||
import ssl
|
import ssl
|
||||||
import requests.certs
|
import time
|
||||||
import attr
|
from typing import Any, Callable, List, Optional, Union, cast # noqa: F401
|
||||||
|
|
||||||
|
import attr
|
||||||
|
import requests.certs
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.helpers.typing import HomeAssistantType, ConfigType, \
|
|
||||||
ServiceDataType
|
|
||||||
from homeassistant.core import callback, Event, ServiceCall
|
|
||||||
from homeassistant.setup import async_prepare_setup_platform
|
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
|
||||||
from homeassistant.loader import bind_hass
|
|
||||||
from homeassistant.helpers import template, config_validation as cv
|
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.util.async_ import (
|
|
||||||
run_coroutine_threadsafe, run_callback_threadsafe)
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_STOP, CONF_VALUE_TEMPLATE, CONF_USERNAME,
|
CONF_PASSWORD, CONF_PAYLOAD, CONF_PORT, CONF_PROTOCOL, CONF_USERNAME,
|
||||||
CONF_PASSWORD, CONF_PORT, CONF_PROTOCOL, CONF_PAYLOAD,
|
CONF_VALUE_TEMPLATE, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
||||||
EVENT_HOMEASSISTANT_START)
|
from homeassistant.core import Event, ServiceCall, callback
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
from homeassistant.helpers import template
|
||||||
|
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)
|
||||||
|
|
||||||
# Loading the config flow file will register the flow
|
# Loading the config flow file will register the flow
|
||||||
from . import config_flow # noqa # pylint: disable=unused-import
|
from . import config_flow # noqa # pylint: disable=unused-import
|
||||||
from .const import CONF_BROKER
|
from .const import CONF_BROKER
|
||||||
from .server import HBMQTT_CONFIG_SCHEMA
|
from .server import HBMQTT_CONFIG_SCHEMA
|
||||||
|
|
||||||
REQUIREMENTS = ['paho-mqtt==1.3.1']
|
REQUIREMENTS = ['paho-mqtt==1.4.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -296,8 +296,7 @@ def subscribe(hass: HomeAssistantType, topic: str,
|
||||||
return remove
|
return remove
|
||||||
|
|
||||||
|
|
||||||
async def _async_setup_server(hass: HomeAssistantType,
|
async def _async_setup_server(hass: HomeAssistantType, config: ConfigType):
|
||||||
config: ConfigType):
|
|
||||||
"""Try to start embedded MQTT broker.
|
"""Try to start embedded MQTT broker.
|
||||||
|
|
||||||
This method is a coroutine.
|
This method is a coroutine.
|
||||||
|
@ -366,7 +365,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
|
||||||
broker_config = await _async_setup_server(hass, config)
|
broker_config = await _async_setup_server(hass, config)
|
||||||
|
|
||||||
if broker_config is None:
|
if broker_config is None:
|
||||||
_LOGGER.error('Unable to start embedded MQTT broker')
|
_LOGGER.error("Unable to start embedded MQTT broker")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
conf.update({
|
conf.update({
|
||||||
|
@ -418,8 +417,8 @@ async def async_setup_entry(hass, entry):
|
||||||
})[DOMAIN]
|
})[DOMAIN]
|
||||||
elif any(key in conf for key in entry.data):
|
elif any(key in conf for key in entry.data):
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
'Data in your config entry is going to override your '
|
"Data in your config entry is going to override your "
|
||||||
'configuration.yaml: %s', entry.data)
|
"configuration.yaml: %s", entry.data)
|
||||||
|
|
||||||
conf.update(entry.data)
|
conf.update(entry.data)
|
||||||
|
|
||||||
|
@ -438,8 +437,8 @@ async def async_setup_entry(hass, entry):
|
||||||
if (conf.get(CONF_CERTIFICATE) is None and
|
if (conf.get(CONF_CERTIFICATE) is None and
|
||||||
19999 < conf[CONF_PORT] < 30000 and
|
19999 < conf[CONF_PORT] < 30000 and
|
||||||
conf[CONF_BROKER].endswith('.cloudmqtt.com')):
|
conf[CONF_BROKER].endswith('.cloudmqtt.com')):
|
||||||
certificate = os.path.join(os.path.dirname(__file__),
|
certificate = os.path.join(
|
||||||
'addtrustexternalcaroot.crt')
|
os.path.dirname(__file__), 'addtrustexternalcaroot.crt')
|
||||||
|
|
||||||
# When the certificate is set to auto, use bundled certs from requests
|
# When the certificate is set to auto, use bundled certs from requests
|
||||||
elif conf.get(CONF_CERTIFICATE) == 'auto':
|
elif conf.get(CONF_CERTIFICATE) == 'auto':
|
||||||
|
@ -623,12 +622,12 @@ class MQTT:
|
||||||
result = await self.hass.async_add_job(
|
result = await self.hass.async_add_job(
|
||||||
self._mqttc.connect, self.broker, self.port, self.keepalive)
|
self._mqttc.connect, self.broker, self.port, self.keepalive)
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
_LOGGER.error('Failed to connect due to exception: %s', err)
|
_LOGGER.error("Failed to connect due to exception: %s", err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if result != 0:
|
if result != 0:
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
_LOGGER.error('Failed to connect: %s', mqtt.error_string(result))
|
_LOGGER.error("Failed to connect: %s", mqtt.error_string(result))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self._mqttc.loop_start()
|
self._mqttc.loop_start()
|
||||||
|
@ -655,7 +654,7 @@ class MQTT:
|
||||||
This method is a coroutine.
|
This method is a coroutine.
|
||||||
"""
|
"""
|
||||||
if not isinstance(topic, str):
|
if not isinstance(topic, str):
|
||||||
raise HomeAssistantError("topic needs to be a string!")
|
raise HomeAssistantError("Topic needs to be a string!")
|
||||||
|
|
||||||
subscription = Subscription(topic, msg_callback, qos, encoding)
|
subscription = Subscription(topic, msg_callback, qos, encoding)
|
||||||
self.subscriptions.append(subscription)
|
self.subscriptions.append(subscription)
|
||||||
|
@ -697,8 +696,8 @@ class MQTT:
|
||||||
self._mqttc.subscribe, topic, qos)
|
self._mqttc.subscribe, topic, qos)
|
||||||
_raise_on_error(result)
|
_raise_on_error(result)
|
||||||
|
|
||||||
def _mqtt_on_connect(self, _mqttc, _userdata, _flags,
|
def _mqtt_on_connect(
|
||||||
result_code: int) -> None:
|
self, _mqttc, _userdata, _flags, result_code: int) -> None:
|
||||||
"""On connect callback.
|
"""On connect callback.
|
||||||
|
|
||||||
Resubscribe to all topics we were subscribed to and publish birth
|
Resubscribe to all topics we were subscribed to and publish birth
|
||||||
|
@ -707,7 +706,7 @@ class MQTT:
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
if result_code != mqtt.CONNACK_ACCEPTED:
|
if result_code != mqtt.CONNACK_ACCEPTED:
|
||||||
_LOGGER.error('Unable to connect to the MQTT broker: %s',
|
_LOGGER.error("Unable to connect to the MQTT broker: %s",
|
||||||
mqtt.connack_string(result_code))
|
mqtt.connack_string(result_code))
|
||||||
self._mqttc.disconnect()
|
self._mqttc.disconnect()
|
||||||
return
|
return
|
||||||
|
@ -741,14 +740,13 @@ class MQTT:
|
||||||
try:
|
try:
|
||||||
payload = msg.payload.decode(subscription.encoding)
|
payload = msg.payload.decode(subscription.encoding)
|
||||||
except (AttributeError, UnicodeDecodeError):
|
except (AttributeError, UnicodeDecodeError):
|
||||||
_LOGGER.warning("Can't decode payload %s on %s "
|
_LOGGER.warning(
|
||||||
"with encoding %s",
|
"Can't decode payload %s on %s with encoding %s",
|
||||||
msg.payload, msg.topic,
|
msg.payload, msg.topic, subscription.encoding)
|
||||||
subscription.encoding)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.hass.async_run_job(subscription.callback,
|
self.hass.async_run_job(
|
||||||
msg.topic, payload, msg.qos)
|
subscription.callback, msg.topic, payload, msg.qos)
|
||||||
|
|
||||||
def _mqtt_on_disconnect(self, _mqttc, _userdata, result_code: int) -> None:
|
def _mqtt_on_disconnect(self, _mqttc, _userdata, result_code: int) -> None:
|
||||||
"""Disconnected callback."""
|
"""Disconnected callback."""
|
||||||
|
@ -810,7 +808,7 @@ class MqttAvailability(Entity):
|
||||||
self._payload_not_available = payload_not_available
|
self._payload_not_available = payload_not_available
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe mqtt events.
|
"""Subscribe MQTT events.
|
||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -5,7 +5,7 @@ import queue
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_PORT
|
from homeassistant.const import CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||||
|
|
||||||
from .const import CONF_BROKER
|
from .const import CONF_BROKER
|
||||||
|
|
||||||
|
@ -20,14 +20,12 @@ class FlowHandler(config_entries.ConfigFlow):
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
return self.async_abort(
|
return self.async_abort(reason='single_instance_allowed')
|
||||||
reason='single_instance_allowed'
|
|
||||||
)
|
|
||||||
|
|
||||||
return await self.async_step_broker()
|
return await self.async_step_broker()
|
||||||
|
|
||||||
async def async_step_broker(self, user_input=None):
|
async def async_step_broker(self, user_input=None):
|
||||||
"""Confirm setup."""
|
"""Confirm the setup."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
|
@ -37,9 +35,7 @@ class FlowHandler(config_entries.ConfigFlow):
|
||||||
|
|
||||||
if can_connect:
|
if can_connect:
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input[CONF_BROKER],
|
title=user_input[CONF_BROKER], data=user_input)
|
||||||
data=user_input
|
|
||||||
)
|
|
||||||
|
|
||||||
errors['base'] = 'cannot_connect'
|
errors['base'] = 'cannot_connect'
|
||||||
|
|
||||||
|
@ -50,10 +46,7 @@ class FlowHandler(config_entries.ConfigFlow):
|
||||||
fields[vol.Optional(CONF_PASSWORD)] = str
|
fields[vol.Optional(CONF_PASSWORD)] = str
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id='broker',
|
step_id='broker', data_schema=vol.Schema(fields), errors=errors)
|
||||||
data_schema=vol.Schema(fields),
|
|
||||||
errors=errors,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_step_import(self, user_input):
|
async def async_step_import(self, user_input):
|
||||||
"""Import a config entry.
|
"""Import a config entry.
|
||||||
|
@ -62,14 +55,9 @@ class FlowHandler(config_entries.ConfigFlow):
|
||||||
Instead, we're going to rely on the values that are in config file.
|
Instead, we're going to rely on the values that are in config file.
|
||||||
"""
|
"""
|
||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
return self.async_abort(
|
return self.async_abort(reason='single_instance_allowed')
|
||||||
reason='single_instance_allowed'
|
|
||||||
)
|
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(title='configuration.yaml', data={})
|
||||||
title='configuration.yaml',
|
|
||||||
data={}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def try_connection(broker, port, username, password):
|
def try_connection(broker, port, username, password):
|
||||||
|
|
|
@ -9,9 +9,9 @@ import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from homeassistant.components import mqtt
|
from homeassistant.components import mqtt
|
||||||
from homeassistant.helpers.discovery import async_load_platform
|
|
||||||
from homeassistant.const import CONF_PLATFORM
|
|
||||||
from homeassistant.components.mqtt import CONF_STATE_TOPIC
|
from homeassistant.components.mqtt import CONF_STATE_TOPIC
|
||||||
|
from homeassistant.const import CONF_PLATFORM
|
||||||
|
from homeassistant.helpers.discovery import async_load_platform
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@ from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['hbmqtt==0.9.4']
|
REQUIREMENTS = ['hbmqtt==0.9.4']
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['http']
|
DEPENDENCIES = ['http']
|
||||||
|
|
||||||
# None allows custom config to be created through generate_config
|
# None allows custom config to be created through generate_config
|
||||||
|
@ -27,8 +30,6 @@ HBMQTT_CONFIG_SCHEMA = vol.Any(None, vol.Schema({
|
||||||
})
|
})
|
||||||
}, extra=vol.ALLOW_EXTRA))
|
}, extra=vol.ALLOW_EXTRA))
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_start(hass, password, server_config):
|
def async_start(hass, password, server_config):
|
||||||
|
|
|
@ -14,7 +14,7 @@ from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_STOP)
|
EVENT_HOMEASSISTANT_STOP)
|
||||||
from homeassistant.helpers import state as state_helper
|
from homeassistant.helpers import state as state_helper
|
||||||
|
|
||||||
REQUIREMENTS = ['paho-mqtt==1.3.1']
|
REQUIREMENTS = ['paho-mqtt==1.4.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -660,7 +660,7 @@ orvibo==1.1.1
|
||||||
|
|
||||||
# homeassistant.components.mqtt
|
# homeassistant.components.mqtt
|
||||||
# homeassistant.components.shiftr
|
# homeassistant.components.shiftr
|
||||||
paho-mqtt==1.3.1
|
paho-mqtt==1.4.0
|
||||||
|
|
||||||
# homeassistant.components.media_player.panasonic_viera
|
# homeassistant.components.media_player.panasonic_viera
|
||||||
panasonic_viera==0.3.1
|
panasonic_viera==0.3.1
|
||||||
|
|
|
@ -112,7 +112,7 @@ numpy==1.15.1
|
||||||
|
|
||||||
# homeassistant.components.mqtt
|
# homeassistant.components.mqtt
|
||||||
# homeassistant.components.shiftr
|
# homeassistant.components.shiftr
|
||||||
paho-mqtt==1.3.1
|
paho-mqtt==1.4.0
|
||||||
|
|
||||||
# homeassistant.components.device_tracker.aruba
|
# homeassistant.components.device_tracker.aruba
|
||||||
# homeassistant.components.device_tracker.asuswrt
|
# homeassistant.components.device_tracker.asuswrt
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue