Skip to content

Commit da2e47a

Browse files
thematrixdevclaude
andcommitted
BREAKING: Require Home Assistant 2025.12+ (drop async_timeout and FlowResult)
- Replace deprecated `FlowResult` with `ConfigFlowResult` from `homeassistant.config_entries` - Replace `async_timeout.timeout` with `asyncio.timeout` (Python 3.11+) - Update OptionsFlow to use framework-injected `config_entry` instead of constructor parameter - Bump version to 14.0.0 Closes #21 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0a61189 commit da2e47a

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

custom_components/clphk/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44

55
import aiohttp
6-
import async_timeout
6+
import asyncio
77
from cryptography.hazmat.primitives import hashes
88
from cryptography.hazmat.primitives import serialization
99
from cryptography.hazmat.primitives.asymmetric import padding
@@ -53,7 +53,7 @@ async def request_otp(session, email, timeout=30):
5353
)).decode(),
5454
}
5555
try:
56-
async with async_timeout.timeout(timeout):
56+
async with asyncio.timeout(timeout):
5757
async with session.post(url, json=json_payload, headers=API_DEFAULT_HEADERS) as response:
5858
response.raise_for_status()
5959
data = await response.json()
@@ -74,7 +74,7 @@ async def verify_otp(session, email, otp, timeout=30):
7474
"otp": otp,
7575
}
7676
try:
77-
async with async_timeout.timeout(timeout):
77+
async with asyncio.timeout(timeout):
7878
async with session.post(url, json=json_payload, headers=API_DEFAULT_HEADERS) as response:
7979
response.raise_for_status()
8080
data = await response.json()

custom_components/clphk/config_flow.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
import re
88
from typing import Any
99

