Update additional platforms to use new MQTT message callback (#22030)

* Move additional platforms to new MQTT callback

* Fix automation.mqtt
This commit is contained in:
emontnemery authored and Paulus Schoutsen committed 2019-03-14 10:58:32 -07:00
1 parent 8d2d71c16a
commit b25e951dcc
8 files changed
+32 -32

No files matched your search

+3 -3
View File
@@ -61,7 +61,7 @@ async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the ARWN platform."""
@callback
def async_sensor_event_received(topic, payload, qos):
def async_sensor_event_received(msg):
"""Process events as sensors.
When a new event on our topic (arwn/#) is received we map it
@@ -74,8 +74,8 @@ async def async_setup_platform(hass, config, async_add_entities,
This lets us dynamically incorporate sensors without any
configuration on our side.
"""
event = json.loads(payload)
sensors = discover_sensors(topic, event)
event = json.loads(msg.payload)
sensors = discover_sensors(msg.topic, event)
if not sensors:
return
+3 -3
View File
@@ -90,16 +90,16 @@ class MQTTRoomSensor(Entity):
self.async_schedule_update_ha_state()
@callback
def message_received(topic, payload, qos):
def message_received(msg):
"""Handle new MQTT messages."""
try:
data = MQTT_PAYLOAD(payload)
data = MQTT_PAYLOAD(msg.payload)
except vol.MultipleInvalid as error:
_LOGGER.debug(
"Skipping update because of malformatted data: %s", error)
return
device = _parse_update_data(topic, data)
device = _parse_update_data(msg.topic, data)
if device.get(CONF_DEVICE_ID) == self._device_id:
if self._distance is None or self._updated is None:
update_state(**device)