Skip to content

Commit 51250bf

Browse files
committed
Fixed mypy errors
1 parent 8452a1d commit 51250bf

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

custom_components/hon/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from pathlib import Path
33
from typing import Any
44

5-
import voluptuous as vol # type: ignore[import-untyped]
5+
import voluptuous as vol
66
from homeassistant.config_entries import ConfigEntry
77
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
88
from homeassistant.helpers import config_validation as cv, aiohttp_client
9-
from homeassistant.core import HomeAssistant
9+
from homeassistant.core import HomeAssistant, Callable
1010
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
1111
from pyhon import Hon
1212

@@ -27,6 +27,16 @@
2727
)
2828

2929

30+
def make_threadsafe_callback(
31+
hass: HomeAssistant, callback: Callable[..., None]
32+
) -> Callable[..., None]:
33+
"""Wrap a callback so it's always called inside the event loop thread."""
34+
35+
def wrapper(*args: Any, **kwargs: Any) -> None:
36+
hass.loop.call_soon_threadsafe(callback, *args, **kwargs)
37+
38+
return wrapper
39+
3040
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
3141
session = aiohttp_client.async_get_clientsession(hass)
3242
if (config_dir := hass.config.config_dir) is None:
@@ -48,10 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4858
coordinator: DataUpdateCoordinator[dict[str, Any]] = DataUpdateCoordinator(
4959
hass, _LOGGER, name=DOMAIN
5060
)
51-
def make_threadsafe_callback(hass, callback):
52-
def wrapper(*args, **kwargs):
53-
hass.loop.call_soon_threadsafe(callback, *args, **kwargs)
54-
return wrapper
61+
5562
hon.subscribe_updates(make_threadsafe_callback(hass, coordinator.async_set_updated_data))
5663

5764
hass.data.setdefault(DOMAIN, {})

custom_components/hon/config_flow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import logging
22
from typing import Any
33

4-
import voluptuous as vol # type: ignore[import-untyped]
4+
import voluptuous as vol
55
from homeassistant import config_entries
66
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
7-
from homeassistant.data_entry_flow import FlowResult
7+
from homeassistant.config_entries import ConfigFlowResult
88

99
from .const import DOMAIN
1010

@@ -21,7 +21,7 @@ def __init__(self) -> None:
2121

2222
async def async_step_user(
2323
self, user_input: dict[str, Any] | None = None
24-
) -> FlowResult:
24+
) -> ConfigFlowResult:
2525
if user_input is None:
2626
return self.async_show_form(
2727
step_id="user",
@@ -53,5 +53,5 @@ async def async_step_user(
5353
},
5454
)
5555

56-
async def async_step_import(self, user_input: dict[str, str]) -> FlowResult:
56+
async def async_step_import(self, user_input: dict[str, str]) -> ConfigFlowResult:
5757
return await self.async_step_user(user_input)

0 commit comments

Comments
 (0)