Skip to content

Commit eeb57ef

Browse files
committed
More fixes
1 parent a06d1cc commit eeb57ef

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

src/pysma/sma_webconnect.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,10 @@ def _load_l10n_from_package(self, locale: str) -> dict:
227227
not found or cannot be loaded.
228228
229229
"""
230-
try:
231-
data = pkgutil.get_data("pysma", f"l10n/{locale}.json")
232-
if data is None:
233-
return {}
234-
return json.loads(data)
235-
except Exception as e:
236-
_LOG.error("Failed to load language '%s': %s", locale, e)
230+
data = pkgutil.get_data("pysma", f"l10n/{locale}.json")
231+
if data is None:
237232
return {}
233+
return json.loads(data)
238234

239235
async def _read_body(self, url: str, payload: dict) -> dict:
240236
"""Parse the json returned by the device and extract result.

src/tests/test_sma_webconnect.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -504,18 +504,16 @@ async def test_unsupported_lang(
504504
) -> None:
505505
"""Test fallback language when requested language is not available locally."""
506506

507-
def read_text_side_effect(*args, **kwargs):
508-
path = str(args[1])
509-
if path.endswith("none.json"):
510-
return None
511-
if path.endswith("de-CH.json"):
512-
raise FileNotFoundError
513-
if path.endswith("en-US.json"):
507+
def get_data_side_effect(package: str, resource: str) -> str | None:
508+
if resource.endswith("en-US.json"):
514509
return json.dumps({"key": "value"})
515510

516-
mock_get_data.side_effect = read_text_side_effect
511+
return None
517512

518-
sma = SMAWebConnect(None, self.host, "pass", lang="de-CH")
513+
mock_get_data.side_effect = get_data_side_effect
514+
515+
session = aiohttp.ClientSession()
516+
sma = SMAWebConnect(session, self.host, "pass", lang="de-CH")
519517

520518
l10n = await sma._read_l10n()
521519

@@ -531,11 +529,3 @@ def read_text_side_effect(*args, **kwargs):
531529
l10n2 = await sma._read_l10n()
532530
assert mock_get_data.call_count == 2
533531
assert l10n == l10n2
534-
535-
# Cover None return
536-
sma = SMAWebConnect(None, self.host, "pass", lang="none")
537-
l10n3 = await sma._read_l10n()
538-
539-
# Fallback language must be loaded
540-
assert l10n3
541-
assert l10n3["key"] == "value"

0 commit comments

Comments
 (0)