Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -167,6 +168,7 @@ async def _subscribe_topics(self):
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
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -155,6 +156,7 @@ def off_delay_listener(now):
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
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -116,6 +117,7 @@ async def _subscribe_topics(self):
"""(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
Expand Down
12 changes: 12 additions & 0 deletions homeassistant/components/mqtt/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -384,6 +385,7 @@ def render_template(msg, template_name):
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)
Expand All @@ -405,6 +407,7 @@ def handle_temperature_received(msg, template_name, attr):
_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(
Expand All @@ -416,6 +419,7 @@ def handle_current_temperature_received(msg):
)

@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")
Expand All @@ -425,6 +429,7 @@ def handle_target_temperature_received(msg):
)

@callback
@log_messages(self.hass, self.entity_id)
def handle_temperature_low_received(msg):
"""Handle target temperature low coming via MQTT."""
handle_temperature_received(
Expand All @@ -436,6 +441,7 @@ def handle_temperature_low_received(msg):
)

@callback
@log_messages(self.hass, self.entity_id)
def handle_temperature_high_received(msg):
"""Handle target temperature high coming via MQTT."""
handle_temperature_received(
Expand All @@ -458,6 +464,7 @@ def handle_mode_received(msg, template_name, attr, mode_list):
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(
Expand All @@ -467,6 +474,7 @@ def handle_current_mode_received(msg):
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(
Expand All @@ -479,6 +487,7 @@ def handle_fan_mode_received(msg):
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(
Expand Down Expand Up @@ -514,20 +523,23 @@ def handle_onoff_mode_received(msg, template_name, attr):
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")

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")

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)
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/mqtt/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -268,7 +269,8 @@ async def _subscribe_topics(self):
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:
Expand All @@ -287,6 +289,7 @@ def tilt_updated(msg):
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
Expand All @@ -311,6 +314,7 @@ def state_message_received(msg):
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
Expand Down Expand Up @@ -354,7 +358,7 @@ def position_message_received(msg):
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],
}

Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/mqtt/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -249,6 +250,7 @@ async def _subscribe_topics(self):
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)
Expand All @@ -266,6 +268,7 @@ def state_received(msg):
}

@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)
Expand All @@ -288,6 +291,7 @@ def speed_received(msg):
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)
Expand Down
9 changes: 9 additions & 0 deletions homeassistant/components/mqtt/light/schema_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
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__)
Expand Down Expand Up @@ -292,6 +293,7 @@ async def _subscribe_topics(self):
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)
Expand All @@ -315,6 +317,7 @@ def state_received(msg):
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)
Expand Down Expand Up @@ -346,6 +349,7 @@ def brightness_received(msg):
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)
Expand Down Expand Up @@ -377,6 +381,7 @@ def rgb_received(msg):
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)
Expand Down Expand Up @@ -406,6 +411,7 @@ def color_temp_received(msg):
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)
Expand Down Expand Up @@ -435,6 +441,7 @@ def effect_received(msg):
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)
Expand Down Expand Up @@ -466,6 +473,7 @@ def hs_received(msg):
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)
Expand Down Expand Up @@ -497,6 +505,7 @@ def white_value_received(msg):
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)
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/light/schema_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
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

Expand Down Expand Up @@ -234,6 +235,7 @@ async def _subscribe_topics(self):
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)
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/light/schema_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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__)
Expand Down Expand Up @@ -215,6 +216,7 @@ async def _subscribe_topics(self):
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[
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -156,6 +157,7 @@ async def _subscribe_topics(self):
value_template.hass = self.hass

@callback
@log_messages(self.hass, self.entity_id)
def message_received(msg):
"""Handle new MQTT messages."""
payload = msg.payload
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
MqttEntityDeviceInfo,
subscription,
)
from .debug_info import log_messages
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -162,6 +163,7 @@ async def _subscribe_topics(self):
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
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/vacuum/schema_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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__)
Expand Down Expand Up @@ -280,6 +281,7 @@ async def _subscribe_topics(self):
tpl.hass = self.hass

@callback
@log_messages(self.hass, self.entity_id)
def message_received(msg):
"""Handle new MQTT message."""
if (
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/vacuum/schema_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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__)
Expand Down Expand Up @@ -246,6 +247,7 @@ async def _subscribe_topics(self):
topics = {}

@callback
@log_messages(self.hass, self.entity_id)
def state_message_received(msg):
"""Handle state MQTT message."""
payload = msg.payload
Expand Down
Loading