Fix MQTT async_added_to_hass (#18575)

* Fix some invocations

* Update manual_mqtt.py
This commit is contained in:
Paulus Schoutsen 2018-11-19 20:48:26 +01:00 committed by Pascal Vizeli
parent 3891f2eebe
commit f86083cf52
2 changed files with 5 additions and 9 deletions

View file

@ -335,11 +335,8 @@ class ManualMQTTAlarm(alarm.AlarmControlPanel):
return state_attr
def async_added_to_hass(self):
"""Subscribe to MQTT events.
This method must be run in the event loop and returns a coroutine.
"""
async def async_added_to_hass(self):
"""Subscribe to MQTT events."""
async_track_state_change(
self.hass, self.entity_id, self._async_state_changed_listener
)
@ -359,7 +356,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanel):
_LOGGER.warning("Received unexpected payload: %s", payload)
return
return mqtt.async_subscribe(
await mqtt.async_subscribe(
self.hass, self._command_topic, message_received, self._qos)
async def _async_state_changed_listener(self, entity_id, old_state,

View file

@ -89,13 +89,12 @@ class MqttCamera(Camera):
"""Return a unique ID."""
return self._unique_id
@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Subscribe MQTT events."""
@callback
def message_received(topic, payload, qos):
"""Handle new MQTT messages."""
self._last_image = payload
return mqtt.async_subscribe(
await mqtt.async_subscribe(
self.hass, self._topic, message_received, self._qos, None)