From 21197fb9689ee63813560b0238453a2dbd14a9af Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 4 Dec 2018 10:55:30 +0100 Subject: [PATCH] Review comments --- homeassistant/components/mqtt/__init__.py | 7 ++++--- tests/components/binary_sensor/test_mqtt.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 11b837113c5..aa63adb72d8 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -840,6 +840,7 @@ class MqttAttributes(Entity): This method must be run in the event loop and returns a coroutine. """ + await super().async_added_to_hass() await self._attributes_subscribe_topics() async def attributes_discovery_update(self, config: dict): @@ -861,15 +862,15 @@ class MqttAttributes(Entity): self._attributes = json_dict self.async_schedule_update_ha_state() else: - _LOGGER.debug("JSON result was not a dictionary") + _LOGGER.warning("JSON result was not a dictionary") self._attributes = None except ValueError: - _LOGGER.debug("Erroneous JSON: %s", payload) + _LOGGER.warning("Erroneous JSON: %s", payload) self._attributes = None self._attributes_sub_state = await async_subscribe_topics( self.hass, self._attributes_sub_state, - {'attributes_topic': { + {CONF_JSON_ATTRS_TOPIC: { 'topic': self._attributes_config.get(CONF_JSON_ATTRS_TOPIC), 'msg_callback': attributes_message_received, 'qos': self._attributes_config.get(CONF_QOS)}}) diff --git a/tests/components/binary_sensor/test_mqtt.py b/tests/components/binary_sensor/test_mqtt.py index a4357eefed8..74c7d32927b 100644 --- a/tests/components/binary_sensor/test_mqtt.py +++ b/tests/components/binary_sensor/test_mqtt.py @@ -293,7 +293,7 @@ class TestSensorMQTT(unittest.TestCase): state = self.hass.states.get('binary_sensor.test') assert state.attributes.get('val') is None - mock_logger.debug.assert_called_with( + mock_logger.warning.assert_called_with( 'JSON result was not a dictionary') @patch('homeassistant.components.mqtt._LOGGER') @@ -314,7 +314,7 @@ class TestSensorMQTT(unittest.TestCase): state = self.hass.states.get('binary_sensor.test') assert state.attributes.get('val') is None - mock_logger.debug.assert_called_with( + mock_logger.warning.assert_called_with( 'Erroneous JSON: %s', 'This is not JSON')