From a9bf32efd0fbc760e79aae70ced89a99b3fb1b8a Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Thu, 19 Apr 2018 22:16:25 -0400 Subject: [PATCH 1/5] expose the condition code on condition sensors --- homeassistant/components/sensor/yweather.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/sensor/yweather.py b/homeassistant/components/sensor/yweather.py index df18e086ddda82..2736bf463321a2 100644 --- a/homeassistant/components/sensor/yweather.py +++ b/homeassistant/components/sensor/yweather.py @@ -131,9 +131,12 @@ def entity_picture(self): @property def device_state_attributes(self): """Return the state attributes.""" - return { - ATTR_ATTRIBUTION: CONF_ATTRIBUTION, - } + attrs = { ATTR_ATTRIBUTION: CONF_ATTRIBUTION } + + if self._code is None or "weather" in self._type: + attrs['condition_code'] = self._code + + return attrs def update(self): """Get the latest data from Yahoo! and updates the states.""" From f897663b9b193a5da88708c1dd1d76af7dc88bb4 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Thu, 19 Apr 2018 22:21:02 -0400 Subject: [PATCH 2/5] :lipstick: --- homeassistant/components/sensor/yweather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/yweather.py b/homeassistant/components/sensor/yweather.py index 2736bf463321a2..931430cffc5ea5 100644 --- a/homeassistant/components/sensor/yweather.py +++ b/homeassistant/components/sensor/yweather.py @@ -131,7 +131,7 @@ def entity_picture(self): @property def device_state_attributes(self): """Return the state attributes.""" - attrs = { ATTR_ATTRIBUTION: CONF_ATTRIBUTION } + attrs = {ATTR_ATTRIBUTION: CONF_ATTRIBUTION} if self._code is None or "weather" in self._type: attrs['condition_code'] = self._code From 49aa7deb3d9af10b314f9e846e09532f1cec5c6d Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Fri, 20 Apr 2018 14:09:23 -0400 Subject: [PATCH 3/5] like thisss duh --- homeassistant/components/sensor/yweather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/yweather.py b/homeassistant/components/sensor/yweather.py index 931430cffc5ea5..db66419e54ab1d 100644 --- a/homeassistant/components/sensor/yweather.py +++ b/homeassistant/components/sensor/yweather.py @@ -133,7 +133,7 @@ def device_state_attributes(self): """Return the state attributes.""" attrs = {ATTR_ATTRIBUTION: CONF_ATTRIBUTION} - if self._code is None or "weather" in self._type: + if self._code is not None and "weather" in self._type: attrs['condition_code'] = self._code return attrs From 5824919ed40fcc9b4aabff3af37c19d509095776 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Fri, 20 Apr 2018 14:12:57 -0400 Subject: [PATCH 4/5] add test for condition_code --- tests/components/sensor/test_yweather.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/components/sensor/test_yweather.py b/tests/components/sensor/test_yweather.py index 88b94906a35131..05395239067b17 100644 --- a/tests/components/sensor/test_yweather.py +++ b/tests/components/sensor/test_yweather.py @@ -162,6 +162,8 @@ def test_setup_all(self, mock_yahooweather): state = self.hass.states.get('sensor.yweather_condition') assert state is not None self.assertEqual(state.state, 'Mostly Cloudy') + self.assertEqual(state.attributes.get('condition_code'), + 28) self.assertEqual(state.attributes.get('friendly_name'), 'Yweather Condition') From f705a150f378695ae052bcb0a3ba879293f64b1e Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Fri, 20 Apr 2018 16:14:35 -0400 Subject: [PATCH 5/5] =?UTF-8?q?It=E2=80=99s=20a=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/components/sensor/test_yweather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/sensor/test_yweather.py b/tests/components/sensor/test_yweather.py index 05395239067b17..aeee47bfa807c8 100644 --- a/tests/components/sensor/test_yweather.py +++ b/tests/components/sensor/test_yweather.py @@ -163,7 +163,7 @@ def test_setup_all(self, mock_yahooweather): assert state is not None self.assertEqual(state.state, 'Mostly Cloudy') self.assertEqual(state.attributes.get('condition_code'), - 28) + '28') self.assertEqual(state.attributes.get('friendly_name'), 'Yweather Condition')