Skip to content

Commit

Permalink
v2.0.6
Browse files Browse the repository at this point in the history
Increase default rest timeout from 10 seconds to 30 seconds
  • Loading branch information
dave_albright committed Feb 23, 2024
1 parent 089db9e commit c2ad041
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v2.0.6
Increase default rest timeout from 10 seconds to 30 seconds
Starting with home assistant 2024, rest availability on Home Assistant Operating System (on Raspberry Pi ?) after restart is delayed and causing setup failure.
If you still get a WUPWS setup error after restarting Home Assistant, you can try and change the DEFAULT_TIMEOUT in const.py to 60 seconds.

v2.0.5
fix error in cardinal wind direction when api returns None

Expand Down
3 changes: 3 additions & 0 deletions custom_components/wundergroundpws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
CONF_LATITUDE, CONF_LONGITUDE, Platform
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.util.unit_system import METRIC_SYSTEM
from .coordinator import WundergroundPWSUpdateCoordinator, WundergroundPWSUpdateCoordinatorConfig
from .const import (
Expand Down Expand Up @@ -51,6 +52,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

wupwscoordinator = WundergroundPWSUpdateCoordinator(hass, config)
await wupwscoordinator.async_config_entry_first_refresh()
if not wupwscoordinator.last_update_success:
raise ConfigEntryNotReady

entry.async_on_unload(entry.add_update_listener(_async_update_listener))
hass.data[DOMAIN][entry.entry_id] = wupwscoordinator
Expand Down
3 changes: 2 additions & 1 deletion custom_components/wundergroundpws/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DOMAIN, CONF_PWS_ID, CONF_NUMERIC_PRECISION, CONF_LANG, CONF_CALENDARDAYTEMPERATURE, DEFAULT_NUMERIC_PRECISION,
DEFAULT_LANG, LANG_CODES, DEFAULT_CALENDARDAYTEMPERATURE, FIELD_OBSERVATIONS, FIELD_LONGITUDE, FIELD_LATITUDE,
CONF_FORECAST_SENSORS, DEFAULT_FORECAST_SENSORS,
DEFAULT_TIMEOUT
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -54,7 +55,7 @@ async def async_step_user(self, user_input=None):
errors["base"] = "invalid_station_id"
raise InvalidStationId

with async_timeout.timeout(10):
with async_timeout.timeout(DEFAULT_TIMEOUT):
url = f'https://api.weather.com/v2/pws/observations/current?stationId={pws_id}&format=json&units=e' \
f'&apiKey={api_key}'
response = await session.get(url, headers=headers)
Expand Down
1 change: 1 addition & 0 deletions custom_components/wundergroundpws/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
ATTR_CONDITION_WINDY_VARIANT: []
}

DEFAULT_TIMEOUT = 30
DEFAULT_NUMERIC_PRECISION = 'none'
DEFAULT_LANG = 'en-US'
DEFAULT_CALENDARDAYTEMPERATURE = False
Expand Down
7 changes: 4 additions & 3 deletions custom_components/wundergroundpws/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
FIELD_FORECAST_TEMPERATUREMAX,
FIELD_FORECAST_TEMPERATUREMIN,
FIELD_FORECAST_CALENDARDAYTEMPERATUREMAX,
FIELD_FORECAST_CALENDARDAYTEMPERATUREMIN, DOMAIN, FIELD_LONGITUDE, FIELD_LATITUDE
FIELD_FORECAST_CALENDARDAYTEMPERATUREMIN, DOMAIN, FIELD_LONGITUDE, FIELD_LATITUDE,
DEFAULT_TIMEOUT
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -121,7 +122,7 @@ async def get_weather(self):
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
}
try:
with async_timeout.timeout(10):
with async_timeout.timeout(DEFAULT_TIMEOUT):
url = self._build_url(_RESOURCECURRENT)
response = await self._session.get(url, headers=headers)
result_current = await response.json()
Expand All @@ -134,7 +135,7 @@ async def get_weather(self):
if not self._latitude:
self._latitude = (result_current[FIELD_OBSERVATIONS][0][FIELD_LATITUDE])

with async_timeout.timeout(10):
with async_timeout.timeout(DEFAULT_TIMEOUT):
url = self._build_url(_RESOURCEFORECAST)
response = await self._session.get(url, headers=headers)
result_forecast = await response.json()
Expand Down
4 changes: 2 additions & 2 deletions custom_components/wundergroundpws/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"domain": "wundergroundpws",
"name": "Wundergroundpws",
"version": "2.0.5",
"version": "2.0.6",
"documentation": "https://github.com/cytech/Home-Assistant-wundergroundpws/",
"issue_tracker": "https://github.com/cytech/Home-Assistant-wundergroundpws/issues/",
"issue_tracker": "https://github.com/cytech/Home-Assistant-wundergroundpws/discussions/",
"requirements": [],
"dependencies": [],
"codeowners": ["@cytech"],
Expand Down

0 comments on commit c2ad041

Please sign in to comment.