From 896f51fd825e1a64e9f2face71e015051ad30178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ab=C3=ADlio=20Costa?= Date: Sat, 19 Dec 2020 15:10:02 +0000 Subject: [PATCH] Add Wind to Accuweather sensors (#44364) --- homeassistant/components/accuweather/const.py | 21 +++++++ .../components/accuweather/sensor.py | 6 +- tests/components/accuweather/test_sensor.py | 56 +++++++++++++++++++ 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/accuweather/const.py b/homeassistant/components/accuweather/const.py index fa9ed6b467f..cbccc3a462d 100644 --- a/homeassistant/components/accuweather/const.py +++ b/homeassistant/components/accuweather/const.py @@ -183,6 +183,20 @@ FORECAST_SENSOR_TYPES = { ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, }, + "WindDay": { + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-windy", + ATTR_LABEL: "Wind Day", + ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, + ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, + }, + "WindNight": { + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-windy", + ATTR_LABEL: "Wind Night", + ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, + ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, + }, } OPTIONAL_SENSORS = ( @@ -284,6 +298,13 @@ SENSOR_TYPES = { ATTR_UNIT_METRIC: TEMP_CELSIUS, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, }, + "Wind": { + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-windy", + ATTR_LABEL: "Wind", + ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, + ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, + }, "WindGust": { ATTR_DEVICE_CLASS: None, ATTR_ICON: "mdi:weather-windy", diff --git a/homeassistant/components/accuweather/sensor.py b/homeassistant/components/accuweather/sensor.py index 4f61322b2c6..90058e254dc 100644 --- a/homeassistant/components/accuweather/sensor.py +++ b/homeassistant/components/accuweather/sensor.py @@ -96,7 +96,7 @@ class AccuWeatherSensor(CoordinatorEntity): return self.coordinator.data[ATTR_FORECAST][self.forecast_day][ self.kind ]["Value"] - if self.kind in ["WindGustDay", "WindGustNight"]: + if self.kind in ["WindDay", "WindNight", "WindGustDay", "WindGustNight"]: return self.coordinator.data[ATTR_FORECAST][self.forecast_day][ self.kind ]["Speed"]["Value"] @@ -115,7 +115,7 @@ class AccuWeatherSensor(CoordinatorEntity): return self.coordinator.data["PrecipitationSummary"][self.kind][ self._unit_system ]["Value"] - if self.kind == "WindGust": + if self.kind in ["Wind", "WindGust"]: return self.coordinator.data[self.kind]["Speed"][self._unit_system]["Value"] return self.coordinator.data[self.kind] @@ -144,7 +144,7 @@ class AccuWeatherSensor(CoordinatorEntity): def device_state_attributes(self): """Return the state attributes.""" if self.forecast_day is not None: - if self.kind in ["WindGustDay", "WindGustNight"]: + if self.kind in ["WindDay", "WindNight", "WindGustDay", "WindGustNight"]: self._attrs["direction"] = self.coordinator.data[ATTR_FORECAST][ self.forecast_day ][self.kind]["Direction"]["English"] diff --git a/tests/components/accuweather/test_sensor.py b/tests/components/accuweather/test_sensor.py index d4aae9a94fc..185f6024886 100644 --- a/tests/components/accuweather/test_sensor.py +++ b/tests/components/accuweather/test_sensor.py @@ -222,6 +222,13 @@ async def test_sensor_enabled_without_forecast(hass): suggested_object_id="home_wet_bulb_temperature", disabled_by=None, ) + registry.async_get_or_create( + SENSOR_DOMAIN, + DOMAIN, + "0123456-wind", + suggested_object_id="home_wind", + disabled_by=None, + ) registry.async_get_or_create( SENSOR_DOMAIN, DOMAIN, @@ -313,6 +320,20 @@ async def test_sensor_enabled_without_forecast(hass): suggested_object_id="home_wind_gust_night_0d", disabled_by=None, ) + registry.async_get_or_create( + SENSOR_DOMAIN, + DOMAIN, + "0123456-windday-0", + suggested_object_id="home_wind_day_0d", + disabled_by=None, + ) + registry.async_get_or_create( + SENSOR_DOMAIN, + DOMAIN, + "0123456-windnight-0", + suggested_object_id="home_wind_night_0d", + disabled_by=None, + ) await init_integration(hass, forecast=True) @@ -393,6 +414,17 @@ async def test_sensor_enabled_without_forecast(hass): assert entry assert entry.unique_id == "0123456-windgust" + state = hass.states.get("sensor.home_wind") + assert state + assert state.state == "14.5" + assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SPEED_KILOMETERS_PER_HOUR + assert state.attributes.get(ATTR_ICON) == "mdi:weather-windy" + + entry = registry.async_get("sensor.home_wind") + assert entry + assert entry.unique_id == "0123456-wind" + state = hass.states.get("sensor.home_cloud_cover_day_0d") assert state assert state.state == "58" @@ -507,6 +539,30 @@ async def test_sensor_enabled_without_forecast(hass): assert entry assert entry.unique_id == "0123456-tree-0" + state = hass.states.get("sensor.home_wind_day_0d") + assert state + assert state.state == "13.0" + assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SPEED_KILOMETERS_PER_HOUR + assert state.attributes.get("direction") == "SSE" + assert state.attributes.get(ATTR_ICON) == "mdi:weather-windy" + + entry = registry.async_get("sensor.home_wind_day_0d") + assert entry + assert entry.unique_id == "0123456-windday-0" + + state = hass.states.get("sensor.home_wind_night_0d") + assert state + assert state.state == "7.4" + assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SPEED_KILOMETERS_PER_HOUR + assert state.attributes.get("direction") == "WNW" + assert state.attributes.get(ATTR_ICON) == "mdi:weather-windy" + + entry = registry.async_get("sensor.home_wind_night_0d") + assert entry + assert entry.unique_id == "0123456-windnight-0" + state = hass.states.get("sensor.home_wind_gust_day_0d") assert state assert state.state == "29.6"