Add Wind to Accuweather sensors (#44364)
This commit is contained in:
parent
317ed418dd
commit
896f51fd82
3 changed files with 80 additions and 3 deletions
|
@ -183,6 +183,20 @@ FORECAST_SENSOR_TYPES = {
|
||||||
ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR,
|
ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR,
|
||||||
ATTR_UNIT_IMPERIAL: SPEED_MILES_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 = (
|
OPTIONAL_SENSORS = (
|
||||||
|
@ -284,6 +298,13 @@ SENSOR_TYPES = {
|
||||||
ATTR_UNIT_METRIC: TEMP_CELSIUS,
|
ATTR_UNIT_METRIC: TEMP_CELSIUS,
|
||||||
ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
|
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": {
|
"WindGust": {
|
||||||
ATTR_DEVICE_CLASS: None,
|
ATTR_DEVICE_CLASS: None,
|
||||||
ATTR_ICON: "mdi:weather-windy",
|
ATTR_ICON: "mdi:weather-windy",
|
||||||
|
|
|
@ -96,7 +96,7 @@ class AccuWeatherSensor(CoordinatorEntity):
|
||||||
return self.coordinator.data[ATTR_FORECAST][self.forecast_day][
|
return self.coordinator.data[ATTR_FORECAST][self.forecast_day][
|
||||||
self.kind
|
self.kind
|
||||||
]["Value"]
|
]["Value"]
|
||||||
if self.kind in ["WindGustDay", "WindGustNight"]:
|
if self.kind in ["WindDay", "WindNight", "WindGustDay", "WindGustNight"]:
|
||||||
return self.coordinator.data[ATTR_FORECAST][self.forecast_day][
|
return self.coordinator.data[ATTR_FORECAST][self.forecast_day][
|
||||||
self.kind
|
self.kind
|
||||||
]["Speed"]["Value"]
|
]["Speed"]["Value"]
|
||||||
|
@ -115,7 +115,7 @@ class AccuWeatherSensor(CoordinatorEntity):
|
||||||
return self.coordinator.data["PrecipitationSummary"][self.kind][
|
return self.coordinator.data["PrecipitationSummary"][self.kind][
|
||||||
self._unit_system
|
self._unit_system
|
||||||
]["Value"]
|
]["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]["Speed"][self._unit_system]["Value"]
|
||||||
return self.coordinator.data[self.kind]
|
return self.coordinator.data[self.kind]
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ class AccuWeatherSensor(CoordinatorEntity):
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
if self.forecast_day is not None:
|
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._attrs["direction"] = self.coordinator.data[ATTR_FORECAST][
|
||||||
self.forecast_day
|
self.forecast_day
|
||||||
][self.kind]["Direction"]["English"]
|
][self.kind]["Direction"]["English"]
|
||||||
|
|
|
@ -222,6 +222,13 @@ async def test_sensor_enabled_without_forecast(hass):
|
||||||
suggested_object_id="home_wet_bulb_temperature",
|
suggested_object_id="home_wet_bulb_temperature",
|
||||||
disabled_by=None,
|
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(
|
registry.async_get_or_create(
|
||||||
SENSOR_DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -313,6 +320,20 @@ async def test_sensor_enabled_without_forecast(hass):
|
||||||
suggested_object_id="home_wind_gust_night_0d",
|
suggested_object_id="home_wind_gust_night_0d",
|
||||||
disabled_by=None,
|
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)
|
await init_integration(hass, forecast=True)
|
||||||
|
|
||||||
|
@ -393,6 +414,17 @@ async def test_sensor_enabled_without_forecast(hass):
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == "0123456-windgust"
|
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")
|
state = hass.states.get("sensor.home_cloud_cover_day_0d")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "58"
|
assert state.state == "58"
|
||||||
|
@ -507,6 +539,30 @@ async def test_sensor_enabled_without_forecast(hass):
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == "0123456-tree-0"
|
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")
|
state = hass.states.get("sensor.home_wind_gust_day_0d")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "29.6"
|
assert state.state == "29.6"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue