Add Wind to Accuweather sensors (#44364)

pull/44375/head
Abílio Costa 2020-12-19 15:10:02 +00:00 committed by GitHub
parent 317ed418dd
commit 896f51fd82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 3 deletions

View File

@ -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",

View File

@ -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"]

View File

@ -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"