Skip to content

Commit

Permalink
Fix MQTT async_added_to_hass (#18575)
Browse files Browse the repository at this point in the history
* Fix some invocations

* Update manual_mqtt.py
  • Loading branch information
balloob authored and pvizeli committed Nov 19, 2018
1 parent 3891f2e commit f86083c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
9 changes: 3 additions & 6 deletions homeassistant/components/alarm_control_panel/manual_mqtt.py
Expand Up @@ -335,11 +335,8 @@ def device_state_attributes(self):

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
)
Expand All @@ -359,7 +356,7 @@ def message_received(topic, payload, qos):
_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,
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/camera/mqtt.py
Expand Up @@ -89,13 +89,12 @@ def unique_id(self):
"""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)

0 comments on commit f86083c

Please sign in to comment.