Add type hints for config entry update listeners (#65412)

This commit is contained in:
epenet 2022-02-02 10:36:04 +01:00 committed by GitHub
parent 627be81531
commit a63e5c7ded
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 47 additions and 39 deletions

View file

@ -155,7 +155,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def update_listener(hass: HomeAssistant, entry: ConfigEntry): async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Update when config_entry options update.""" """Update when config_entry options update."""
router = hass.data[DOMAIN][entry.entry_id][DATA_ASUSWRT] router = hass.data[DOMAIN][entry.entry_id][DATA_ASUSWRT]

View file

@ -70,7 +70,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True return True
async def update_listener(hass: HomeAssistant, entry: ConfigEntry): async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload to update options.""" """Reload to update options."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -13,6 +13,7 @@ from axis.streammanager import SIGNAL_PLAYING, STATE_STOPPED
from homeassistant.components import mqtt from homeassistant.components import mqtt
from homeassistant.components.mqtt import DOMAIN as MQTT_DOMAIN from homeassistant.components.mqtt import DOMAIN as MQTT_DOMAIN
from homeassistant.components.mqtt.models import ReceiveMessage from homeassistant.components.mqtt.models import ReceiveMessage
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
CONF_NAME, CONF_NAME,
@ -156,7 +157,9 @@ class AxisNetworkDevice:
async_dispatcher_send(self.hass, self.signal_new_event, event_id) async_dispatcher_send(self.hass, self.signal_new_event, event_id)
@staticmethod @staticmethod
async def async_new_address_callback(hass, entry): async def async_new_address_callback(
hass: HomeAssistant, entry: ConfigEntry
) -> None:
"""Handle signals of device getting new address. """Handle signals of device getting new address.
Called when config entry is updated. Called when config entry is updated.

View file

@ -115,7 +115,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True return True
async def update_listener(hass, config_entry): async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Update when config_entry options update.""" """Update when config_entry options update."""
_LOGGER.debug("Config entry was updated, rerunning setup") _LOGGER.debug("Config entry was updated, rerunning setup")
await hass.config_entries.async_reload(config_entry.entry_id) await hass.config_entries.async_reload(config_entry.entry_id)

View file

@ -4,9 +4,9 @@ import asyncio
import async_timeout import async_timeout
from pydeconz import DeconzSession, errors, group, light, sensor from pydeconz import DeconzSession, errors, group, light, sensor
from homeassistant.config_entries import SOURCE_HASSIO from homeassistant.config_entries import SOURCE_HASSIO, ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import ( from homeassistant.helpers import (
aiohttp_client, aiohttp_client,
@ -193,7 +193,9 @@ class DeconzGateway:
return True return True
@staticmethod @staticmethod
async def async_config_entry_updated(hass, entry) -> None: async def async_config_entry_updated(
hass: HomeAssistant, entry: ConfigEntry
) -> None:
"""Handle signals of config entry being updated. """Handle signals of config entry being updated.
This is a static method because a class method (bound method), can not be used with weak references. This is a static method because a class method (bound method), can not be used with weak references.

View file

@ -88,6 +88,6 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
return unload_ok return unload_ok
async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry): async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(config_entry.entry_id) await hass.config_entries.async_reload(config_entry.entry_id)

View file

@ -81,6 +81,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def update_listener(hass, entry): async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -184,7 +184,7 @@ async def _async_register_events(hass, doorstation):
return True return True
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
config_entry_id = entry.entry_id config_entry_id = entry.entry_id
doorstation = hass.data[DOMAIN][config_entry_id][DOOR_STATION] doorstation = hass.data[DOMAIN][config_entry_id][DOOR_STATION]

View file

@ -115,7 +115,7 @@ async def async_setup_entry(
] = forked_daapd_updater ] = forked_daapd_updater
async def update_listener(hass, entry): async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
async_dispatcher_send( async_dispatcher_send(
hass, SIGNAL_CONFIG_OPTIONS_UPDATE.format(entry.entry_id), entry.options hass, SIGNAL_CONFIG_OPTIONS_UPDATE.format(entry.entry_id), entry.options

View file

@ -55,7 +55,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def update_listener(hass, config_entry): async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Update listener.""" """Update listener."""
await hass.config_entries.async_reload(config_entry.entry_id) await hass.config_entries.async_reload(config_entry.entry_id)

View file

@ -163,7 +163,7 @@ class GlancesData:
) )
@staticmethod @staticmethod
async def async_options_updated(hass, entry): async def async_options_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Triggered by config entry options updates.""" """Triggered by config entry options updates."""
hass.data[DOMAIN][entry.entry_id].set_scan_interval( hass.data[DOMAIN][entry.entry_id].set_scan_interval(
entry.options[CONF_SCAN_INTERVAL] entry.options[CONF_SCAN_INTERVAL]

View file

@ -94,7 +94,7 @@ def _async_import_options_from_data_if_missing(hass: HomeAssistant, entry: Confi
hass.config_entries.async_update_entry(entry, options=options) hass.config_entries.async_update_entry(entry, options=options)
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
async_dispatcher_send( async_dispatcher_send(
hass, f"{HARMONY_OPTIONS_UPDATE}-{entry.unique_id}", entry.options hass, f"{HARMONY_OPTIONS_UPDATE}-{entry.unique_id}", entry.options

View file

@ -313,7 +313,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True return True
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
if entry.source == SOURCE_IMPORT: if entry.source == SOURCE_IMPORT:
return return

View file

@ -55,7 +55,7 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
return True return True
async def update_listener(hass, config) -> None: async def update_listener(hass: HomeAssistant, config: ConfigEntry) -> None:
"""Update listener.""" """Update listener."""
await hass.config_entries.async_reload(config.entry_id) await hass.config_entries.async_reload(config.entry_id)

View file

@ -201,7 +201,7 @@ class IslamicPrayerClient:
) )
@staticmethod @staticmethod
async def async_options_updated(hass, entry): async def async_options_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Triggered by config entry options updates.""" """Triggered by config entry options updates."""
if hass.data[DOMAIN].event_unsub: if hass.data[DOMAIN].event_unsub:
hass.data[DOMAIN].event_unsub() hass.data[DOMAIN].event_unsub()

View file

@ -227,7 +227,7 @@ async def async_setup_entry(
async def _async_update_listener( async def _async_update_listener(
hass: HomeAssistant, entry: config_entries.ConfigEntry hass: HomeAssistant, entry: config_entries.ConfigEntry
): ) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -96,7 +96,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
return unload_ok return unload_ok
async def update_listener(hass, entry): async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -281,7 +281,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def async_entry_updated(hass: HomeAssistant, entry: ConfigEntry): async def async_entry_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload the config entry when options change.""" """Reload the config entry when options change."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -186,6 +186,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -63,6 +63,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -115,7 +115,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -83,7 +83,7 @@ CONFIG_SCHEMA = vol.Schema(
PLATFORMS = [Platform.BINARY_SENSOR, Platform.CLIMATE, Platform.SENSOR] PLATFORMS = [Platform.BINARY_SENSOR, Platform.CLIMATE, Platform.SENSOR]
async def options_updated(hass, entry): async def options_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
gateway = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][entry.data[CONF_ID]] gateway = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][entry.data[CONF_ID]]
async_dispatcher_send(hass, gateway.options_update_signal, entry) async_dispatcher_send(hass, gateway.options_update_signal, entry)

View file

@ -180,7 +180,7 @@ async def async_unload_platforms(hass: HomeAssistant, entry: ConfigEntry, platfo
return unloaded return unloaded
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -265,7 +265,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def async_options_updated(hass, entry): async def async_options_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Triggered by config entry options updates.""" """Triggered by config entry options updates."""
server_id = entry.data[CONF_SERVER_IDENTIFIER] server_id = entry.data[CONF_SERVER_IDENTIFIER]

View file

@ -145,7 +145,7 @@ async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True return True
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
coordinator = hass.data[DOMAIN][entry.entry_id][COORDINATOR] coordinator = hass.data[DOMAIN][entry.entry_id][COORDINATOR]
update_interval = entry.options.get(CONF_SCAN_INTERVAL) update_interval = entry.options.get(CONF_SCAN_INTERVAL)

View file

@ -80,7 +80,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -111,7 +111,7 @@ async def async_disconnect_or_timeout(hass, roomba):
return True return True
async def async_update_options(hass, config_entry): async def async_update_options(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Update options.""" """Update options."""
await hass.config_entries.async_reload(config_entry.entry_id) await hass.config_entries.async_reload(config_entry.entry_id)

View file

@ -92,7 +92,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
async def async_update_listener(hass: HomeAssistant, entry: ConfigEntry): async def async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -60,7 +60,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True return True
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -103,7 +103,7 @@ def _async_import_options_from_data_if_missing(hass: HomeAssistant, entry: Confi
hass.config_entries.async_update_entry(entry, options=options) hass.config_entries.async_update_entry(entry, options=options)
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -107,7 +107,7 @@ def get_poll_interval(entry: ConfigEntry) -> timedelta:
) )
async def update_listener(hass, entry): async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
wall_connector_data: WallConnectorData = hass.data[DOMAIN][entry.entry_id] wall_connector_data: WallConnectorData = hass.data[DOMAIN][entry.entry_id]
wall_connector_data.update_coordinator.update_interval = get_poll_interval(entry) wall_connector_data.update_coordinator.update_interval = get_poll_interval(entry)

View file

@ -330,7 +330,7 @@ class TransmissionClient:
) )
@staticmethod @staticmethod
async def async_options_updated(hass, entry): async def async_options_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Triggered by config entry options updates.""" """Triggered by config entry options updates."""
tm_client = hass.data[DOMAIN][entry.entry_id] tm_client = hass.data[DOMAIN][entry.entry_id]
tm_client.set_scan_interval(entry.options[CONF_SCAN_INTERVAL]) tm_client.set_scan_interval(entry.options[CONF_SCAN_INTERVAL])

View file

@ -26,6 +26,7 @@ from aiounifi.events import (
from aiounifi.websocket import STATE_DISCONNECTED, STATE_RUNNING from aiounifi.websocket import STATE_DISCONNECTED, STATE_RUNNING
import async_timeout import async_timeout
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
CONF_PASSWORD, CONF_PASSWORD,
@ -34,7 +35,7 @@ from homeassistant.const import (
CONF_VERIFY_SSL, CONF_VERIFY_SSL,
Platform, Platform,
) )
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import aiohttp_client, entity_registry as er from homeassistant.helpers import aiohttp_client, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
@ -397,7 +398,9 @@ class UniFiController:
del self._heartbeat_time[unique_id] del self._heartbeat_time[unique_id]
@staticmethod @staticmethod
async def async_config_entry_updated(hass, config_entry) -> None: async def async_config_entry_updated(
hass: HomeAssistant, config_entry: ConfigEntry
) -> None:
"""Handle signals of config entry being updated. """Handle signals of config entry being updated.
If config entry is updated due to reauth flow If config entry is updated due to reauth flow

View file

@ -177,7 +177,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
return True return True
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -58,7 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True return True
async def async_update_options(hass: HomeAssistant, entry: ConfigEntry): async def async_update_options(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Update options.""" """Update options."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)

View file

@ -230,7 +230,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry): async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update.""" """Handle options update."""
await hass.config_entries.async_reload(entry.entry_id) await hass.config_entries.async_reload(entry.entry_id)