10-
import async_timeout
10+
import asyncio
11+
1112
import voluptuous as vol
1213
from homeassistant import config_entries
1314
from homeassistant.const import (
1415
CONF_NAME,
1516
CONF_TIMEOUT,
1617
CONF_TYPE,
1718
)
18-
from homeassistant.data_entry_flow import FlowResult
19+
from homeassistant.config_entries import ConfigFlowResult
1920
from homeassistant.helpers import aiohttp_client
2021
from homeassistant.helpers.selector import (
2122
BooleanSelector,
@@ -227,7 +228,7 @@ async def _validate_access_token(session, token: str, timeout: int = 30) -> tupl
227228
"Authorization": normalized,
228229
}
229230
try:
230-
async with async_timeout.timeout(timeout):
231+
async with asyncio.timeout(timeout):
231232
async with session.get(
232233
"https://api.clp.com.hk/ts1/ms/profile/accountdetails/myServicesCA",
233234
headers=headers,
@@ -247,21 +248,20 @@ async def _validate_access_token(session, token: str, timeout: int = 30) -> tupl
247248
class CLPHKOptionsFlowHandler(config_entries.OptionsFlow):
248249
"""Options flow: tokens -> options."""
249250

250-
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
251-
self.config_entry = config_entry
252-
self._merged_data = {**config_entry.data, **config_entry.options}
251+
def __init__(self) -> None:
253252
self._pending: dict[str, Any] = {}
254253

255-
async def async_step_init(self, user_input=None) -> FlowResult:
254+
async def async_step_init(self, user_input=None) -> ConfigFlowResult:
256255
return await self.async_step_tokens(user_input)
257256

258-
async def async_step_tokens(self, user_input=None) -> FlowResult:
257+
async def async_step_tokens(self, user_input=None) -> ConfigFlowResult:
259258
errors: dict[str, str] = {}
260259
if user_input is not None:
261260
access_token_input = user_input[CONF_ACCESS_TOKEN]
262261
refresh_token_input = user_input[CONF_REFRESH_TOKEN]
262+
merged = {**self.config_entry.data, **self.config_entry.options}
263263
session = aiohttp_client.async_get_clientsession(self.hass)
264-
timeout = int(self._merged_data.get(CONF_TIMEOUT, 30))
264+
timeout = int(merged.get(CONF_TIMEOUT, 30))
265265
normalized_access_token, error_key = await _validate_access_token(
266266
session=session,
267267
token=access_token_input,
@@ -279,7 +279,7 @@ async def async_step_tokens(self, user_input=None) -> FlowResult:
279279
self._pending[CONF_REFRESH_TOKEN] = normalized_refresh_token
280280
return await self.async_step_options()
281281

282-
defaults = self._merged_data
282+
defaults = {**self.config_entry.data, **self.config_entry.options}
283283
return self.async_show_form(
284284
step_id="tokens",
285285
data_schema=vol.Schema(
@@ -291,7 +291,7 @@ async def async_step_tokens(self, user_input=None) -> FlowResult:
291291
errors=errors,
292292
)
293293

294-
async def async_step_options(self, user_input=None) -> FlowResult:
294+
async def async_step_options(self, user_input=None) -> ConfigFlowResult:
295295
if user_input is not None:
296296
self.hass.config_entries.async_update_entry(
297297
self.config_entry,
@@ -307,7 +307,7 @@ async def async_step_options(self, user_input=None) -> FlowResult:
307307

308308
return self.async_show_form(
309309
step_id="options",
310-
data_schema=_build_options_schema(self._merged_data),
310+
data_schema=_build_options_schema({**self.config_entry.data, **self.config_entry.options}),
311311
errors={},
312312
)
313313

@@ -320,10 +320,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain="clphk"):
320320
def __init__(self) -> None:
321321
self._pending: dict[str, Any] = {}
322322

323-
async def async_step_user(self, user_input: dict[str, Any] | None = None) -> FlowResult:
323+
async def async_step_user(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
324324
return await self.async_step_tokens(user_input)
325325

326-
async def async_step_tokens(self, user_input: dict[str, Any] | None = None) -> FlowResult:
326+
async def async_step_tokens(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
327327
errors: dict[str, str] = {}
328328
if user_input is not None:
329329
access_token_input = user_input[CONF_ACCESS_TOKEN]
@@ -357,7 +357,7 @@ async def async_step_tokens(self, user_input: dict[str, Any] | None = None) -> F
357357
errors=errors,
358358
)
359359

360-
async def async_step_options(self, user_input: dict[str, Any] | None = None) -> FlowResult:
360+
async def async_step_options(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
361361
if user_input is not None:
362362
data = {
363363
**user_input,
@@ -374,4 +374,4 @@ async def async_step_options(self, user_input: dict[str, Any] | None = None) ->
374374

375375
@staticmethod
376376
def async_get_options_flow(config_entry):
377-
return CLPHKOptionsFlowHandler(config_entry)
377+
return CLPHKOptionsFlowHandler()

custom_components/clphk/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "13.0.1",
2+
"version": "14.0.0",
33
"issue_tracker": "https://github.com/thematrixdev/home-assistant-clp/issues",
44

55
"domain": "clphk",

custom_components/clphk/sensor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import logging
88

99
import aiohttp
10-
import async_timeout
1110
import homeassistant.helpers.config_validation as cv
1211
import pytz
1312
import voluptuous as vol
@@ -402,7 +401,7 @@ async def api_request(
402401
if headers:
403402
merged_headers.update(headers)
404403

405-
async with async_timeout.timeout(self._timeout):
404+
async with asyncio.timeout(self._timeout):
406405
response = await self._session.request(
407406
method,
408407
url,
@@ -501,7 +500,7 @@ async def _refresh_access_token(self):
501500
refresh_headers = dict(API_DEFAULT_HEADERS)
502501
refresh_headers["Content-Type"] = "application/json"
503502

504-
async with async_timeout.timeout(self._timeout):
503+
async with asyncio.timeout(self._timeout):
505504
response = await self._session.request(
506505
"POST",
507506
"https://api.clp.com.hk/ts1/ms/profile/identity/manage/account/refresh_token",

0 commit comments

Comments
 (0)