Skip to content

Commit 36e33bf

Browse files
author
dave_albright
committed
v2.0.7
Move sensor translation file initialization to WundergroundPWSUpdateCoordinatorConfig in __init__.py Fixes "Detected blocking call to open with args" warning
1 parent c2ad041 commit 36e33bf

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v2.0.7
2+
Move sensor translation file initialization to WundergroundPWSUpdateCoordinatorConfig in `__init__.py`
3+
Fixes "Detected blocking call to open with args" warning
4+
15
v2.0.6
26
Increase default rest timeout from 10 seconds to 30 seconds
37
Starting with home assistant 2024, rest availability on Home Assistant Operating System (on Raspberry Pi ?) after restart is delayed and causing setup failure.

custom_components/wundergroundpws/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""The wundergroundpws component."""
22
import logging
3+
import os.path
34
from typing import Final
45
from homeassistant.config_entries import ConfigEntry
56
from homeassistant.const import (
@@ -9,6 +10,7 @@
910
from homeassistant.core import HomeAssistant
1011
from homeassistant.exceptions import ConfigEntryNotReady
1112
from homeassistant.util.unit_system import METRIC_SYSTEM
13+
from homeassistant.util import json
1214
from .coordinator import WundergroundPWSUpdateCoordinator, WundergroundPWSUpdateCoordinatorConfig
1315
from .const import (
1416
CONF_LANG,
@@ -47,9 +49,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
4749
calendarday=entry.options[CONF_CALENDARDAYTEMPERATURE],
4850
latitude=latitude,
4951
longitude=longitude,
50-
forecast_enable=entry.options.get(CONF_FORECAST_SENSORS, False)
52+
forecast_enable=entry.options.get(CONF_FORECAST_SENSORS, False),
53+
tranfile=""
5154
)
5255

56+
"""get translation file for wupws sensor friendly_name"""
57+
tfiledir = f'{hass.config.config_dir}/custom_components/{DOMAIN}/wupws_translations/'
58+
tfilename = config.lang.split('-', 1)[0]
59+
60+
if os.path.isfile(f'{tfiledir}{tfilename}.json'):
61+
config.tranfile = await hass.async_add_executor_job(json.load_json, f'{tfiledir}{tfilename}.json')
62+
else:
63+
config.tranfile = await hass.async_add_executor_job(json.load_json, f'{tfiledir}en.json')
64+
_LOGGER.warning(f'Sensor translation file {tfilename}.json does not exist. Defaulting to en-US.')
65+
5366
wupwscoordinator = WundergroundPWSUpdateCoordinator(hass, config)
5467
await wupwscoordinator.async_config_entry_first_refresh()
5568
if not wupwscoordinator.last_update_success:

custom_components/wundergroundpws/coordinator.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from homeassistant.exceptions import HomeAssistantError
1616
from homeassistant.helpers.aiohttp_client import async_get_clientsession
1717
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
18-
from homeassistant.util import json
1918
from homeassistant.util.unit_system import METRIC_SYSTEM
2019
from homeassistant.const import (
2120
PERCENTAGE, UnitOfPressure, UnitOfTemperature, UnitOfLength, UnitOfSpeed, UnitOfVolumetricFlux)
@@ -29,7 +28,7 @@
2928
FIELD_FORECAST_TEMPERATUREMAX,
3029
FIELD_FORECAST_TEMPERATUREMIN,
3130
FIELD_FORECAST_CALENDARDAYTEMPERATUREMAX,
32-
FIELD_FORECAST_CALENDARDAYTEMPERATUREMIN, DOMAIN, FIELD_LONGITUDE, FIELD_LATITUDE,
31+
FIELD_FORECAST_CALENDARDAYTEMPERATUREMIN, FIELD_LONGITUDE, FIELD_LATITUDE,
3332
DEFAULT_TIMEOUT
3433
)
3534

@@ -59,6 +58,7 @@ class WundergroundPWSUpdateCoordinatorConfig:
5958
longitude: str
6059
forecast_enable: bool
6160
update_interval = MIN_TIME_BETWEEN_UPDATES
61+
tranfile: str
6262

6363

6464
class WundergroundPWSUpdateCoordinator(DataUpdateCoordinator):
@@ -84,7 +84,7 @@ def __init__(
8484
self._features = set()
8585
self.data = None
8686
self._session = async_get_clientsession(self._hass)
87-
self._tranfile = self.get_tran_file()
87+
self._tranfile = config.tranfile
8888

8989
if self._unit_system_api == 'm':
9090
self.units_of_measurement = (UnitOfTemperature.CELSIUS, UnitOfLength.MILLIMETERS, UnitOfLength.METERS,
@@ -224,17 +224,6 @@ def _iconcode_to_condition(cls, icon_code):
224224
_LOGGER.warning(f'Unmapped iconCode from TWC Api. (44 is Not Available (N/A)) "{icon_code}". ')
225225
return None
226226

227-
def get_tran_file(self):
228-
"""get translation file for wupws sensor friendly_name"""
229-
tfiledir = f'{self._hass.config.config_dir}/custom_components/{DOMAIN}/wupws_translations/'
230-
tfilename = self._lang.split('-', 1)[0]
231-
try:
232-
tfiledata = json.load_json(f'{tfiledir}{tfilename}.json')
233-
except Exception: # pylint: disable=broad-except
234-
tfiledata = json.load_json(f'{tfiledir}en.json')
235-
_LOGGER.warning(f'Sensor translation file {tfilename}.json does not exist. Defaulting to en-US.')
236-
return tfiledata
237-
238227

239228
class InvalidApiKey(HomeAssistantError):
240229
"""Error to indicate there is an invalid api key."""

custom_components/wundergroundpws/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "wundergroundpws",
33
"name": "Wundergroundpws",
4-
"version": "2.0.6",
4+
"version": "2.0.7",
55
"documentation": "https://github.com/cytech/Home-Assistant-wundergroundpws/",
66
"issue_tracker": "https://github.com/cytech/Home-Assistant-wundergroundpws/discussions/",
77
"requirements": [],

0 commit comments

Comments
 (0)