fix: defer curl_cffi import + ko translation placeholder + legacy safety_alert schema migration#16
Merged
Conversation
…legacy safety_alert schema
Three small fixes discovered while writing the README guide:
1. safety_alert/api.py — defer ``import curl_cffi`` from module top-level
to inside the request method. Importing curl_cffi triggers blocking
disk I/O (listdir on site-packages, read_text on METADATA) which HA
detects during async_setup_entry and warns:
Detected blocking call to listdir/read_text/open inside the event
loop by custom integration 'kr_component_kit' at
safety_alert/api.py, line 9: import curl_cffi
Lazy import defers those reads to the first HTTP request, by which
point the event loop can run them on the executor cleanly.
2. translations/ko.json — add ``{error}`` placeholder to the
cannot_connect error string so it matches en.json/ja.json. HA emits a
validation error otherwise:
Validation of translation placeholders for localized (ko) string
component.kr_component_kit.config.error.cannot_connect failed:
(set() != {'error'})
3. __init__.py — add backward-compat path for an even older
safety_alert entry.data schema that stored regions under ``area_codes``
(plural, bare list). Entries on that legacy schema produced a
17-sensor entity layout that's now orphaned (state unavailable) and
sets neither ``regions`` nor ``area_code`` (single), so they fall
through both existing branches and end up with regions=[] (no
coordinator setup, no entity creation). The new mapping turns each
legacy code into the current {"code", "name"} shape so the entry
auto-heals on the next HA start.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Critical regression fix. Previous config_flow exposed only: - 17 광역시도 (sido-level) - Seoul gu (autonomous districts within Seoul only) This meant users outside Seoul could only register at sido granularity — e.g. "경기도" but not "경기도 시흥시" — a hard downgrade from earlier versions of the integration that used safekorea.go.kr's region API to cascade through sido → sgg → emd. The region client (safety_alert/region_api.py) was still in the codebase but no longer wired into config_flow. This commit restores the three-step cascading flow: Step 1 (safety_alert): sido dropdown (hardcoded 17개) Step 2 (safety_alert_sgg): sgg dropdown for selected sido (live API) Step 3 (safety_alert_emd): emd dropdown for selected sgg (live API) Each step's "leave blank" option lets users stop at sido- or sgg-level granularity if they don't want per-동 alerts. Output is stored in the existing `regions[]` schema with `code` / `code2` / `code3` matching the __init__.py setup path that's been there all along. Field names sido_code / sgg_code / emd_code match the en.json labels that were already in the codebase from the original cascading flow (those translation keys were never removed even though config_flow had been simplified to a single dropdown). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Bundle with PR #16 fixes (curl_cffi lazy import, ko translation placeholder, legacy schema migration, cascading region dropdown restoration) for HACS update notification. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HA 로그와 실제 entity 상태 검증 결과 발견된 3가지 작은 버그 수정.
1. safety_alert/api.py — blocking I/O 제거 (lazy import)
HA 로그에서 발견:
import curl_cffi가 module top-level에 있어서 setup 단계에서 disk I/O 발생. lazy import로 변경 — 첫 HTTP 요청 시점으로 미룸. 그땐 event loop가 executor에서 안전하게 처리.2. translations/ko.json — cannot_connect placeholder 추가
HA validation 경고:
en.json/ja.json의cannot_connect는{error}placeholder 포함인데ko.json만 빠져 있었음. 일관성 맞춤.3. init.py — 안전알림 legacy
area_codesschema 마이그레이션실제 HA 인스턴스에서 발견: 이전 버전 안전알림 entry data가
area_codes(복수형 bare list) 로 저장되어 있어, 현재 코드가regions=[]로 떨어지고 entity 생성 0개. 결과적으로 이전 코드가 만든 17개 sensor entity가 orphan 상태로 남고 모두unavailable.이전 두 단계 fallback (
regions/area_code단일) 다음에area_codes케이스도 처리하도록 추가. 다음 HA 재시작 시 entry 가 자동 자가 치유.Test plan
Detected blocking call ... import curl_cffi메시지가 사라지는지 (HA 재시작 후)area_codesschema 가진 entry 가 다음 HA 재시작 시 entity 생성하는지 (사용자 실제 환경에서 검증 — 본 환경에서는 entry 삭제 후 재등록으로 새 schema 사용 중)Notes
이 PR은 PR #15 (README 개선)와 독립적. main에 머지된 후 docs PR도 이어서 머지하면 됨.
🤖 Generated with Claude Code