Skip to content

Commit b562c8f

Browse files
authored
Release 1.6.2 (#99)
2 parents 2198eb2 + 77323b9 commit b562c8f

File tree

10 files changed

+333
-17
lines changed

10 files changed

+333
-17
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
main @schizza
1+
* @schizza

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
## Changelog
22

3+
## 1.6.2
4+
5+
## 🐛 Opravy chyb
6+
7+
**Fix school year bounds (#97) @schizza**
8+
9+
- Opravena chyba získávání počátečního data školního roku pro `Nástěnku` a `Zprávy`
10+
11+
**Fixed issue when cached schools will hang initialization. (#98) @schizza**
12+
13+
- Opravena chyba, kdy při inicializaci komponenty mohlo dojít k zasekuní na načítací obrazovce
14+
315
## 1.6.1
416

517
## 🐛 Opravy chyb

bump-version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.bumpversion]
2-
current_version = "1.6.1"
2+
current_version = "1.6.2"
33
commit = false
44
tag = false
55

custom_components/bakalari/api.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
RATE_LIMIT_EXCEEDED,
3232
ChildRecord,
3333
)
34-
from .utils import ensure_child_record, redact_child_info
34+
from .utils import ensure_child_record, redact_child_info, school_year_bounds
3535

3636
_LOGGER = logging.getLogger(__name__)
3737
_fetch_lock: asyncio.Lock = asyncio.Lock()
@@ -394,8 +394,7 @@ async def async_get_messages(self, lib) -> list[MessageContainer]:
394394

395395
today = datetime.today().date()
396396

397-
# TODO: change to actual year, while sensors are refactored!
398-
start_of_school_year = datetime(year=today.year, month=10, day=1).date()
397+
start_of_school_year, _ = school_year_bounds(today)
399398

400399
_LOGGER.debug(
401400
"[class=%s module=%s] Fetching messages for child_id=%s",
@@ -432,7 +431,7 @@ async def async_fetch_noticeboard(self, lib) -> list[MessageContainer]:
432431
messages = await _noticeboard.fetch_noticeboard()
433432

434433
today = datetime.today().date()
435-
start_of_school_year = datetime(year=today.year, month=10, day=1).date()
434+
start_of_school_year, _ = school_year_bounds(today)
436435

437436
if messages.count_messages():
438437
return messages.get_messages_by_date(start_of_school_year, today)

custom_components/bakalari/config_flow.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(self) -> None:
4040
self._schools: Schools | None = None
4141
self._loading_task = None
4242
self._reauth_data: dict | None = None
43+
self._loading_error: str | None = None
4344

4445
async def _load_schools(self) -> bool:
4546
"""Load schools from cache or fetch new ones from server."""
@@ -63,6 +64,7 @@ async def _load_schools(self) -> bool:
6364
self.__class__.__name__,
6465
__name__,
6566
)
67+
self._loading_error = "cannot_connect"
6668
return False
6769

6870
await schools_storage.async_save(schools_cache.school_list)
@@ -71,17 +73,24 @@ async def _load_schools(self) -> bool:
7173
self.__class__.__name__,
7274
__name__,
7375
)
74-
else:
75-
_LOGGER.info(
76-
"[class=%s module=%s] Schools loaded from cache.",
77-
self.__class__.__name__,
78-
__name__,
79-
)
80-
return False
76+
return True
77+
78+
_LOGGER.info(
79+
"[class=%s module=%s] Schools loaded from cache.",
80+
self.__class__.__name__,
81+
__name__,
82+
)
83+
return True
8184

8285
async def async_step_user(self, user_input=None) -> config_entries.ConfigFlowResult:
8386
"""Handle the initial step."""
8487

88+
# After progress finishes, HA will re-enter this step; at that point we can
89+
# either continue or show an error with a retry button.
90+
if user_input is not None and user_input.get("retry"):
91+
self._loading_task = None
92+
self._loading_error = None
93+
8594
if self._loading_task is None:
8695
self._loading_task = self.hass.async_create_task(self._load_schools())
8796

@@ -91,6 +100,34 @@ async def async_step_user(self, user_input=None) -> config_entries.ConfigFlowRes
91100
progress_task=self._loading_task,
92101
)
93102

103+
# Task exists -> either still running or already finished.
104+
if not self._loading_task.done():
105+
return self.async_show_progress(
106+
step_id="user",
107+
progress_action="loading_schools",
108+
progress_task=self._loading_task,
109+
)
110+
111+
try:
112+
ok = bool(self._loading_task.result())
113+
except Exception: # noqa: BLE001 - surface as HA form error
114+
_LOGGER.exception(
115+
"[class=%s module=%s] Unexpected error while loading schools",
116+
self.__class__.__name__,
117+
__name__,
118+
)
119+
ok = False
120+
self._loading_error = "unknown"
121+
122+
if not ok:
123+
# Reset task so user can retry.
124+
self._loading_task = None
125+
return self.async_show_form(
126+
step_id="user",
127+
data_schema=vol.Schema({vol.Optional("retry", default=True): bool}),
128+
errors={"base": self._loading_error or "cannot_connect"},
129+
)
130+
94131
return self.async_show_progress_done(next_step_id="complete")
95132

96133
async def async_step_complete(

custom_components/bakalari/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
MANUFACTURER = "Bakaláři pro HomeAssistant"
99
MODEL = "Bakaláři backend"
1010

11-
LIB_VERSION: Final = "1.6.1"
11+
LIB_VERSION: Final = "1.6.2"
1212
API_VERSION: Final = "0.10.0"
1313
SW_VERSION: Final = f"API: {API_VERSION} Library: {LIB_VERSION}"
1414
CONF_CHILDREN: Final = "children"

custom_components/bakalari/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"requirements": [
1717
"async-bakalari-api==0.10.0"
1818
],
19-
"version": "1.6.1"
19+
"version": "1.6.2"
2020
}

custom_components/bakalari/translations/cs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"error": {
55
"loading_failed": "Nepodařilo se načíst školy z serveru ani s cache!",
66
"invalid_auth": "Neplatné přihlašovací údaje!",
7-
"cannot_connect": "Nelze se připojit k serveru!"
7+
"cannot_connect": "Nelze se připojit k serveru!",
8+
"unknown": "Neznámá chyba."
89
},
910
"abort": {
1011
"reauth_entry_not_found": "Nepodařilo se najít dítě s daným přihlašovacím jménem.",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "bakalari-ha"
3-
version = "1.6.1"
3+
version = "1.6.2"
44
description = "Home Assistant custom integration for Bakaláři API endpoints."
55
readme = "README.md"
66
requires-python = ">=3.13"

0 commit comments

Comments
 (0)