Add MQTT debug info for remaining MQTT integrations (#33506)

pull/33508/head
Erik Montnemery 2020-04-01 20:48:32 +02:00 committed by GitHub
parent c63ec698a1
commit fbd197146a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 170 additions and 2 deletions

View File

@ -41,6 +41,7 @@ from . import (
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
_LOGGER = logging.getLogger(__name__)
@ -167,6 +168,7 @@ class MqttAlarm(
command_template.hass = self.hass
@callback
@log_messages(self.hass, self.entity_id)
def message_received(msg):
"""Run when new MQTT message has been received."""
payload = msg.payload

View File

@ -37,6 +37,7 @@ from . import (
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
_LOGGER = logging.getLogger(__name__)
@ -155,6 +156,7 @@ class MqttBinarySensor(
self.async_write_ha_state()
@callback
@log_messages(self.hass, self.entity_id)
def state_message_received(msg):
"""Handle a new received MQTT state message."""
payload = msg.payload

View File

@ -21,6 +21,7 @@ from . import (
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
_LOGGER = logging.getLogger(__name__)
@ -116,6 +117,7 @@ class MqttCamera(
"""(Re)Subscribe to topics."""
@callback
@log_messages(self.hass, self.entity_id)
def message_received(msg):
"""Handle new MQTT messages."""
self._last_image = msg.payload

View File

@ -60,6 +60,7 @@ from . import (
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
_LOGGER = logging.getLogger(__name__)
@ -384,6 +385,7 @@ class MqttClimate(
return template(msg.payload)
@callback
@log_messages(self.hass, self.entity_id)
def handle_action_received(msg):
"""Handle receiving action via MQTT."""
payload = render_template(msg, CONF_ACTION_TEMPLATE)
@ -405,6 +407,7 @@ class MqttClimate(
_LOGGER.error("Could not parse temperature from %s", payload)
@callback
@log_messages(self.hass, self.entity_id)
def handle_current_temperature_received(msg):
"""Handle current temperature coming via MQTT."""
handle_temperature_received(
@ -416,6 +419,7 @@ class MqttClimate(
)
@callback
@log_messages(self.hass, self.entity_id)
def handle_target_temperature_received(msg):
"""Handle target temperature coming via MQTT."""
handle_temperature_received(msg, CONF_TEMP_STATE_TEMPLATE, "_target_temp")
@ -425,6 +429,7 @@ class MqttClimate(
)
@callback
@log_messages(self.hass, self.entity_id)
def handle_temperature_low_received(msg):
"""Handle target temperature low coming via MQTT."""
handle_temperature_received(
@ -436,6 +441,7 @@ class MqttClimate(
)
@callback
@log_messages(self.hass, self.entity_id)
def handle_temperature_high_received(msg):
"""Handle target temperature high coming via MQTT."""
handle_temperature_received(
@ -458,6 +464,7 @@ class MqttClimate(
self.async_write_ha_state()
@callback
@log_messages(self.hass, self.entity_id)
def handle_current_mode_received(msg):
"""Handle receiving mode via MQTT."""
handle_mode_received(
@ -467,6 +474,7 @@ class MqttClimate(
add_subscription(topics, CONF_MODE_STATE_TOPIC, handle_current_mode_received)
@callback
@log_messages(self.hass, self.entity_id)
def handle_fan_mode_received(msg):
"""Handle receiving fan mode via MQTT."""
handle_mode_received(
@ -479,6 +487,7 @@ class MqttClimate(
add_subscription(topics, CONF_FAN_MODE_STATE_TOPIC, handle_fan_mode_received)
@callback
@log_messages(self.hass, self.entity_id)
def handle_swing_mode_received(msg):
"""Handle receiving swing mode via MQTT."""
handle_mode_received(
@ -514,6 +523,7 @@ class MqttClimate(
self.async_write_ha_state()
@callback
@log_messages(self.hass, self.entity_id)
def handle_away_mode_received(msg):
"""Handle receiving away mode via MQTT."""
handle_onoff_mode_received(msg, CONF_AWAY_MODE_STATE_TEMPLATE, "_away")
@ -521,6 +531,7 @@ class MqttClimate(
add_subscription(topics, CONF_AWAY_MODE_STATE_TOPIC, handle_away_mode_received)
@callback
@log_messages(self.hass, self.entity_id)
def handle_aux_mode_received(msg):
"""Handle receiving aux mode via MQTT."""
handle_onoff_mode_received(msg, CONF_AUX_STATE_TEMPLATE, "_aux")
@ -528,6 +539,7 @@ class MqttClimate(
add_subscription(topics, CONF_AUX_STATE_TOPIC, handle_aux_mode_received)
@callback
@log_messages(self.hass, self.entity_id)
def handle_hold_mode_received(msg):
"""Handle receiving hold mode via MQTT."""
payload = render_template(msg, CONF_HOLD_STATE_TEMPLATE)

View File

@ -49,6 +49,7 @@ from . import (
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
_LOGGER = logging.getLogger(__name__)
@ -268,7 +269,8 @@ class MqttCover(
topics = {}
@callback
def tilt_updated(msg):
@log_messages(self.hass, self.entity_id)
def tilt_message_received(msg):
"""Handle tilt updates."""
payload = msg.payload
if tilt_status_template is not None:
@ -287,6 +289,7 @@ class MqttCover(
self.async_write_ha_state()
@callback
@log_messages(self.hass, self.entity_id)
def state_message_received(msg):
"""Handle new MQTT state messages."""
payload = msg.payload
@ -311,6 +314,7 @@ class MqttCover(
self.async_write_ha_state()
@callback
@log_messages(self.hass, self.entity_id)
def position_message_received(msg):
"""Handle new MQTT state messages."""
payload = msg.payload
@ -354,7 +358,7 @@ class MqttCover(
self._tilt_value = STATE_UNKNOWN
topics["tilt_status_topic"] = {
"topic": self._config.get(CONF_TILT_STATUS_TOPIC),
"msg_callback": tilt_updated,
"msg_callback": tilt_message_received,
"qos": self._config[CONF_QOS],
}

View File

@ -40,6 +40,7 @@ from . import (
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
_LOGGER = logging.getLogger(__name__)
@ -249,6 +250,7 @@ class MqttFan(
templates[key] = tpl.async_render_with_possible_json_value
@callback
@log_messages(self.hass, self.entity_id)
def state_received(msg):
"""Handle new received MQTT message."""
payload = templates[CONF_STATE](msg.payload)
@ -266,6 +268,7 @@ class MqttFan(
}
@callback
@log_messages(self.hass, self.entity_id)
def speed_received(msg):
"""Handle new received MQTT message for the speed."""
payload = templates[ATTR_SPEED](msg.payload)
@ -288,6 +291,7 @@ class MqttFan(
self._speed = SPEED_OFF
@callback
@log_messages(self.hass, self.entity_id)
def oscillation_received(msg):
"""Handle new received MQTT message for the oscillation."""
payload = templates[OSCILLATION](msg.payload)

View File

@ -51,6 +51,7 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.util.color as color_util
from ..debug_info import log_messages
from .schema import MQTT_LIGHT_SCHEMA_SCHEMA
_LOGGER = logging.getLogger(__name__)
@ -292,6 +293,7 @@ class MqttLight(
last_state = await self.async_get_last_state()
@callback
@log_messages(self.hass, self.entity_id)
def state_received(msg):
"""Handle new MQTT messages."""
payload = templates[CONF_STATE](msg.payload)
@ -315,6 +317,7 @@ class MqttLight(
self._state = last_state.state == STATE_ON
@callback
@log_messages(self.hass, self.entity_id)
def brightness_received(msg):
"""Handle new MQTT messages for the brightness."""
payload = templates[CONF_BRIGHTNESS](msg.payload)
@ -346,6 +349,7 @@ class MqttLight(
self._brightness = None
@callback
@log_messages(self.hass, self.entity_id)
def rgb_received(msg):
"""Handle new MQTT messages for RGB."""
payload = templates[CONF_RGB](msg.payload)
@ -377,6 +381,7 @@ class MqttLight(
self._hs = (0, 0)
@callback
@log_messages(self.hass, self.entity_id)
def color_temp_received(msg):
"""Handle new MQTT messages for color temperature."""
payload = templates[CONF_COLOR_TEMP](msg.payload)
@ -406,6 +411,7 @@ class MqttLight(
self._color_temp = None
@callback
@log_messages(self.hass, self.entity_id)
def effect_received(msg):
"""Handle new MQTT messages for effect."""
payload = templates[CONF_EFFECT](msg.payload)
@ -435,6 +441,7 @@ class MqttLight(
self._effect = None
@callback
@log_messages(self.hass, self.entity_id)
def hs_received(msg):
"""Handle new MQTT messages for hs color."""
payload = templates[CONF_HS](msg.payload)
@ -466,6 +473,7 @@ class MqttLight(
self._hs = (0, 0)
@callback
@log_messages(self.hass, self.entity_id)
def white_value_received(msg):
"""Handle new MQTT messages for white value."""
payload = templates[CONF_WHITE_VALUE](msg.payload)
@ -497,6 +505,7 @@ class MqttLight(
self._white_value = None
@callback
@log_messages(self.hass, self.entity_id)
def xy_received(msg):
"""Handle new MQTT messages for xy color."""
payload = templates[CONF_XY](msg.payload)

View File

@ -54,6 +54,7 @@ from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType
import homeassistant.util.color as color_util
from ..debug_info import log_messages
from .schema import MQTT_LIGHT_SCHEMA_SCHEMA
from .schema_basic import CONF_BRIGHTNESS_SCALE
@ -234,6 +235,7 @@ class MqttLightJson(
last_state = await self.async_get_last_state()
@callback
@log_messages(self.hass, self.entity_id)
def state_received(msg):
"""Handle new MQTT messages."""
values = json.loads(msg.payload)

View File

@ -45,6 +45,7 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.util.color as color_util
from ..debug_info import log_messages
from .schema import MQTT_LIGHT_SCHEMA_SCHEMA
_LOGGER = logging.getLogger(__name__)
@ -215,6 +216,7 @@ class MqttTemplate(
last_state = await self.async_get_last_state()
@callback
@log_messages(self.hass, self.entity_id)
def state_received(msg):
"""Handle new MQTT messages."""
state = self._templates[

View File

@ -29,6 +29,7 @@ from . import (
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
_LOGGER = logging.getLogger(__name__)
@ -156,6 +157,7 @@ class MqttLock(
value_template.hass = self.hass
@callback
@log_messages(self.hass, self.entity_id)
def message_received(msg):
"""Handle new MQTT messages."""
payload = msg.payload

View File

@ -34,6 +34,7 @@ from . import (
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
_LOGGER = logging.getLogger(__name__)
@ -162,6 +163,7 @@ class MqttSwitch(
template.hass = self.hass
@callback
@log_messages(self.hass, self.entity_id)
def state_message_received(msg):
"""Handle new MQTT state messages."""
payload = msg.payload

View File

@ -32,6 +32,7 @@ from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.icon import icon_for_battery_level
from ..debug_info import log_messages
from .schema import MQTT_VACUUM_SCHEMA, services_to_strings, strings_to_services
_LOGGER = logging.getLogger(__name__)
@ -280,6 +281,7 @@ class MqttVacuum(
tpl.hass = self.hass
@callback
@log_messages(self.hass, self.entity_id)
def message_received(msg):
"""Handle new MQTT message."""
if (

View File

@ -45,6 +45,7 @@ from homeassistant.const import (
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from ..debug_info import log_messages
from .schema import MQTT_VACUUM_SCHEMA, services_to_strings, strings_to_services
_LOGGER = logging.getLogger(__name__)
@ -246,6 +247,7 @@ class MqttStateVacuum(
topics = {}
@callback
@log_messages(self.hass, self.entity_id)
def state_message_received(msg):
"""Handle state MQTT message."""
payload = msg.payload

View File

@ -21,6 +21,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -494,3 +495,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, alarm_control_panel.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, alarm_control_panel.DOMAIN, DEFAULT_CONFIG
)

View File

@ -23,6 +23,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -508,3 +509,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, binary_sensor.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, binary_sensor.DOMAIN, DEFAULT_CONFIG
)

View File

@ -13,6 +13,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -207,3 +208,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG, "test_topic", b"ON"
)

View File

@ -33,6 +33,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -908,6 +909,20 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
config = {
CLIMATE_DOMAIN: {
"platform": "mqtt",
"name": "test",
"mode_state_topic": "test-topic",
}
}
await help_test_entity_debug_info_message(
hass, mqtt_mock, CLIMATE_DOMAIN, config, "test-topic"
)
async def test_precision_default(hass, mqtt_mock):
"""Test that setting precision to tenths works as intended."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)

View File

@ -30,6 +30,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -1762,3 +1763,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, cover.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, cover.DOMAIN, DEFAULT_CONFIG
)

View File

@ -11,6 +11,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -509,3 +510,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, fan.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, fan.DOMAIN, DEFAULT_CONFIG
)

View File

@ -27,6 +27,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -629,3 +630,20 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, vacuum.DOMAIN, DEFAULT_CONFIG_2
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
config = {
vacuum.DOMAIN: {
"platform": "mqtt",
"name": "test",
"battery_level_topic": "test-topic",
"battery_level_template": "{{ value_json.battery_level }}",
"command_topic": "command-topic",
"availability_topic": "avty-topic",
}
}
await help_test_entity_debug_info_message(
hass, mqtt_mock, vacuum.DOMAIN, config, "test-topic"
)

View File

@ -170,6 +170,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -1358,3 +1359,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
)

View File

@ -109,6 +109,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -1134,3 +1135,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
)

View File

@ -46,6 +46,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -957,3 +958,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
)

View File

@ -11,6 +11,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -399,3 +400,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, lock.DOMAIN, DEFAULT_CONFIG
)

View File

@ -38,6 +38,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -454,3 +455,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, vacuum.DOMAIN, DEFAULT_CONFIG_2
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, vacuum.DOMAIN, DEFAULT_CONFIG_2
)

View File

@ -15,6 +15,7 @@ from .test_common import (
help_test_discovery_removal,
help_test_discovery_update,
help_test_discovery_update_attr,
help_test_entity_debug_info_message,
help_test_entity_device_info_remove,
help_test_entity_device_info_update,
help_test_entity_device_info_with_connection,
@ -366,3 +367,10 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG
)