mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Add typing in dynalite and activate mypy (#53238)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
9b705ad6df
commit
193d1b945b
@ -52,6 +52,7 @@ from .const import (
|
|||||||
SERVICE_REQUEST_AREA_PRESET,
|
SERVICE_REQUEST_AREA_PRESET,
|
||||||
SERVICE_REQUEST_CHANNEL_LEVEL,
|
SERVICE_REQUEST_CHANNEL_LEVEL,
|
||||||
)
|
)
|
||||||
|
from .convert_config import convert_config
|
||||||
|
|
||||||
|
|
||||||
def num_string(value: int | str) -> str:
|
def num_string(value: int | str) -> str:
|
||||||
@ -263,7 +264,7 @@ async def async_entry_changed(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up a bridge from a config entry."""
|
"""Set up a bridge from a config entry."""
|
||||||
LOGGER.debug("Setting up entry %s", entry.data)
|
LOGGER.debug("Setting up entry %s", entry.data)
|
||||||
bridge = DynaliteBridge(hass, entry.data)
|
bridge = DynaliteBridge(hass, convert_config(entry.data))
|
||||||
# need to do it before the listener
|
# need to do it before the listener
|
||||||
hass.data[DOMAIN][entry.entry_id] = bridge
|
hass.data[DOMAIN][entry.entry_id] = bridge
|
||||||
entry.async_on_unload(entry.add_update_listener(async_entry_changed))
|
entry.async_on_unload(entry.add_update_listener(async_entry_changed))
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Code to handle a Dynalite bridge."""
|
"""Code to handle a Dynalite bridge."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from types import MappingProxyType
|
||||||
from typing import Any, Callable
|
from typing import Any, Callable
|
||||||
|
|
||||||
from dynalite_devices_lib.dynalite_devices import (
|
from dynalite_devices_lib.dynalite_devices import (
|
||||||
@ -27,9 +28,8 @@ class DynaliteBridge:
|
|||||||
def __init__(self, hass: HomeAssistant, config: dict[str, Any]) -> None:
|
def __init__(self, hass: HomeAssistant, config: dict[str, Any]) -> None:
|
||||||
"""Initialize the system based on host parameter."""
|
"""Initialize the system based on host parameter."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.area = {}
|
self.async_add_devices: dict[str, Callable] = {}
|
||||||
self.async_add_devices = {}
|
self.waiting_devices: dict[str, list[str]] = {}
|
||||||
self.waiting_devices = {}
|
|
||||||
self.host = config[CONF_HOST]
|
self.host = config[CONF_HOST]
|
||||||
# Configure the dynalite devices
|
# Configure the dynalite devices
|
||||||
self.dynalite_devices = DynaliteDevices(
|
self.dynalite_devices = DynaliteDevices(
|
||||||
@ -37,7 +37,7 @@ class DynaliteBridge:
|
|||||||
update_device_func=self.update_device,
|
update_device_func=self.update_device,
|
||||||
notification_func=self.handle_notification,
|
notification_func=self.handle_notification,
|
||||||
)
|
)
|
||||||
self.dynalite_devices.configure(convert_config(config))
|
self.dynalite_devices.configure(config)
|
||||||
|
|
||||||
async def async_setup(self) -> bool:
|
async def async_setup(self) -> bool:
|
||||||
"""Set up a Dynalite bridge."""
|
"""Set up a Dynalite bridge."""
|
||||||
@ -45,7 +45,7 @@ class DynaliteBridge:
|
|||||||
LOGGER.debug("Setting up bridge - host %s", self.host)
|
LOGGER.debug("Setting up bridge - host %s", self.host)
|
||||||
return await self.dynalite_devices.async_setup()
|
return await self.dynalite_devices.async_setup()
|
||||||
|
|
||||||
def reload_config(self, config: dict[str, Any]) -> None:
|
def reload_config(self, config: MappingProxyType[str, Any]) -> None:
|
||||||
"""Reconfigure a bridge when config changes."""
|
"""Reconfigure a bridge when config changes."""
|
||||||
LOGGER.debug("Reloading bridge - host %s, config %s", self.host, config)
|
LOGGER.debug("Reloading bridge - host %s, config %s", self.host, config)
|
||||||
self.dynalite_devices.configure(convert_config(config))
|
self.dynalite_devices.configure(convert_config(config))
|
||||||
|
@ -8,6 +8,7 @@ from homeassistant.const import CONF_HOST
|
|||||||
|
|
||||||
from .bridge import DynaliteBridge
|
from .bridge import DynaliteBridge
|
||||||
from .const import DOMAIN, LOGGER
|
from .const import DOMAIN, LOGGER
|
||||||
|
from .convert_config import convert_config
|
||||||
|
|
||||||
|
|
||||||
class DynaliteFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
class DynaliteFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
@ -25,11 +26,13 @@ class DynaliteFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
host = import_info[CONF_HOST]
|
host = import_info[CONF_HOST]
|
||||||
for entry in self._async_current_entries():
|
for entry in self._async_current_entries():
|
||||||
if entry.data[CONF_HOST] == host:
|
if entry.data[CONF_HOST] == host:
|
||||||
if entry.data != import_info:
|
self.hass.config_entries.async_update_entry(
|
||||||
self.hass.config_entries.async_update_entry(entry, data=import_info)
|
entry, data=dict(import_info)
|
||||||
|
)
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
# New entry
|
# New entry
|
||||||
bridge = DynaliteBridge(self.hass, import_info)
|
bridge = DynaliteBridge(self.hass, convert_config(import_info))
|
||||||
if not await bridge.async_setup():
|
if not await bridge.async_setup():
|
||||||
LOGGER.error("Unable to setup bridge - import info=%s", import_info)
|
LOGGER.error("Unable to setup bridge - import info=%s", import_info)
|
||||||
return self.async_abort(reason="no_connection")
|
return self.async_abort(reason="no_connection")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Convert the HA config to the dynalite config."""
|
"""Convert the HA config to the dynalite config."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from types import MappingProxyType
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from dynalite_devices_lib import const as dyn_const
|
from dynalite_devices_lib import const as dyn_const
|
||||||
@ -136,7 +137,9 @@ def convert_template(config: dict[str, Any]) -> dict[str, Any]:
|
|||||||
return convert_with_map(config, my_map)
|
return convert_with_map(config, my_map)
|
||||||
|
|
||||||
|
|
||||||
def convert_config(config: dict[str, Any]) -> dict[str, Any]:
|
def convert_config(
|
||||||
|
config: dict[str, Any] | MappingProxyType[str, Any]
|
||||||
|
) -> dict[str, Any]:
|
||||||
"""Convert a config dict by replacing component consts with library consts."""
|
"""Convert a config dict by replacing component consts with library consts."""
|
||||||
my_map = {
|
my_map = {
|
||||||
CONF_NAME: dyn_const.CONF_NAME,
|
CONF_NAME: dyn_const.CONF_NAME,
|
||||||
|
@ -43,7 +43,7 @@ class DynaliteBase(Entity):
|
|||||||
"""Initialize the base class."""
|
"""Initialize the base class."""
|
||||||
self._device = device
|
self._device = device
|
||||||
self._bridge = bridge
|
self._bridge = bridge
|
||||||
self._unsub_dispatchers = []
|
self._unsub_dispatchers: list[Callable[[], None]] = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
|
3
mypy.ini
3
mypy.ini
@ -1139,9 +1139,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.doorbird.*]
|
[mypy-homeassistant.components.doorbird.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.dynalite.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.edl21.*]
|
[mypy-homeassistant.components.edl21.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.dhcp.*",
|
"homeassistant.components.dhcp.*",
|
||||||
"homeassistant.components.directv.*",
|
"homeassistant.components.directv.*",
|
||||||
"homeassistant.components.doorbird.*",
|
"homeassistant.components.doorbird.*",
|
||||||
"homeassistant.components.dynalite.*",
|
|
||||||
"homeassistant.components.edl21.*",
|
"homeassistant.components.edl21.*",
|
||||||
"homeassistant.components.elkm1.*",
|
"homeassistant.components.elkm1.*",
|
||||||
"homeassistant.components.emonitor.*",
|
"homeassistant.components.emonitor.*",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user