2020-01-15 20:01:47 +00:00
|
|
|
"""Helpers for interacting with pynws."""
|
2020-04-16 14:15:55 +00:00
|
|
|
from homeassistant.components.nws.const import CONF_STATION
|
2020-01-15 20:01:47 +00:00
|
|
|
from homeassistant.components.weather import (
|
2020-09-05 19:11:15 +00:00
|
|
|
ATTR_CONDITION_LIGHTNING_RAINY,
|
2020-01-15 20:01:47 +00:00
|
|
|
ATTR_FORECAST_CONDITION,
|
2020-09-05 19:11:15 +00:00
|
|
|
ATTR_FORECAST_PRECIPITATION_PROBABILITY,
|
2020-01-15 20:01:47 +00:00
|
|
|
ATTR_FORECAST_TEMP,
|
|
|
|
ATTR_FORECAST_TIME,
|
|
|
|
ATTR_FORECAST_WIND_BEARING,
|
|
|
|
ATTR_FORECAST_WIND_SPEED,
|
|
|
|
ATTR_WEATHER_HUMIDITY,
|
|
|
|
ATTR_WEATHER_PRESSURE,
|
|
|
|
ATTR_WEATHER_TEMPERATURE,
|
|
|
|
ATTR_WEATHER_VISIBILITY,
|
|
|
|
ATTR_WEATHER_WIND_BEARING,
|
|
|
|
ATTR_WEATHER_WIND_SPEED,
|
|
|
|
)
|
|
|
|
from homeassistant.const import (
|
2020-04-08 15:22:25 +00:00
|
|
|
CONF_API_KEY,
|
2020-04-16 14:15:55 +00:00
|
|
|
CONF_LATITUDE,
|
|
|
|
CONF_LONGITUDE,
|
2020-01-15 20:01:47 +00:00
|
|
|
LENGTH_KILOMETERS,
|
|
|
|
LENGTH_METERS,
|
|
|
|
LENGTH_MILES,
|
|
|
|
PRESSURE_HPA,
|
|
|
|
PRESSURE_INHG,
|
|
|
|
PRESSURE_PA,
|
2021-11-09 07:12:28 +00:00
|
|
|
SPEED_KILOMETERS_PER_HOUR,
|
|
|
|
SPEED_MILES_PER_HOUR,
|
2020-01-15 20:01:47 +00:00
|
|
|
TEMP_CELSIUS,
|
|
|
|
TEMP_FAHRENHEIT,
|
|
|
|
)
|
|
|
|
from homeassistant.util.distance import convert as convert_distance
|
|
|
|
from homeassistant.util.pressure import convert as convert_pressure
|
2021-11-09 07:12:28 +00:00
|
|
|
from homeassistant.util.speed import convert as convert_speed
|
2020-01-15 20:01:47 +00:00
|
|
|
from homeassistant.util.temperature import convert as convert_temperature
|
|
|
|
|
2020-04-16 14:15:55 +00:00
|
|
|
NWS_CONFIG = {
|
|
|
|
CONF_API_KEY: "test",
|
|
|
|
CONF_LATITUDE: 35,
|
|
|
|
CONF_LONGITUDE: -75,
|
|
|
|
CONF_STATION: "ABC",
|
|
|
|
}
|
2020-04-08 15:22:25 +00:00
|
|
|
|
2020-01-15 20:01:47 +00:00
|
|
|
DEFAULT_STATIONS = ["ABC", "XYZ"]
|
|
|
|
|
|
|
|
DEFAULT_OBSERVATION = {
|
|
|
|
"temperature": 10,
|
|
|
|
"seaLevelPressure": 100000,
|
2021-04-01 16:50:37 +00:00
|
|
|
"barometricPressure": 100000,
|
2020-01-15 20:01:47 +00:00
|
|
|
"relativeHumidity": 10,
|
|
|
|
"windSpeed": 10,
|
|
|
|
"windDirection": 180,
|
|
|
|
"visibility": 10000,
|
|
|
|
"textDescription": "A long description",
|
|
|
|
"station": "ABC",
|
|
|
|
"timestamp": "2019-08-12T23:53:00+00:00",
|
|
|
|
"iconTime": "day",
|
|
|
|
"iconWeather": (("Fair/clear", None),),
|
2021-04-01 16:50:37 +00:00
|
|
|
"dewpoint": 5,
|
|
|
|
"windChill": 5,
|
|
|
|
"heatIndex": 15,
|
|
|
|
"windGust": 20,
|
2020-01-15 20:01:47 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 16:50:37 +00:00
|
|
|
SENSOR_EXPECTED_OBSERVATION_METRIC = {
|
|
|
|
"dewpoint": "5",
|
|
|
|
"temperature": "10",
|
|
|
|
"windChill": "5",
|
|
|
|
"heatIndex": "15",
|
|
|
|
"relativeHumidity": "10",
|
|
|
|
"windSpeed": "10",
|
|
|
|
"windGust": "20",
|
|
|
|
"windDirection": "180",
|
|
|
|
"barometricPressure": "100000",
|
|
|
|
"seaLevelPressure": "100000",
|
|
|
|
"visibility": "10000",
|
|
|
|
}
|
|
|
|
|
|
|
|
SENSOR_EXPECTED_OBSERVATION_IMPERIAL = {
|
|
|
|
"dewpoint": str(round(convert_temperature(5, TEMP_CELSIUS, TEMP_FAHRENHEIT))),
|
|
|
|
"temperature": str(round(convert_temperature(10, TEMP_CELSIUS, TEMP_FAHRENHEIT))),
|
|
|
|
"windChill": str(round(convert_temperature(5, TEMP_CELSIUS, TEMP_FAHRENHEIT))),
|
|
|
|
"heatIndex": str(round(convert_temperature(15, TEMP_CELSIUS, TEMP_FAHRENHEIT))),
|
|
|
|
"relativeHumidity": "10",
|
2021-11-09 07:12:28 +00:00
|
|
|
"windSpeed": str(
|
|
|
|
round(convert_speed(10, SPEED_KILOMETERS_PER_HOUR, SPEED_MILES_PER_HOUR))
|
|
|
|
),
|
|
|
|
"windGust": str(
|
|
|
|
round(convert_speed(20, SPEED_KILOMETERS_PER_HOUR, SPEED_MILES_PER_HOUR))
|
|
|
|
),
|
2021-04-01 16:50:37 +00:00
|
|
|
"windDirection": "180",
|
|
|
|
"barometricPressure": str(
|
|
|
|
round(convert_pressure(100000, PRESSURE_PA, PRESSURE_INHG), 2)
|
|
|
|
),
|
|
|
|
"seaLevelPressure": str(
|
|
|
|
round(convert_pressure(100000, PRESSURE_PA, PRESSURE_INHG), 2)
|
|
|
|
),
|
|
|
|
"visibility": str(round(convert_distance(10000, LENGTH_METERS, LENGTH_MILES))),
|
|
|
|
}
|
|
|
|
|
|
|
|
WEATHER_EXPECTED_OBSERVATION_IMPERIAL = {
|
2020-01-15 20:01:47 +00:00
|
|
|
ATTR_WEATHER_TEMPERATURE: round(
|
|
|
|
convert_temperature(10, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
|
|
|
),
|
|
|
|
ATTR_WEATHER_WIND_BEARING: 180,
|
|
|
|
ATTR_WEATHER_WIND_SPEED: round(
|
2022-06-27 09:39:02 +00:00
|
|
|
convert_speed(10, SPEED_KILOMETERS_PER_HOUR, SPEED_MILES_PER_HOUR), 2
|
2020-01-15 20:01:47 +00:00
|
|
|
),
|
|
|
|
ATTR_WEATHER_PRESSURE: round(
|
|
|
|
convert_pressure(100000, PRESSURE_PA, PRESSURE_INHG), 2
|
|
|
|
),
|
|
|
|
ATTR_WEATHER_VISIBILITY: round(
|
2022-06-27 09:39:02 +00:00
|
|
|
convert_distance(10000, LENGTH_METERS, LENGTH_MILES), 2
|
2020-01-15 20:01:47 +00:00
|
|
|
),
|
|
|
|
ATTR_WEATHER_HUMIDITY: 10,
|
|
|
|
}
|
|
|
|
|
2021-04-01 16:50:37 +00:00
|
|
|
WEATHER_EXPECTED_OBSERVATION_METRIC = {
|
2020-01-15 20:01:47 +00:00
|
|
|
ATTR_WEATHER_TEMPERATURE: 10,
|
|
|
|
ATTR_WEATHER_WIND_BEARING: 180,
|
2020-06-29 22:41:52 +00:00
|
|
|
ATTR_WEATHER_WIND_SPEED: 10,
|
2020-01-15 20:01:47 +00:00
|
|
|
ATTR_WEATHER_PRESSURE: round(convert_pressure(100000, PRESSURE_PA, PRESSURE_HPA)),
|
|
|
|
ATTR_WEATHER_VISIBILITY: round(
|
|
|
|
convert_distance(10000, LENGTH_METERS, LENGTH_KILOMETERS)
|
|
|
|
),
|
|
|
|
ATTR_WEATHER_HUMIDITY: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
NONE_OBSERVATION = {key: None for key in DEFAULT_OBSERVATION}
|
|
|
|
|
|
|
|
DEFAULT_FORECAST = [
|
|
|
|
{
|
|
|
|
"number": 1,
|
|
|
|
"name": "Tonight",
|
|
|
|
"startTime": "2019-08-12T20:00:00-04:00",
|
|
|
|
"isDaytime": False,
|
|
|
|
"temperature": 10,
|
|
|
|
"windSpeedAvg": 10,
|
|
|
|
"windBearing": 180,
|
|
|
|
"detailedForecast": "A detailed forecast.",
|
|
|
|
"timestamp": "2019-08-12T23:53:00+00:00",
|
|
|
|
"iconTime": "night",
|
|
|
|
"iconWeather": (("lightning-rainy", 40), ("lightning-rainy", 90)),
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
EXPECTED_FORECAST_IMPERIAL = {
|
2020-09-05 19:11:15 +00:00
|
|
|
ATTR_FORECAST_CONDITION: ATTR_CONDITION_LIGHTNING_RAINY,
|
2020-01-15 20:01:47 +00:00
|
|
|
ATTR_FORECAST_TIME: "2019-08-12T20:00:00-04:00",
|
|
|
|
ATTR_FORECAST_TEMP: 10,
|
|
|
|
ATTR_FORECAST_WIND_SPEED: 10,
|
|
|
|
ATTR_FORECAST_WIND_BEARING: 180,
|
2020-09-05 19:11:15 +00:00
|
|
|
ATTR_FORECAST_PRECIPITATION_PROBABILITY: 90,
|
2020-01-15 20:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPECTED_FORECAST_METRIC = {
|
2020-09-05 19:11:15 +00:00
|
|
|
ATTR_FORECAST_CONDITION: ATTR_CONDITION_LIGHTNING_RAINY,
|
2020-01-15 20:01:47 +00:00
|
|
|
ATTR_FORECAST_TIME: "2019-08-12T20:00:00-04:00",
|
2022-03-30 20:49:28 +00:00
|
|
|
ATTR_FORECAST_TEMP: round(
|
|
|
|
convert_temperature(10, TEMP_FAHRENHEIT, TEMP_CELSIUS), 1
|
|
|
|
),
|
2020-01-15 20:01:47 +00:00
|
|
|
ATTR_FORECAST_WIND_SPEED: round(
|
2022-06-27 09:39:02 +00:00
|
|
|
convert_speed(10, SPEED_MILES_PER_HOUR, SPEED_KILOMETERS_PER_HOUR), 2
|
2020-01-15 20:01:47 +00:00
|
|
|
),
|
|
|
|
ATTR_FORECAST_WIND_BEARING: 180,
|
2020-09-05 19:11:15 +00:00
|
|
|
ATTR_FORECAST_PRECIPITATION_PROBABILITY: 90,
|
2020-01-15 20:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NONE_FORECAST = [{key: None for key in DEFAULT_FORECAST[0]}]
|