Skip to content

Commit bde12af

Browse files
committed
스마트 앱 초기 설정 관련부분 로직 개선
스마트 앱 초기 설정 관련부분 로직 개선
1 parent f2aa67a commit bde12af

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

custom_components/smartthings_customize/__init__.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,24 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
152152
remove_entry = False
153153

154154
app = await async_get_app_info(hass, entry.data[CONF_APP_ID], entry.data[CONF_ACCESS_TOKEN])
155-
155+
if app is None:
156+
_LOGGER.warning("App info is None. Clearing cached app info and retrying. app_id=%s", entry.data[CONF_APP_ID])
157+
# 캐시 지우고 다시 앱 정보 요청
158+
await async_remove_app_info(hass, entry.data[CONF_APP_ID])
159+
app = await async_get_app_info(hass, entry.data[CONF_APP_ID], entry.data[CONF_ACCESS_TOKEN])
160+
161+
# 그래도 앱 정보를 못 찾으면, SmartThings API로 직접 조회
162+
if app is None:
163+
try:
164+
app = await api.app(entry.data[CONF_APP_ID])
165+
except ClientResponseError as ex:
166+
_LOGGER.exception("Failed to fetch app from API. status=%s", getattr(ex, "status", None))
167+
raise ConfigEntryNotReady from ex
168+
169+
if app is None:
170+
_LOGGER.error("Unable to load SmartApp info (app is None). app_id=%s", entry.data[CONF_APP_ID])
171+
raise ConfigEntryNotReady
172+
156173
try:
157174
# See if the app is already setup. This occurs when there are
158175
# installs in multiple SmartThings locations (valid use-case)
@@ -170,7 +187,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
170187

171188
# Get scenes
172189
scenes = await async_get_entry_scenes(entry, api)
173-
190+
174191
# Get SmartApp token to sync subscriptions
175192
token = await api.generate_tokens(
176193
entry.data[CONF_CLIENT_ID],
@@ -184,7 +201,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
184201
}
185202
)
186203

187-
api = SmartThings_custom(async_get_clientsession(hass), entry.data[CONF_ACCESS_TOKEN])
204+
api = SmartThings_custom(async_get_clientsession(hass), token.access_token)
188205

189206
# Get devices and their current status
190207
devices = await api.devices(location_ids=[installed_app.location_id])

0 commit comments

Comments
 (0)