From d76993034e3cbdec286d9c47544bfff412a3780b Mon Sep 17 00:00:00 2001 From: jan iversen Date: Thu, 22 Apr 2021 22:23:36 +0200 Subject: [PATCH] Replace HomeAssistantType with HomeAssistant for integrations m* - n* (#49566) * Integration neato: rename HomeAssistantType to HomeAssistant. * Integration mysensors: rename HomeAssistantType to HomeAssistant. * Integration mobile_app: rename HomeAssistantType to HomeAssistant. * Integration minecraft_server: rename HomeAssistantType to HomeAssistant. * Clean up Co-authored-by: Martin Hjelmare --- .../components/minecraft_server/__init__.py | 12 +++++----- .../minecraft_server/binary_sensor.py | 4 ++-- .../components/minecraft_server/helpers.py | 4 ++-- .../components/minecraft_server/sensor.py | 4 ++-- .../components/mobile_app/__init__.py | 5 +++-- .../components/mobile_app/helpers.py | 5 ++--- .../components/mobile_app/webhook.py | 5 ++--- .../components/mysensors/__init__.py | 8 +++---- .../components/mysensors/binary_sensor.py | 5 ++--- homeassistant/components/mysensors/climate.py | 4 ++-- homeassistant/components/mysensors/cover.py | 4 ++-- .../components/mysensors/device_tracker.py | 6 ++--- homeassistant/components/mysensors/gateway.py | 21 ++++++++---------- homeassistant/components/mysensors/handler.py | 21 ++++++++---------- homeassistant/components/mysensors/helpers.py | 3 +-- homeassistant/components/mysensors/light.py | 5 ++--- homeassistant/components/mysensors/sensor.py | 4 ++-- homeassistant/components/mysensors/switch.py | 4 ++-- homeassistant/components/neato/__init__.py | 13 ++++++----- .../minecraft_server/test_config_flow.py | 22 +++++++++---------- .../components/mysensors/test_config_flow.py | 20 ++++++++--------- tests/components/mysensors/test_gateway.py | 4 ++-- tests/components/mysensors/test_init.py | 5 +++-- tests/components/neato/test_config_flow.py | 6 ++--- 24 files changed, 92 insertions(+), 102 deletions(-) diff --git a/homeassistant/components/minecraft_server/__init__.py b/homeassistant/components/minecraft_server/__init__.py index f466988cda4..e887f31ae0f 100644 --- a/homeassistant/components/minecraft_server/__init__.py +++ b/homeassistant/components/minecraft_server/__init__.py @@ -10,14 +10,14 @@ from mcstatus.server import MinecraftServer as MCStatus from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, ) from homeassistant.helpers.entity import Entity from homeassistant.helpers.event import async_track_time_interval -from homeassistant.helpers.typing import ConfigType, HomeAssistantType +from homeassistant.helpers.typing import ConfigType from . import helpers from .const import DOMAIN, MANUFACTURER, SCAN_INTERVAL, SIGNAL_NAME_PREFIX @@ -27,7 +27,7 @@ PLATFORMS = ["binary_sensor", "sensor"] _LOGGER = logging.getLogger(__name__) -async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry) -> bool: +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up Minecraft Server from a config entry.""" domain_data = hass.data.setdefault(DOMAIN, {}) @@ -52,9 +52,7 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry) return True -async def async_unload_entry( - hass: HomeAssistantType, config_entry: ConfigEntry -) -> bool: +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Unload Minecraft Server config entry.""" unique_id = config_entry.unique_id server = hass.data[DOMAIN][unique_id] @@ -81,7 +79,7 @@ class MinecraftServer: _MAX_RETRIES_STATUS = 3 def __init__( - self, hass: HomeAssistantType, unique_id: str, config_data: ConfigType + self, hass: HomeAssistant, unique_id: str, config_data: ConfigType ) -> None: """Initialize server instance.""" self._hass = hass diff --git a/homeassistant/components/minecraft_server/binary_sensor.py b/homeassistant/components/minecraft_server/binary_sensor.py index aadcba44e85..79325f9c90c 100644 --- a/homeassistant/components/minecraft_server/binary_sensor.py +++ b/homeassistant/components/minecraft_server/binary_sensor.py @@ -5,14 +5,14 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntity, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.helpers.typing import HomeAssistantType +from homeassistant.core import HomeAssistant from . import MinecraftServer, MinecraftServerEntity from .const import DOMAIN, ICON_STATUS, NAME_STATUS async def async_setup_entry( - hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities + hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities ) -> None: """Set up the Minecraft Server binary sensor platform.""" server = hass.data[DOMAIN][config_entry.unique_id] diff --git a/homeassistant/components/minecraft_server/helpers.py b/homeassistant/components/minecraft_server/helpers.py index f6409ce525d..13ec4cd1afb 100644 --- a/homeassistant/components/minecraft_server/helpers.py +++ b/homeassistant/components/minecraft_server/helpers.py @@ -6,12 +6,12 @@ from typing import Any import aiodns from homeassistant.const import CONF_HOST, CONF_PORT -from homeassistant.helpers.typing import HomeAssistantType +from homeassistant.core import HomeAssistant from .const import SRV_RECORD_PREFIX -async def async_check_srv_record(hass: HomeAssistantType, host: str) -> dict[str, Any]: +async def async_check_srv_record(hass: HomeAssistant, host: str) -> dict[str, Any]: """Check if the given host is a valid Minecraft SRV record.""" # Check if 'host' is a valid SRV record. return_value = None diff --git a/homeassistant/components/minecraft_server/sensor.py b/homeassistant/components/minecraft_server/sensor.py index 3d77d9e2772..651c2762c55 100644 --- a/homeassistant/components/minecraft_server/sensor.py +++ b/homeassistant/components/minecraft_server/sensor.py @@ -6,7 +6,7 @@ from typing import Any from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import TIME_MILLISECONDS -from homeassistant.helpers.typing import HomeAssistantType +from homeassistant.core import HomeAssistant from . import MinecraftServer, MinecraftServerEntity from .const import ( @@ -30,7 +30,7 @@ from .const import ( async def async_setup_entry( - hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities + hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities ) -> None: """Set up the Minecraft Server sensor platform.""" server = hass.data[DOMAIN][config_entry.unique_id] diff --git a/homeassistant/components/mobile_app/__init__.py b/homeassistant/components/mobile_app/__init__.py index e63698d3eb5..1321818b91f 100644 --- a/homeassistant/components/mobile_app/__init__.py +++ b/homeassistant/components/mobile_app/__init__.py @@ -8,8 +8,9 @@ from homeassistant.components.webhook import ( async_unregister as webhook_unregister, ) from homeassistant.const import ATTR_DEVICE_ID, CONF_WEBHOOK_ID +from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, discovery -from homeassistant.helpers.typing import ConfigType, HomeAssistantType +from homeassistant.helpers.typing import ConfigType from .const import ( ATTR_DEVICE_NAME, @@ -32,7 +33,7 @@ from .webhook import handle_webhook PLATFORMS = "sensor", "binary_sensor", "device_tracker" -async def async_setup(hass: HomeAssistantType, config: ConfigType): +async def async_setup(hass: HomeAssistant, config: ConfigType): """Set up the mobile app component.""" store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY) app_config = await store.async_load() diff --git a/homeassistant/components/mobile_app/helpers.py b/homeassistant/components/mobile_app/helpers.py index 63d638cd9e5..7fe4bb5ecd6 100644 --- a/homeassistant/components/mobile_app/helpers.py +++ b/homeassistant/components/mobile_app/helpers.py @@ -15,9 +15,8 @@ from homeassistant.const import ( HTTP_BAD_REQUEST, HTTP_OK, ) -from homeassistant.core import Context +from homeassistant.core import Context, HomeAssistant from homeassistant.helpers.json import JSONEncoder -from homeassistant.helpers.typing import HomeAssistantType from .const import ( ATTR_APP_DATA, @@ -139,7 +138,7 @@ def safe_registration(registration: dict) -> dict: } -def savable_state(hass: HomeAssistantType) -> dict: +def savable_state(hass: HomeAssistant) -> dict: """Return a clean object containing things that should be saved.""" return { DATA_DELETED_IDS: hass.data[DOMAIN][DATA_DELETED_IDS], diff --git a/homeassistant/components/mobile_app/webhook.py b/homeassistant/components/mobile_app/webhook.py index 6be39f34f00..64f10d5616a 100644 --- a/homeassistant/components/mobile_app/webhook.py +++ b/homeassistant/components/mobile_app/webhook.py @@ -33,7 +33,7 @@ from homeassistant.const import ( HTTP_BAD_REQUEST, HTTP_CREATED, ) -from homeassistant.core import EventOrigin +from homeassistant.core import EventOrigin, HomeAssistant from homeassistant.exceptions import HomeAssistantError, ServiceNotFound from homeassistant.helpers import ( config_validation as cv, @@ -42,7 +42,6 @@ from homeassistant.helpers import ( template, ) from homeassistant.helpers.dispatcher import async_dispatcher_send -from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util.decorator import Registry from .const import ( @@ -145,7 +144,7 @@ def validate_schema(schema): async def handle_webhook( - hass: HomeAssistantType, webhook_id: str, request: Request + hass: HomeAssistant, webhook_id: str, request: Request ) -> Response: """Handle webhook callback.""" if webhook_id in hass.data[DOMAIN][DATA_DELETED_IDS]: diff --git a/homeassistant/components/mysensors/__init__.py b/homeassistant/components/mysensors/__init__.py index c9ad496762d..c5ed31326a3 100644 --- a/homeassistant/components/mysensors/__init__.py +++ b/homeassistant/components/mysensors/__init__.py @@ -19,7 +19,7 @@ from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.typing import ConfigType, HomeAssistantType +from homeassistant.helpers.typing import ConfigType from .const import ( ATTR_DEVICES, @@ -142,7 +142,7 @@ CONFIG_SCHEMA = vol.Schema( ) -async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the MySensors component.""" hass.data[DOMAIN] = {DATA_HASS_CONFIG: config} @@ -182,7 +182,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: return True -async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool: +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up an instance of the MySensors integration. Every instance has a connection to exactly one Gateway. @@ -234,7 +234,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool return True -async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Remove an instance of the MySensors integration.""" gateway = get_mysensors_gateway(hass, entry.entry_id) diff --git a/homeassistant/components/mysensors/binary_sensor.py b/homeassistant/components/mysensors/binary_sensor.py index c4e12d170c0..161f5cab8c7 100644 --- a/homeassistant/components/mysensors/binary_sensor.py +++ b/homeassistant/components/mysensors/binary_sensor.py @@ -16,9 +16,8 @@ from homeassistant.components.mysensors import on_unload from homeassistant.components.mysensors.const import MYSENSORS_DISCOVERY from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_ON -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.typing import HomeAssistantType SENSORS = { "S_DOOR": "door", @@ -33,7 +32,7 @@ SENSORS = { async def async_setup_entry( - hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities: Callable + hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable ): """Set up this platform for a specific ConfigEntry(==Gateway).""" diff --git a/homeassistant/components/mysensors/climate.py b/homeassistant/components/mysensors/climate.py index b1916fc4ed1..a3104677fa2 100644 --- a/homeassistant/components/mysensors/climate.py +++ b/homeassistant/components/mysensors/climate.py @@ -19,8 +19,8 @@ from homeassistant.components.mysensors import on_unload from homeassistant.components.mysensors.const import MYSENSORS_DISCOVERY from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.typing import HomeAssistantType DICT_HA_TO_MYS = { HVAC_MODE_AUTO: "AutoChangeOver", @@ -40,7 +40,7 @@ OPERATION_LIST = [HVAC_MODE_OFF, HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_HEAT] async def async_setup_entry( - hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities: Callable + hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable ): """Set up this platform for a specific ConfigEntry(==Gateway).""" diff --git a/homeassistant/components/mysensors/cover.py b/homeassistant/components/mysensors/cover.py index 33393f08def..bade01f42d8 100644 --- a/homeassistant/components/mysensors/cover.py +++ b/homeassistant/components/mysensors/cover.py @@ -9,8 +9,8 @@ from homeassistant.components.mysensors import on_unload from homeassistant.components.mysensors.const import MYSENSORS_DISCOVERY from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_OFF, STATE_ON +from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.typing import HomeAssistantType _LOGGER = logging.getLogger(__name__) @@ -26,7 +26,7 @@ class CoverState(Enum): async def async_setup_entry( - hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities: Callable + hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable ): """Set up this platform for a specific ConfigEntry(==Gateway).""" diff --git a/homeassistant/components/mysensors/device_tracker.py b/homeassistant/components/mysensors/device_tracker.py index 068029af960..45416ff7ae7 100644 --- a/homeassistant/components/mysensors/device_tracker.py +++ b/homeassistant/components/mysensors/device_tracker.py @@ -3,13 +3,13 @@ from homeassistant.components import mysensors from homeassistant.components.device_tracker import DOMAIN from homeassistant.components.mysensors import DevId, on_unload from homeassistant.components.mysensors.const import ATTR_GATEWAY_ID, GatewayId +from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util import slugify async def async_setup_scanner( - hass: HomeAssistantType, config, async_see, discovery_info=None + hass: HomeAssistant, config, async_see, discovery_info=None ): """Set up the MySensors device scanner.""" if not discovery_info: @@ -53,7 +53,7 @@ async def async_setup_scanner( class MySensorsDeviceScanner(mysensors.device.MySensorsDevice): """Represent a MySensors scanner.""" - def __init__(self, hass: HomeAssistantType, async_see, *args): + def __init__(self, hass: HomeAssistant, async_see, *args): """Set up instance.""" super().__init__(*args) self.async_see = async_see diff --git a/homeassistant/components/mysensors/gateway.py b/homeassistant/components/mysensors/gateway.py index 0d800e0215e..ec403e6e34b 100644 --- a/homeassistant/components/mysensors/gateway.py +++ b/homeassistant/components/mysensors/gateway.py @@ -16,9 +16,8 @@ import voluptuous as vol from homeassistant.components.mqtt import DOMAIN as MQTT_DOMAIN from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP -from homeassistant.core import Event, callback +from homeassistant.core import Event, HomeAssistant, callback import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.typing import HomeAssistantType from .const import ( CONF_BAUD_RATE, @@ -67,7 +66,7 @@ def is_socket_address(value): raise vol.Invalid("Device is not a valid domain name or ip address") from err -async def try_connect(hass: HomeAssistantType, user_input: dict[str, str]) -> bool: +async def try_connect(hass: HomeAssistant, user_input: dict[str, str]) -> bool: """Try to connect to a gateway and report if it worked.""" if user_input[CONF_DEVICE] == MQTT_COMPONENT: return True # dont validate mqtt. mqtt gateways dont send ready messages :( @@ -113,7 +112,7 @@ async def try_connect(hass: HomeAssistantType, user_input: dict[str, str]) -> bo def get_mysensors_gateway( - hass: HomeAssistantType, gateway_id: GatewayId + hass: HomeAssistant, gateway_id: GatewayId ) -> BaseAsyncGateway | None: """Return the Gateway for a given GatewayId.""" if MYSENSORS_GATEWAYS not in hass.data[DOMAIN]: @@ -123,7 +122,7 @@ def get_mysensors_gateway( async def setup_gateway( - hass: HomeAssistantType, entry: ConfigEntry + hass: HomeAssistant, entry: ConfigEntry ) -> BaseAsyncGateway | None: """Set up the Gateway for the given ConfigEntry.""" @@ -145,7 +144,7 @@ async def setup_gateway( async def _get_gateway( - hass: HomeAssistantType, + hass: HomeAssistant, device: str, version: str, event_callback: Callable[[Message], None], @@ -233,7 +232,7 @@ async def _get_gateway( async def finish_setup( - hass: HomeAssistantType, entry: ConfigEntry, gateway: BaseAsyncGateway + hass: HomeAssistant, entry: ConfigEntry, gateway: BaseAsyncGateway ): """Load any persistent devices and platforms and start gateway.""" discover_tasks = [] @@ -248,7 +247,7 @@ async def finish_setup( async def _discover_persistent_devices( - hass: HomeAssistantType, entry: ConfigEntry, gateway: BaseAsyncGateway + hass: HomeAssistant, entry: ConfigEntry, gateway: BaseAsyncGateway ): """Discover platforms for devices loaded via persistence file.""" tasks = [] @@ -278,9 +277,7 @@ async def gw_stop(hass, entry: ConfigEntry, gateway: BaseAsyncGateway): await gateway.stop() -async def _gw_start( - hass: HomeAssistantType, entry: ConfigEntry, gateway: BaseAsyncGateway -): +async def _gw_start(hass: HomeAssistant, entry: ConfigEntry, gateway: BaseAsyncGateway): """Start the gateway.""" gateway_ready = asyncio.Event() @@ -319,7 +316,7 @@ async def _gw_start( def _gw_callback_factory( - hass: HomeAssistantType, gateway_id: GatewayId + hass: HomeAssistant, gateway_id: GatewayId ) -> Callable[[Message], None]: """Return a new callback for the gateway.""" diff --git a/homeassistant/components/mysensors/handler.py b/homeassistant/components/mysensors/handler.py index d21140701f9..8558cd01f42 100644 --- a/homeassistant/components/mysensors/handler.py +++ b/homeassistant/components/mysensors/handler.py @@ -3,9 +3,8 @@ from __future__ import annotations from mysensors import Message -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_send -from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util import decorator from .const import CHILD_CALLBACK, NODE_CALLBACK, DevId, GatewayId @@ -16,9 +15,7 @@ HANDLERS = decorator.Registry() @HANDLERS.register("set") -async def handle_set( - hass: HomeAssistantType, gateway_id: GatewayId, msg: Message -) -> None: +async def handle_set(hass: HomeAssistant, gateway_id: GatewayId, msg: Message) -> None: """Handle a mysensors set message.""" validated = validate_set_msg(gateway_id, msg) _handle_child_update(hass, gateway_id, validated) @@ -26,7 +23,7 @@ async def handle_set( @HANDLERS.register("internal") async def handle_internal( - hass: HomeAssistantType, gateway_id: GatewayId, msg: Message + hass: HomeAssistant, gateway_id: GatewayId, msg: Message ) -> None: """Handle a mysensors internal message.""" internal = msg.gateway.const.Internal(msg.sub_type) @@ -38,7 +35,7 @@ async def handle_internal( @HANDLERS.register("I_BATTERY_LEVEL") async def handle_battery_level( - hass: HomeAssistantType, gateway_id: GatewayId, msg: Message + hass: HomeAssistant, gateway_id: GatewayId, msg: Message ) -> None: """Handle an internal battery level message.""" _handle_node_update(hass, gateway_id, msg) @@ -46,7 +43,7 @@ async def handle_battery_level( @HANDLERS.register("I_HEARTBEAT_RESPONSE") async def handle_heartbeat( - hass: HomeAssistantType, gateway_id: GatewayId, msg: Message + hass: HomeAssistant, gateway_id: GatewayId, msg: Message ) -> None: """Handle an heartbeat.""" _handle_node_update(hass, gateway_id, msg) @@ -54,7 +51,7 @@ async def handle_heartbeat( @HANDLERS.register("I_SKETCH_NAME") async def handle_sketch_name( - hass: HomeAssistantType, gateway_id: GatewayId, msg: Message + hass: HomeAssistant, gateway_id: GatewayId, msg: Message ) -> None: """Handle an internal sketch name message.""" _handle_node_update(hass, gateway_id, msg) @@ -62,7 +59,7 @@ async def handle_sketch_name( @HANDLERS.register("I_SKETCH_VERSION") async def handle_sketch_version( - hass: HomeAssistantType, gateway_id: GatewayId, msg: Message + hass: HomeAssistant, gateway_id: GatewayId, msg: Message ) -> None: """Handle an internal sketch version message.""" _handle_node_update(hass, gateway_id, msg) @@ -70,7 +67,7 @@ async def handle_sketch_version( @callback def _handle_child_update( - hass: HomeAssistantType, gateway_id: GatewayId, validated: dict[str, list[DevId]] + hass: HomeAssistant, gateway_id: GatewayId, validated: dict[str, list[DevId]] ): """Handle a child update.""" signals: list[str] = [] @@ -94,7 +91,7 @@ def _handle_child_update( @callback -def _handle_node_update(hass: HomeAssistantType, gateway_id: GatewayId, msg: Message): +def _handle_node_update(hass: HomeAssistant, gateway_id: GatewayId, msg: Message): """Handle a node update.""" signal = NODE_CALLBACK.format(gateway_id, msg.node_id) async_dispatcher_send(hass, signal) diff --git a/homeassistant/components/mysensors/helpers.py b/homeassistant/components/mysensors/helpers.py index 71ea97bc371..9a35f67d49b 100644 --- a/homeassistant/components/mysensors/helpers.py +++ b/homeassistant/components/mysensors/helpers.py @@ -15,7 +15,6 @@ from homeassistant.const import CONF_NAME from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send -from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util.decorator import Registry from .const import ( @@ -37,7 +36,7 @@ SCHEMAS = Registry() async def on_unload( - hass: HomeAssistantType, entry: ConfigEntry | GatewayId, fnct: Callable + hass: HomeAssistant, entry: ConfigEntry | GatewayId, fnct: Callable ) -> None: """Register a callback to be called when entry is unloaded. diff --git a/homeassistant/components/mysensors/light.py b/homeassistant/components/mysensors/light.py index f90f9c5c81c..3262487d18e 100644 --- a/homeassistant/components/mysensors/light.py +++ b/homeassistant/components/mysensors/light.py @@ -16,9 +16,8 @@ from homeassistant.components.mysensors import on_unload from homeassistant.components.mysensors.const import MYSENSORS_DISCOVERY from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_OFF, STATE_ON -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.typing import HomeAssistantType import homeassistant.util.color as color_util from homeassistant.util.color import rgb_hex_to_rgb_list @@ -26,7 +25,7 @@ SUPPORT_MYSENSORS_RGBW = SUPPORT_COLOR | SUPPORT_WHITE_VALUE async def async_setup_entry( - hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities: Callable + hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable ): """Set up this platform for a specific ConfigEntry(==Gateway).""" device_class_map = { diff --git a/homeassistant/components/mysensors/sensor.py b/homeassistant/components/mysensors/sensor.py index 1a5f7330ddf..a63f143f1d7 100644 --- a/homeassistant/components/mysensors/sensor.py +++ b/homeassistant/components/mysensors/sensor.py @@ -25,8 +25,8 @@ from homeassistant.const import ( VOLT, VOLUME_CUBIC_METERS, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.typing import HomeAssistantType SENSORS = { "V_TEMP": [None, "mdi:thermometer"], @@ -64,7 +64,7 @@ SENSORS = { async def async_setup_entry( - hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities: Callable + hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable ): """Set up this platform for a specific ConfigEntry(==Gateway).""" diff --git a/homeassistant/components/mysensors/switch.py b/homeassistant/components/mysensors/switch.py index 14911e11090..a410cc64df4 100644 --- a/homeassistant/components/mysensors/switch.py +++ b/homeassistant/components/mysensors/switch.py @@ -6,12 +6,12 @@ import voluptuous as vol from homeassistant.components import mysensors from homeassistant.components.switch import DOMAIN, SwitchEntity from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON +from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from . import on_unload from ...config_entries import ConfigEntry from ...helpers.dispatcher import async_dispatcher_connect -from ...helpers.typing import HomeAssistantType from .const import DOMAIN as MYSENSORS_DOMAIN, MYSENSORS_DISCOVERY, SERVICE_SEND_IR_CODE ATTR_IR_CODE = "V_IR_SEND" @@ -22,7 +22,7 @@ SEND_IR_CODE_SERVICE_SCHEMA = vol.Schema( async def async_setup_entry( - hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities: Callable + hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable ): """Set up this platform for a specific ConfigEntry(==Gateway).""" device_class_map = { diff --git a/homeassistant/components/neato/__init__.py b/homeassistant/components/neato/__init__.py index 9413ff77236..036d91534f4 100644 --- a/homeassistant/components/neato/__init__.py +++ b/homeassistant/components/neato/__init__.py @@ -9,9 +9,10 @@ import voluptuous as vol from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_TOKEN +from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv -from homeassistant.helpers.typing import ConfigType, HomeAssistantType +from homeassistant.helpers.typing import ConfigType from homeassistant.util import Throttle from . import api, config_flow @@ -42,7 +43,7 @@ CONFIG_SCHEMA = vol.Schema( PLATFORMS = ["camera", "vacuum", "switch", "sensor"] -async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Neato component.""" hass.data[NEATO_DOMAIN] = {} @@ -66,7 +67,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: return True -async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool: +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up config entry.""" if CONF_TOKEN not in entry.data: raise ConfigEntryAuthFailed @@ -99,7 +100,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool return True -async def async_unload_entry(hass: HomeAssistantType, entry: ConfigType) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: ConfigType) -> bool: """Unload config entry.""" unload_functions = ( hass.config_entries.async_forward_entry_unload(entry, platform) @@ -116,9 +117,9 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigType) -> bool class NeatoHub: """A My Neato hub wrapper class.""" - def __init__(self, hass: HomeAssistantType, neato: Account): + def __init__(self, hass: HomeAssistant, neato: Account): """Initialize the Neato hub.""" - self._hass: HomeAssistantType = hass + self._hass = hass self.my_neato: Account = neato @Throttle(timedelta(minutes=1)) diff --git a/tests/components/minecraft_server/test_config_flow.py b/tests/components/minecraft_server/test_config_flow.py index 9fcea3261ee..9717fa0052b 100644 --- a/tests/components/minecraft_server/test_config_flow.py +++ b/tests/components/minecraft_server/test_config_flow.py @@ -13,12 +13,12 @@ from homeassistant.components.minecraft_server.const import ( ) from homeassistant.config_entries import SOURCE_USER from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT +from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import ( RESULT_TYPE_ABORT, RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM, ) -from homeassistant.helpers.typing import HomeAssistantType from tests.common import MockConfigEntry @@ -80,7 +80,7 @@ SRV_RECORDS = asyncio.Future() SRV_RECORDS.set_result([QueryMock()]) -async def test_show_config_form(hass: HomeAssistantType) -> None: +async def test_show_config_form(hass: HomeAssistant) -> None: """Test if initial configuration form is shown.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER} @@ -90,7 +90,7 @@ async def test_show_config_form(hass: HomeAssistantType) -> None: assert result["step_id"] == "user" -async def test_invalid_ip(hass: HomeAssistantType) -> None: +async def test_invalid_ip(hass: HomeAssistant) -> None: """Test error in case of an invalid IP address.""" with patch("getmac.get_mac_address", return_value=None): result = await hass.config_entries.flow.async_init( @@ -101,7 +101,7 @@ async def test_invalid_ip(hass: HomeAssistantType) -> None: assert result["errors"] == {"base": "invalid_ip"} -async def test_same_host(hass: HomeAssistantType) -> None: +async def test_same_host(hass: HomeAssistant) -> None: """Test abort in case of same host name.""" with patch("aiodns.DNSResolver.query", side_effect=aiodns.error.DNSError,), patch( "mcstatus.server.MinecraftServer.status", @@ -126,7 +126,7 @@ async def test_same_host(hass: HomeAssistantType) -> None: assert result["reason"] == "already_configured" -async def test_port_too_small(hass: HomeAssistantType) -> None: +async def test_port_too_small(hass: HomeAssistant) -> None: """Test error in case of a too small port.""" with patch( "aiodns.DNSResolver.query", @@ -140,7 +140,7 @@ async def test_port_too_small(hass: HomeAssistantType) -> None: assert result["errors"] == {"base": "invalid_port"} -async def test_port_too_large(hass: HomeAssistantType) -> None: +async def test_port_too_large(hass: HomeAssistant) -> None: """Test error in case of a too large port.""" with patch( "aiodns.DNSResolver.query", @@ -154,7 +154,7 @@ async def test_port_too_large(hass: HomeAssistantType) -> None: assert result["errors"] == {"base": "invalid_port"} -async def test_connection_failed(hass: HomeAssistantType) -> None: +async def test_connection_failed(hass: HomeAssistant) -> None: """Test error in case of a failed connection.""" with patch( "aiodns.DNSResolver.query", @@ -168,7 +168,7 @@ async def test_connection_failed(hass: HomeAssistantType) -> None: assert result["errors"] == {"base": "cannot_connect"} -async def test_connection_succeeded_with_srv_record(hass: HomeAssistantType) -> None: +async def test_connection_succeeded_with_srv_record(hass: HomeAssistant) -> None: """Test config entry in case of a successful connection with a SRV record.""" with patch("aiodns.DNSResolver.query", return_value=SRV_RECORDS,), patch( "mcstatus.server.MinecraftServer.status", @@ -184,7 +184,7 @@ async def test_connection_succeeded_with_srv_record(hass: HomeAssistantType) -> assert result["data"][CONF_HOST] == USER_INPUT_SRV[CONF_HOST] -async def test_connection_succeeded_with_host(hass: HomeAssistantType) -> None: +async def test_connection_succeeded_with_host(hass: HomeAssistant) -> None: """Test config entry in case of a successful connection with a host name.""" with patch("aiodns.DNSResolver.query", side_effect=aiodns.error.DNSError,), patch( "mcstatus.server.MinecraftServer.status", @@ -200,7 +200,7 @@ async def test_connection_succeeded_with_host(hass: HomeAssistantType) -> None: assert result["data"][CONF_HOST] == "mc.dummyserver.com" -async def test_connection_succeeded_with_ip4(hass: HomeAssistantType) -> None: +async def test_connection_succeeded_with_ip4(hass: HomeAssistant) -> None: """Test config entry in case of a successful connection with an IPv4 address.""" with patch("getmac.get_mac_address", return_value="01:23:45:67:89:ab"), patch( "aiodns.DNSResolver.query", @@ -219,7 +219,7 @@ async def test_connection_succeeded_with_ip4(hass: HomeAssistantType) -> None: assert result["data"][CONF_HOST] == "1.1.1.1" -async def test_connection_succeeded_with_ip6(hass: HomeAssistantType) -> None: +async def test_connection_succeeded_with_ip6(hass: HomeAssistant) -> None: """Test config entry in case of a successful connection with an IPv6 address.""" with patch("getmac.get_mac_address", return_value="01:23:45:67:89:ab"), patch( "aiodns.DNSResolver.query", diff --git a/tests/components/mysensors/test_config_flow.py b/tests/components/mysensors/test_config_flow.py index a91159e4395..dfad2b50558 100644 --- a/tests/components/mysensors/test_config_flow.py +++ b/tests/components/mysensors/test_config_flow.py @@ -23,13 +23,13 @@ from homeassistant.components.mysensors.const import ( DOMAIN, ConfGatewayType, ) -from homeassistant.helpers.typing import HomeAssistantType +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry async def get_form( - hass: HomeAssistantType, gatway_type: ConfGatewayType, expected_step_id: str + hass: HomeAssistant, gatway_type: ConfGatewayType, expected_step_id: str ): """Get a form for the given gateway type.""" await setup.async_setup_component(hass, "persistent_notification", {}) @@ -50,7 +50,7 @@ async def get_form( return result -async def test_config_mqtt(hass: HomeAssistantType, mqtt: None) -> None: +async def test_config_mqtt(hass: HomeAssistant, mqtt: None) -> None: """Test configuring a mqtt gateway.""" step = await get_form(hass, CONF_GATEWAY_TYPE_MQTT, "gw_mqtt") flow_id = step["flow_id"] @@ -88,7 +88,7 @@ async def test_config_mqtt(hass: HomeAssistantType, mqtt: None) -> None: assert len(mock_setup_entry.mock_calls) == 1 -async def test_missing_mqtt(hass: HomeAssistantType) -> None: +async def test_missing_mqtt(hass: HomeAssistant) -> None: """Test configuring a mqtt gateway without mqtt integration setup.""" await setup.async_setup_component(hass, "persistent_notification", {}) result = await hass.config_entries.flow.async_init( @@ -106,7 +106,7 @@ async def test_missing_mqtt(hass: HomeAssistantType) -> None: assert result["errors"] == {"base": "mqtt_required"} -async def test_config_serial(hass: HomeAssistantType): +async def test_config_serial(hass: HomeAssistant): """Test configuring a gateway via serial.""" step = await get_form(hass, CONF_GATEWAY_TYPE_SERIAL, "gw_serial") flow_id = step["flow_id"] @@ -146,7 +146,7 @@ async def test_config_serial(hass: HomeAssistantType): assert len(mock_setup_entry.mock_calls) == 1 -async def test_config_tcp(hass: HomeAssistantType): +async def test_config_tcp(hass: HomeAssistant): """Test configuring a gateway via tcp.""" step = await get_form(hass, CONF_GATEWAY_TYPE_TCP, "gw_tcp") flow_id = step["flow_id"] @@ -183,7 +183,7 @@ async def test_config_tcp(hass: HomeAssistantType): assert len(mock_setup_entry.mock_calls) == 1 -async def test_fail_to_connect(hass: HomeAssistantType): +async def test_fail_to_connect(hass: HomeAssistant): """Test configuring a gateway via tcp.""" step = await get_form(hass, CONF_GATEWAY_TYPE_TCP, "gw_tcp") flow_id = step["flow_id"] @@ -365,7 +365,7 @@ async def test_fail_to_connect(hass: HomeAssistantType): ], ) async def test_config_invalid( - hass: HomeAssistantType, + hass: HomeAssistant, mqtt: config_entries.ConfigEntry, gateway_type: ConfGatewayType, expected_step_id: str, @@ -440,7 +440,7 @@ async def test_config_invalid( }, ], ) -async def test_import(hass: HomeAssistantType, mqtt: None, user_input: dict) -> None: +async def test_import(hass: HomeAssistant, mqtt: None, user_input: dict) -> None: """Test importing a gateway.""" await setup.async_setup_component(hass, "persistent_notification", {}) @@ -731,7 +731,7 @@ async def test_import(hass: HomeAssistantType, mqtt: None, user_input: dict) -> ], ) async def test_duplicate( - hass: HomeAssistantType, + hass: HomeAssistant, mqtt: None, first_input: dict, second_input: dict, diff --git a/tests/components/mysensors/test_gateway.py b/tests/components/mysensors/test_gateway.py index d3e360e0b9f..f2e7aa77c8c 100644 --- a/tests/components/mysensors/test_gateway.py +++ b/tests/components/mysensors/test_gateway.py @@ -5,7 +5,7 @@ import pytest import voluptuous as vol from homeassistant.components.mysensors.gateway import is_serial_port -from homeassistant.helpers.typing import HomeAssistantType +from homeassistant.core import HomeAssistant @pytest.mark.parametrize( @@ -18,7 +18,7 @@ from homeassistant.helpers.typing import HomeAssistantType ("/dev/ttyACM0", False), ], ) -def test_is_serial_port_windows(hass: HomeAssistantType, port: str, expect_valid: bool): +def test_is_serial_port_windows(hass: HomeAssistant, port: str, expect_valid: bool): """Test windows serial port.""" with patch("sys.platform", "win32"): diff --git a/tests/components/mysensors/test_init.py b/tests/components/mysensors/test_init.py index 780621112ab..30fbf3ea686 100644 --- a/tests/components/mysensors/test_init.py +++ b/tests/components/mysensors/test_init.py @@ -25,7 +25,8 @@ from homeassistant.components.mysensors.const import ( CONF_TOPIC_IN_PREFIX, CONF_TOPIC_OUT_PREFIX, ) -from homeassistant.helpers.typing import ConfigType, HomeAssistantType +from homeassistant.core import HomeAssistant +from homeassistant.helpers.typing import ConfigType from homeassistant.setup import async_setup_component @@ -226,7 +227,7 @@ from homeassistant.setup import async_setup_component ], ) async def test_import( - hass: HomeAssistantType, + hass: HomeAssistant, mqtt: None, config: ConfigType, expected_calls: int, diff --git a/tests/components/neato/test_config_flow.py b/tests/components/neato/test_config_flow.py index 7c7e25f2e0c..3650dae8a5c 100644 --- a/tests/components/neato/test_config_flow.py +++ b/tests/components/neato/test_config_flow.py @@ -5,8 +5,8 @@ from pybotvac.neato import Neato from homeassistant import config_entries, data_entry_flow, setup from homeassistant.components.neato.const import NEATO_DOMAIN +from homeassistant.core import HomeAssistant from homeassistant.helpers import config_entry_oauth2_flow -from homeassistant.helpers.typing import HomeAssistantType from tests.common import MockConfigEntry @@ -74,7 +74,7 @@ async def test_full_flow( assert len(mock_setup.mock_calls) == 1 -async def test_abort_if_already_setup(hass: HomeAssistantType): +async def test_abort_if_already_setup(hass: HomeAssistant): """Test we abort if Neato is already setup.""" entry = MockConfigEntry( domain=NEATO_DOMAIN, @@ -91,7 +91,7 @@ async def test_abort_if_already_setup(hass: HomeAssistantType): async def test_reauth( - hass: HomeAssistantType, aiohttp_client, aioclient_mock, current_request_with_host + hass: HomeAssistant, aiohttp_client, aioclient_mock, current_request_with_host ): """Test initialization of the reauth flow.""" assert await setup.async_setup_component(