1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Pass Message object to MQTT message callbacks (#21959)

* Pass Message object to MQTT message callbacks

* Improve method of detecting deprecated msg callback

* Fix mysensors

* Fixup

* Review comments

* Fix merge error
This commit is contained in:
emontnemery
2019-03-13 20:58:20 +01:00
committed by Paulus Schoutsen
parent 50ec3d7de5
commit 5957e4b75b
19 changed files with 203 additions and 142 deletions

View File

@@ -212,9 +212,9 @@ class MqttFan(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
templates[key] = tpl.async_render_with_possible_json_value
@callback
def state_received(topic, payload, qos):
def state_received(msg):
"""Handle new received MQTT message."""
payload = templates[CONF_STATE](payload)
payload = templates[CONF_STATE](msg.payload)
if payload == self._payload[STATE_ON]:
self._state = True
elif payload == self._payload[STATE_OFF]:
@@ -228,9 +228,9 @@ class MqttFan(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
'qos': self._config.get(CONF_QOS)}
@callback
def speed_received(topic, payload, qos):
def speed_received(msg):
"""Handle new received MQTT message for the speed."""
payload = templates[ATTR_SPEED](payload)
payload = templates[ATTR_SPEED](msg.payload)
if payload == self._payload[SPEED_LOW]:
self._speed = SPEED_LOW
elif payload == self._payload[SPEED_MEDIUM]:
@@ -247,9 +247,9 @@ class MqttFan(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
self._speed = SPEED_OFF
@callback
def oscillation_received(topic, payload, qos):
def oscillation_received(msg):
"""Handle new received MQTT message for the oscillation."""
payload = templates[OSCILLATION](payload)
payload = templates[OSCILLATION](msg.payload)
if payload == self._payload[OSCILLATE_ON_PAYLOAD]:
self._oscillation = True
elif payload == self._payload[OSCILLATE_OFF_PAYLOAD]: