From 19d25cd90165125d1e75884db5703dfebb73fb1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 20 May 2021 20:19:20 +0300 Subject: [PATCH] Change config entry state to an enum (#49654) * Change config entry state to an enum * Allow but deprecate EntryState str equality comparison * Test fixes * Rename to ConfigEntryState * Remove str comparability backcompat * Update new occurrences of strs cropped up during review --- .../components/config/config_entries.py | 2 +- homeassistant/components/dsmr/config_flow.py | 4 +- homeassistant/components/ozw/__init__.py | 6 +- homeassistant/components/ozw/config_flow.py | 2 +- homeassistant/components/plex/__init__.py | 4 +- .../components/somfy_mylink/config_flow.py | 2 +- homeassistant/components/tuya/config_flow.py | 2 +- homeassistant/components/vizio/__init__.py | 4 +- homeassistant/components/zwave_js/api.py | 4 +- homeassistant/config_entries.py | 92 ++++++----- tests/components/abode/test_init.py | 6 +- tests/components/accuweather/test_init.py | 16 +- tests/components/advantage_air/test_init.py | 12 +- tests/components/aemet/test_config_flow.py | 10 +- tests/components/aemet/test_init.py | 6 +- tests/components/airly/test_init.py | 20 +-- tests/components/almond/test_init.py | 8 +- tests/components/atag/test_init.py | 4 +- tests/components/august/test_init.py | 36 ++-- tests/components/blebox/test_config_flow.py | 4 +- tests/components/blebox/test_init.py | 8 +- tests/components/bond/test_init.py | 18 +- tests/components/broadlink/test_device.py | 35 ++-- tests/components/brother/test_init.py | 12 +- tests/components/bsblan/test_init.py | 6 +- tests/components/buienradar/test_init.py | 9 +- tests/components/canary/test_init.py | 12 +- tests/components/cert_expiry/test_init.py | 8 +- tests/components/cert_expiry/test_sensors.py | 4 +- tests/components/cloudflare/test_init.py | 14 +- .../components/config/test_config_entries.py | 30 ++-- tests/components/coronavirus/test_init.py | 4 +- .../devolo_home_control/test_init.py | 17 +- tests/components/dexcom/test_init.py | 6 +- tests/components/directv/test_init.py | 12 +- tests/components/dsmr/test_sensor.py | 5 +- tests/components/dynalite/test_config_flow.py | 8 +- tests/components/eafm/test_sensor.py | 2 +- tests/components/elgato/test_init.py | 4 +- tests/components/freebox/test_init.py | 8 +- tests/components/fritzbox/test_init.py | 16 +- tests/components/gios/test_init.py | 12 +- tests/components/gree/test_init.py | 6 +- .../components/home_plus_control/test_init.py | 8 +- .../home_plus_control/test_switch.py | 4 +- .../specific_devices/test_ecobee3.py | 4 +- .../components/homematicip_cloud/test_hap.py | 4 +- .../components/homematicip_cloud/test_init.py | 15 +- tests/components/huisbaasje/test_init.py | 18 +- tests/components/hyperion/test_light.py | 6 +- tests/components/ialarm/test_init.py | 14 +- tests/components/insteon/test_config_flow.py | 4 +- tests/components/ipp/test_init.py | 12 +- .../islamic_prayer_times/test_init.py | 6 +- tests/components/kmtronic/test_config_flow.py | 6 +- tests/components/kmtronic/test_init.py | 12 +- tests/components/kodi/test_init.py | 6 +- tests/components/litterrobot/test_init.py | 11 +- tests/components/lyric/test_config_flow.py | 2 +- tests/components/mazda/test_init.py | 19 +-- tests/components/met/test_init.py | 12 +- tests/components/met_eireann/test_init.py | 6 +- tests/components/mikrotik/test_hub.py | 2 +- tests/components/nam/test_init.py | 12 +- tests/components/neato/test_config_flow.py | 2 +- tests/components/nest/test_init_sdm.py | 19 +-- tests/components/netatmo/test_init.py | 2 +- tests/components/nightscout/test_init.py | 12 +- tests/components/nzbget/test_init.py | 12 +- tests/components/onewire/test_init.py | 17 +- .../openweathermap/test_config_flow.py | 12 +- tests/components/ozw/common.py | 4 +- tests/components/ozw/conftest.py | 4 +- tests/components/ozw/test_init.py | 26 +-- tests/components/panasonic_viera/test_init.py | 4 +- tests/components/plex/test_config_flow.py | 14 +- tests/components/plex/test_init.py | 37 ++--- .../components/plugwise/test_binary_sensor.py | 8 +- tests/components/plugwise/test_climate.py | 12 +- tests/components/plugwise/test_init.py | 20 +-- tests/components/plugwise/test_sensor.py | 12 +- tests/components/plugwise/test_switch.py | 12 +- tests/components/rfxtrx/test_switch.py | 3 +- tests/components/roku/test_init.py | 12 +- .../components/ruckus_unleashed/test_init.py | 14 +- .../components/smart_meter_texas/test_init.py | 15 +- tests/components/smarttub/test_init.py | 10 +- tests/components/somfy/test_config_flow.py | 4 +- tests/components/sonarr/test_init.py | 16 +- tests/components/speedtestdotnet/test_init.py | 6 +- tests/components/srp_energy/test_init.py | 3 +- tests/components/subaru/conftest.py | 4 +- tests/components/subaru/test_init.py | 21 +-- tests/components/totalconnect/test_init.py | 4 +- tests/components/vera/test_init.py | 4 +- tests/components/volumio/test_config_flow.py | 2 +- tests/components/wilight/test_init.py | 12 +- tests/components/wled/test_init.py | 4 +- tests/components/yeelight/test_init.py | 4 +- tests/components/zwave_js/test_init.py | 41 ++--- tests/test_config_entries.py | 154 +++++++++--------- 101 files changed, 557 insertions(+), 688 deletions(-) diff --git a/homeassistant/components/config/config_entries.py b/homeassistant/components/config/config_entries.py index 11c39089f35..efc60288439 100644 --- a/homeassistant/components/config/config_entries.py +++ b/homeassistant/components/config/config_entries.py @@ -385,7 +385,7 @@ def entry_json(entry: config_entries.ConfigEntry) -> dict: "domain": entry.domain, "title": entry.title, "source": entry.source, - "state": entry.state, + "state": entry.state.value, "supports_options": supports_options, "supports_unload": entry.supports_unload, "disabled_by": entry.disabled_by, diff --git a/homeassistant/components/dsmr/config_flow.py b/homeassistant/components/dsmr/config_flow.py index bdaaea22f64..b349afb28c7 100644 --- a/homeassistant/components/dsmr/config_flow.py +++ b/homeassistant/components/dsmr/config_flow.py @@ -149,8 +149,8 @@ class DSMRFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): and reload_on_update and entry.state in ( - config_entries.ENTRY_STATE_LOADED, - config_entries.ENTRY_STATE_SETUP_RETRY, + config_entries.ConfigEntryState.LOADED, + config_entries.ConfigEntryState.SETUP_RETRY, ) ): self.hass.async_create_task( diff --git a/homeassistant/components/ozw/__init__.py b/homeassistant/components/ozw/__init__.py index 17ab4ca7eb8..7890129dd91 100644 --- a/homeassistant/components/ozw/__init__.py +++ b/homeassistant/components/ozw/__init__.py @@ -22,7 +22,7 @@ from openzwavemqtt.util.mqtt_client import MQTTClient from homeassistant.components import mqtt from homeassistant.components.hassio.handler import HassioAPIError -from homeassistant.config_entries import ENTRY_STATE_LOADED, ConfigEntry +from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady @@ -92,7 +92,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): # noqa: C else: mqtt_entries = hass.config_entries.async_entries("mqtt") - if not mqtt_entries or mqtt_entries[0].state != ENTRY_STATE_LOADED: + if not mqtt_entries or mqtt_entries[0].state is not ConfigEntryState.LOADED: _LOGGER.error("MQTT integration is not set up") return False @@ -100,7 +100,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): # noqa: C @callback def send_message(topic, payload): - if mqtt_entry.state != ENTRY_STATE_LOADED: + if mqtt_entry.state is not ConfigEntryState.LOADED: _LOGGER.error("MQTT integration is not set up") return diff --git a/homeassistant/components/ozw/config_flow.py b/homeassistant/components/ozw/config_flow.py index 4ff8a512c75..cc07d738488 100644 --- a/homeassistant/components/ozw/config_flow.py +++ b/homeassistant/components/ozw/config_flow.py @@ -98,7 +98,7 @@ class DomainConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): mqtt_entries = self.hass.config_entries.async_entries("mqtt") if ( not mqtt_entries - or mqtt_entries[0].state != config_entries.ENTRY_STATE_LOADED + or mqtt_entries[0].state is not config_entries.ConfigEntryState.LOADED ): return self.async_abort(reason="mqtt_required") return self._async_create_entry_from_vars() diff --git a/homeassistant/components/plex/__init__.py b/homeassistant/components/plex/__init__.py index c534384a7eb..ffdf9aa5554 100644 --- a/homeassistant/components/plex/__init__.py +++ b/homeassistant/components/plex/__init__.py @@ -14,7 +14,7 @@ from plexwebsocket import ( import requests.exceptions from homeassistant.components.media_player import DOMAIN as MP_DOMAIN -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_URL, CONF_VERIFY_SSL, EVENT_HOMEASSISTANT_STOP from homeassistant.core import callback from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady @@ -107,7 +107,7 @@ async def async_setup_entry(hass, entry): entry, data={**entry.data, PLEX_SERVER_CONFIG: new_server_data} ) except requests.exceptions.ConnectionError as error: - if entry.state != ENTRY_STATE_SETUP_RETRY: + if entry.state is not ConfigEntryState.SETUP_RETRY: _LOGGER.error( "Plex server (%s) could not be reached: [%s]", server_config[CONF_URL], diff --git a/homeassistant/components/somfy_mylink/config_flow.py b/homeassistant/components/somfy_mylink/config_flow.py index aac04a34a9a..ecbd9abd402 100644 --- a/homeassistant/components/somfy_mylink/config_flow.py +++ b/homeassistant/components/somfy_mylink/config_flow.py @@ -144,7 +144,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow): async def async_step_init(self, user_input=None): """Handle options flow.""" - if self.config_entry.state != config_entries.ENTRY_STATE_LOADED: + if self.config_entry.state is not config_entries.ConfigEntryState.LOADED: _LOGGER.error("MyLink must be connected to manage device options") return self.async_abort(reason="cannot_connect") diff --git a/homeassistant/components/tuya/config_flow.py b/homeassistant/components/tuya/config_flow.py index ee17715b5e9..970a1c54f1e 100644 --- a/homeassistant/components/tuya/config_flow.py +++ b/homeassistant/components/tuya/config_flow.py @@ -245,7 +245,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow): async def async_step_init(self, user_input=None): """Handle options flow.""" - if self.config_entry.state != config_entries.ENTRY_STATE_LOADED: + if self.config_entry.state is not config_entries.ConfigEntryState.LOADED: _LOGGER.error("Tuya integration not yet loaded") return self.async_abort(reason=RESULT_CONN_ERROR) diff --git a/homeassistant/components/vizio/__init__.py b/homeassistant/components/vizio/__init__.py index d51b6a4fbca..fb3a399327d 100644 --- a/homeassistant/components/vizio/__init__.py +++ b/homeassistant/components/vizio/__init__.py @@ -10,7 +10,7 @@ from pyvizio.util import gen_apps_list_from_url import voluptuous as vol from homeassistant.components.media_player import DEVICE_CLASS_TV -from homeassistant.config_entries import ENTRY_STATE_LOADED, SOURCE_IMPORT, ConfigEntry +from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry, ConfigEntryState from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -80,7 +80,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> ) # Exclude this config entry because its not unloaded yet if not any( - entry.state == ENTRY_STATE_LOADED + entry.state is ConfigEntryState.LOADED and entry.entry_id != config_entry.entry_id and entry.data[CONF_DEVICE_CLASS] == DEVICE_CLASS_TV for entry in hass.config_entries.async_entries(DOMAIN) diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index e722cac9e09..1c2b345faec 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -25,7 +25,7 @@ from homeassistant.components.websocket_api.const import ( ERR_NOT_SUPPORTED, ERR_UNKNOWN_ERROR, ) -from homeassistant.config_entries import ENTRY_STATE_LOADED, ConfigEntry +from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.const import CONF_URL from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import config_validation as cv @@ -85,7 +85,7 @@ def async_get_entry(orig_func: Callable) -> Callable: ) return - if entry.state != ENTRY_STATE_LOADED: + if entry.state is not ConfigEntryState.LOADED: connection.send_error( msg[ID], ERR_NOT_LOADED, f"Config entry {entry_id} not loaded" ) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 729d8ae94fa..7719d8edcc9 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -4,6 +4,7 @@ from __future__ import annotations import asyncio from collections.abc import Iterable, Mapping from contextvars import ContextVar +from enum import Enum import functools import logging from types import MappingProxyType, MethodType @@ -63,20 +64,37 @@ PATH_CONFIG = ".config_entries.json" SAVE_DELAY = 1 -# The config entry has been set up successfully -ENTRY_STATE_LOADED = "loaded" -# There was an error while trying to set up this config entry -ENTRY_STATE_SETUP_ERROR = "setup_error" -# There was an error while trying to migrate the config entry to a new version -ENTRY_STATE_MIGRATION_ERROR = "migration_error" -# The config entry was not ready to be set up yet, but might be later -ENTRY_STATE_SETUP_RETRY = "setup_retry" -# The config entry has not been loaded -ENTRY_STATE_NOT_LOADED = "not_loaded" -# An error occurred when trying to unload the entry -ENTRY_STATE_FAILED_UNLOAD = "failed_unload" -UNRECOVERABLE_STATES = (ENTRY_STATE_MIGRATION_ERROR, ENTRY_STATE_FAILED_UNLOAD) +class ConfigEntryState(Enum): + """Config entry state.""" + + LOADED = "loaded", True + """The config entry has been set up successfully""" + SETUP_ERROR = "setup_error", True + """There was an error while trying to set up this config entry""" + MIGRATION_ERROR = "migration_error", False + """There was an error while trying to migrate the config entry to a new version""" + SETUP_RETRY = "setup_retry", True + """The config entry was not ready to be set up yet, but might be later""" + NOT_LOADED = "not_loaded", True + """The config entry has not been loaded""" + FAILED_UNLOAD = "failed_unload", False + """An error occurred when trying to unload the entry""" + + _recoverable: bool + + def __new__(cls: type[object], value: str, recoverable: bool) -> ConfigEntryState: + """Create new ConfigEntryState.""" + obj = object.__new__(cls) + obj._value_ = value + obj._recoverable = recoverable + return cast("ConfigEntryState", obj) + + @property + def recoverable(self) -> bool: + """Get if the state is recoverable.""" + return self._recoverable + DEFAULT_DISCOVERY_UNIQUE_ID = "default_discovery_unique_id" DISCOVERY_NOTIFICATION_ID = "config_entry_discovery" @@ -156,7 +174,7 @@ class ConfigEntry: options: Mapping[str, Any] | None = None, unique_id: str | None = None, entry_id: str | None = None, - state: str = ENTRY_STATE_NOT_LOADED, + state: ConfigEntryState = ConfigEntryState.NOT_LOADED, disabled_by: str | None = None, ) -> None: """Initialize a config entry.""" @@ -237,7 +255,7 @@ class ConfigEntry: err, ) if self.domain == integration.domain: - self.state = ENTRY_STATE_SETUP_ERROR + self.state = ConfigEntryState.SETUP_ERROR self.reason = "Import error" return @@ -251,13 +269,13 @@ class ConfigEntry: self.domain, err, ) - self.state = ENTRY_STATE_SETUP_ERROR + self.state = ConfigEntryState.SETUP_ERROR self.reason = "Import error" return # Perform migration if not await self.async_migrate(hass): - self.state = ENTRY_STATE_MIGRATION_ERROR + self.state = ConfigEntryState.MIGRATION_ERROR self.reason = None return @@ -288,7 +306,7 @@ class ConfigEntry: self.async_start_reauth(hass) result = False except ConfigEntryNotReady as ex: - self.state = ENTRY_STATE_SETUP_RETRY + self.state = ConfigEntryState.SETUP_RETRY self.reason = str(ex) or None wait_time = 2 ** min(tries, 4) * 5 tries += 1 @@ -337,10 +355,10 @@ class ConfigEntry: return if result: - self.state = ENTRY_STATE_LOADED + self.state = ConfigEntryState.LOADED self.reason = None else: - self.state = ENTRY_STATE_SETUP_ERROR + self.state = ConfigEntryState.SETUP_ERROR self.reason = error_reason async def async_shutdown(self) -> None: @@ -362,7 +380,7 @@ class ConfigEntry: Returns if unload is possible and was successful. """ if self.source == SOURCE_IGNORE: - self.state = ENTRY_STATE_NOT_LOADED + self.state = ConfigEntryState.NOT_LOADED self.reason = None return True @@ -374,20 +392,20 @@ class ConfigEntry: # that was uninstalled, or an integration # that has been renamed without removing the config # entry. - self.state = ENTRY_STATE_NOT_LOADED + self.state = ConfigEntryState.NOT_LOADED self.reason = None return True component = integration.get_component() if integration.domain == self.domain: - if self.state in UNRECOVERABLE_STATES: + if not self.state.recoverable: return False - if self.state != ENTRY_STATE_LOADED: + if self.state is not ConfigEntryState.LOADED: self.async_cancel_retry_setup() - self.state = ENTRY_STATE_NOT_LOADED + self.state = ConfigEntryState.NOT_LOADED self.reason = None return True @@ -395,7 +413,7 @@ class ConfigEntry: if not supports_unload: if integration.domain == self.domain: - self.state = ENTRY_STATE_FAILED_UNLOAD + self.state = ConfigEntryState.FAILED_UNLOAD self.reason = "Unload not supported" return False @@ -406,7 +424,7 @@ class ConfigEntry: # Only adjust state if we unloaded the component if result and integration.domain == self.domain: - self.state = ENTRY_STATE_NOT_LOADED + self.state = ConfigEntryState.NOT_LOADED self.reason = None self._async_process_on_unload() @@ -417,7 +435,7 @@ class ConfigEntry: "Error unloading entry %s for %s", self.title, integration.domain ) if integration.domain == self.domain: - self.state = ENTRY_STATE_FAILED_UNLOAD + self.state = ConfigEntryState.FAILED_UNLOAD self.reason = "Unknown error" return False @@ -620,10 +638,7 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager): # Unload the entry before setting up the new one. # We will remove it only after the other one is set up, # so that device customizations are not getting lost. - if ( - existing_entry is not None - and existing_entry.state not in UNRECOVERABLE_STATES - ): + if existing_entry is not None and existing_entry.state.recoverable: await self.config_entries.async_unload(existing_entry.entry_id) entry = ConfigEntry( @@ -770,8 +785,8 @@ class ConfigEntries: if entry is None: raise UnknownEntry - if entry.state in UNRECOVERABLE_STATES: - unload_success = entry.state != ENTRY_STATE_FAILED_UNLOAD + if not entry.state.recoverable: + unload_success = entry.state is not ConfigEntryState.FAILED_UNLOAD else: unload_success = await self.async_unload(entry_id) @@ -855,7 +870,7 @@ class ConfigEntries: if entry is None: raise UnknownEntry - if entry.state != ENTRY_STATE_NOT_LOADED: + if entry.state is not ConfigEntryState.NOT_LOADED: raise OperationNotAllowed # Setup Component if not set up yet @@ -870,7 +885,7 @@ class ConfigEntries: if not result: return result - return entry.state == ENTRY_STATE_LOADED + return entry.state is ConfigEntryState.LOADED # type: ignore[comparison-overlap] # mypy bug? async def async_unload(self, entry_id: str) -> bool: """Unload a config entry.""" @@ -879,7 +894,7 @@ class ConfigEntries: if entry is None: raise UnknownEntry - if entry.state in UNRECOVERABLE_STATES: + if not entry.state.recoverable: raise OperationNotAllowed return await entry.async_unload(self.hass) @@ -1115,7 +1130,8 @@ class ConfigFlow(data_entry_flow.FlowHandler): if ( changed and reload_on_update - and entry.state in (ENTRY_STATE_LOADED, ENTRY_STATE_SETUP_RETRY) + and entry.state + in (ConfigEntryState.LOADED, ConfigEntryState.SETUP_RETRY) ): self.hass.async_create_task( self.hass.config_entries.async_reload(entry.entry_id) diff --git a/tests/components/abode/test_init.py b/tests/components/abode/test_init.py index 41219f5ccef..5e58695ace6 100644 --- a/tests/components/abode/test_init.py +++ b/tests/components/abode/test_init.py @@ -11,7 +11,7 @@ from homeassistant.components.abode import ( SERVICE_TRIGGER_AUTOMATION, ) from homeassistant.components.alarm_control_panel import DOMAIN as ALARM_DOMAIN -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_USERNAME, HTTP_BAD_REQUEST from .common import setup_platform @@ -79,7 +79,7 @@ async def test_invalid_credentials(hass): async def test_raise_config_entry_not_ready_when_offline(hass): - """Config entry state is ENTRY_STATE_SETUP_RETRY when abode is offline.""" + """Config entry state is SETUP_RETRY when abode is offline.""" with patch( "homeassistant.components.abode.Abode", side_effect=AbodeException("any"), @@ -87,6 +87,6 @@ async def test_raise_config_entry_not_ready_when_offline(hass): config_entry = await setup_platform(hass, ALARM_DOMAIN) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY assert hass.config_entries.flow.async_progress() == [] diff --git a/tests/components/accuweather/test_init.py b/tests/components/accuweather/test_init.py index bb45e894e74..d6f76f113b3 100644 --- a/tests/components/accuweather/test_init.py +++ b/tests/components/accuweather/test_init.py @@ -6,11 +6,7 @@ from unittest.mock import patch from accuweather import ApiError from homeassistant.components.accuweather.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE from homeassistant.util.dt import utcnow @@ -48,7 +44,7 @@ async def test_config_not_ready(hass): ): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass): @@ -56,12 +52,12 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) @@ -69,7 +65,7 @@ async def test_update_interval(hass): """Test correct update interval.""" entry = await init_integration(hass) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED current = json.loads(load_fixture("accuweather/current_conditions_data.json")) future = utcnow() + timedelta(minutes=40) @@ -91,7 +87,7 @@ async def test_update_interval_forecast(hass): """Test correct update interval when forecast is True.""" entry = await init_integration(hass, forecast=True) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED current = json.loads(load_fixture("accuweather/current_conditions_data.json")) forecast = json.loads(load_fixture("accuweather/forecast_data.json")) diff --git a/tests/components/advantage_air/test_init.py b/tests/components/advantage_air/test_init.py index 1567b9ee8ad..ca8ecff359e 100644 --- a/tests/components/advantage_air/test_init.py +++ b/tests/components/advantage_air/test_init.py @@ -1,10 +1,6 @@ """Test the Advantage Air Initialization.""" -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from tests.components.advantage_air import ( TEST_SYSTEM_DATA, @@ -22,11 +18,11 @@ async def test_async_setup_entry(hass, aioclient_mock): ) entry = await add_mock_config(hass) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED async def test_async_setup_entry_failure(hass, aioclient_mock): @@ -38,4 +34,4 @@ async def test_async_setup_entry_failure(hass, aioclient_mock): ) entry = await add_mock_config(hass) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY diff --git a/tests/components/aemet/test_config_flow.py b/tests/components/aemet/test_config_flow.py index 36713a02903..af14c170f40 100644 --- a/tests/components/aemet/test_config_flow.py +++ b/tests/components/aemet/test_config_flow.py @@ -6,7 +6,7 @@ import requests_mock from homeassistant import data_entry_flow from homeassistant.components.aemet.const import CONF_STATION_UPDATES, DOMAIN -from homeassistant.config_entries import ENTRY_STATE_LOADED, SOURCE_USER +from homeassistant.config_entries import SOURCE_USER, ConfigEntryState from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME import homeassistant.util.dt as dt_util @@ -47,7 +47,7 @@ async def test_form(hass): conf_entries = hass.config_entries.async_entries(DOMAIN) entry = conf_entries[0] - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == CONFIG[CONF_NAME] @@ -75,7 +75,7 @@ async def test_form_options(hass): assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == "loaded" + assert entry.state is ConfigEntryState.LOADED result = await hass.config_entries.options.async_init(entry.entry_id) @@ -93,7 +93,7 @@ async def test_form_options(hass): await hass.async_block_till_done() - assert entry.state == "loaded" + assert entry.state is ConfigEntryState.LOADED result = await hass.config_entries.options.async_init(entry.entry_id) @@ -111,7 +111,7 @@ async def test_form_options(hass): await hass.async_block_till_done() - assert entry.state == "loaded" + assert entry.state is ConfigEntryState.LOADED async def test_form_duplicated_id(hass): diff --git a/tests/components/aemet/test_init.py b/tests/components/aemet/test_init.py index f1c6c48f3f3..b1f452c1b46 100644 --- a/tests/components/aemet/test_init.py +++ b/tests/components/aemet/test_init.py @@ -5,7 +5,7 @@ from unittest.mock import patch import requests_mock from homeassistant.components.aemet.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME import homeassistant.util.dt as dt_util @@ -37,8 +37,8 @@ async def test_unload_entry(hass): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/airly/test_init.py b/tests/components/airly/test_init.py index da545eb5193..a20ae6ddd1a 100644 --- a/tests/components/airly/test_init.py +++ b/tests/components/airly/test_init.py @@ -5,11 +5,7 @@ import pytest from homeassistant.components.airly import set_update_interval from homeassistant.components.airly.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE from homeassistant.util.dt import utcnow @@ -52,7 +48,7 @@ async def test_config_not_ready(hass, aioclient_mock): aioclient_mock.get(API_POINT_URL, exc=ConnectionError()) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_config_without_unique_id(hass, aioclient_mock): @@ -71,7 +67,7 @@ async def test_config_without_unique_id(hass, aioclient_mock): aioclient_mock.get(API_POINT_URL, text=load_fixture("airly_valid_station.json")) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert entry.unique_id == "123-456" @@ -92,7 +88,7 @@ async def test_config_with_turned_off_station(hass, aioclient_mock): aioclient_mock.get(API_POINT_URL, text=load_fixture("airly_no_station.json")) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_update_interval(hass, aioclient_mock): @@ -127,7 +123,7 @@ async def test_update_interval(hass, aioclient_mock): assert aioclient_mock.call_count == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED update_interval = set_update_interval(instances, REMAINING_RQUESTS) future = utcnow() + update_interval @@ -164,7 +160,7 @@ async def test_update_interval(hass, aioclient_mock): assert aioclient_mock.call_count == 3 assert len(hass.config_entries.async_entries(DOMAIN)) == 2 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED update_interval = set_update_interval(instances, REMAINING_RQUESTS) future = utcnow() + update_interval @@ -181,12 +177,12 @@ async def test_unload_entry(hass, aioclient_mock): entry = await init_integration(hass, aioclient_mock) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) diff --git a/tests/components/almond/test_init.py b/tests/components/almond/test_init.py index fb74bdfa7f5..64537aa9465 100644 --- a/tests/components/almond/test_init.py +++ b/tests/components/almond/test_init.py @@ -38,7 +38,7 @@ async def test_set_up_oauth_remote_url(hass, aioclient_mock): ): assert await async_setup_component(hass, "almond", {}) - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED hass.config.components.add("cloud") with patch("homeassistant.components.almond.ALMOND_SETUP_DELAY", 0), patch( @@ -71,7 +71,7 @@ async def test_set_up_oauth_no_external_url(hass, aioclient_mock): ), patch("pyalmond.WebAlmondAPI.async_create_device") as mock_create_device: assert await async_setup_component(hass, "almond", {}) - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert len(mock_create_device.mock_calls) == 0 @@ -90,7 +90,7 @@ async def test_set_up_hassio(hass, aioclient_mock): with patch("pyalmond.WebAlmondAPI.async_create_device") as mock_create_device: assert await async_setup_component(hass, "almond", {}) - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert len(mock_create_device.mock_calls) == 0 @@ -112,5 +112,5 @@ async def test_set_up_local(hass, aioclient_mock): with patch("pyalmond.WebAlmondAPI.async_create_device") as mock_create_device: assert await async_setup_component(hass, "almond", {}) - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert len(mock_create_device.mock_calls) == 1 diff --git a/tests/components/atag/test_init.py b/tests/components/atag/test_init.py index 7b7f3c1e33a..59f38ae7bfe 100644 --- a/tests/components/atag/test_init.py +++ b/tests/components/atag/test_init.py @@ -1,7 +1,7 @@ """Tests for the ATAG integration.""" from homeassistant.components.atag import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from . import init_integration, mock_connection @@ -15,7 +15,7 @@ async def test_config_entry_not_ready( """Test configuration entry not ready on library error.""" mock_connection(aioclient_mock, conn_error=True) entry = await init_integration(hass, aioclient_mock) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_config_entry( diff --git a/tests/components/august/test_init.py b/tests/components/august/test_init.py index bc9f0048738..44594239d74 100644 --- a/tests/components/august/test_init.py +++ b/tests/components/august/test_init.py @@ -9,11 +9,7 @@ from yalexs.exceptions import AugustApiAIOHTTPError from homeassistant import setup from homeassistant.components.august.const import DOMAIN from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ( ATTR_ENTITY_ID, SERVICE_LOCK, @@ -36,7 +32,7 @@ from tests.components.august.mocks import ( async def test_august_is_offline(hass): - """Config entry state is ENTRY_STATE_SETUP_RETRY when august is offline.""" + """Config entry state is SETUP_RETRY when august is offline.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -53,7 +49,7 @@ async def test_august_is_offline(hass): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY async def test_unlock_throws_august_api_http_error(hass): @@ -141,7 +137,7 @@ async def test_lock_has_doorsense(hass): async def test_auth_fails(hass): - """Config entry state is ENTRY_STATE_SETUP_ERROR when auth fails.""" + """Config entry state is SETUP_ERROR when auth fails.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -159,7 +155,7 @@ async def test_auth_fails(hass): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() @@ -167,7 +163,7 @@ async def test_auth_fails(hass): async def test_bad_password(hass): - """Config entry state is ENTRY_STATE_SETUP_ERROR when the password has been changed.""" + """Config entry state is SETUP_ERROR when the password has been changed.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -187,7 +183,7 @@ async def test_bad_password(hass): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() @@ -195,7 +191,7 @@ async def test_bad_password(hass): async def test_http_failure(hass): - """Config entry state is ENTRY_STATE_SETUP_RETRY when august is offline.""" + """Config entry state is SETUP_RETRY when august is offline.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -213,13 +209,13 @@ async def test_http_failure(hass): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY assert hass.config_entries.flow.async_progress() == [] async def test_unknown_auth_state(hass): - """Config entry state is ENTRY_STATE_SETUP_ERROR when august is in an unknown auth state.""" + """Config entry state is SETUP_ERROR when august is in an unknown auth state.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -237,7 +233,7 @@ async def test_unknown_auth_state(hass): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() @@ -245,7 +241,7 @@ async def test_unknown_auth_state(hass): async def test_requires_validation_state(hass): - """Config entry state is ENTRY_STATE_SETUP_ERROR when august requires validation.""" + """Config entry state is SETUP_ERROR when august requires validation.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -265,14 +261,14 @@ async def test_requires_validation_state(hass): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR assert len(hass.config_entries.flow.async_progress()) == 1 assert hass.config_entries.flow.async_progress()[0]["context"]["source"] == "reauth" async def test_unknown_auth_http_401(hass): - """Config entry state is ENTRY_STATE_SETUP_ERROR when august gets an http.""" + """Config entry state is SETUP_ERROR when august gets an http.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -290,7 +286,7 @@ async def test_unknown_auth_http_401(hass): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() @@ -306,7 +302,7 @@ async def test_load_unload(hass): hass, [august_operative_lock, august_inoperative_lock] ) - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(config_entry.entry_id) await hass.async_block_till_done() diff --git a/tests/components/blebox/test_config_flow.py b/tests/components/blebox/test_config_flow.py index 965c707d2af..03f5d0b4f2a 100644 --- a/tests/components/blebox/test_config_flow.py +++ b/tests/components/blebox/test_config_flow.py @@ -173,7 +173,7 @@ async def test_async_setup_entry(hass, valid_feature_mock): await hass.async_block_till_done() assert hass.config_entries.async_entries() == [config] - assert config.state == config_entries.ENTRY_STATE_LOADED + assert config.state is config_entries.ConfigEntryState.LOADED async def test_async_remove_entry(hass, valid_feature_mock): @@ -189,4 +189,4 @@ async def test_async_remove_entry(hass, valid_feature_mock): await hass.async_block_till_done() assert hass.config_entries.async_entries() == [] - assert config.state == config_entries.ENTRY_STATE_NOT_LOADED + assert config.state is config_entries.ConfigEntryState.NOT_LOADED diff --git a/tests/components/blebox/test_init.py b/tests/components/blebox/test_init.py index 098c10f2cfc..c0add2696b5 100644 --- a/tests/components/blebox/test_init.py +++ b/tests/components/blebox/test_init.py @@ -5,7 +5,7 @@ import logging import blebox_uniapi from homeassistant.components.blebox.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_NOT_LOADED, ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from .conftest import mock_config, patch_product_identify @@ -23,7 +23,7 @@ async def test_setup_failure(hass, caplog): await hass.async_block_till_done() assert "Identify failed at 172.100.123.4:80 ()" in caplog.text - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_setup_failure_on_connection(hass, caplog): @@ -39,7 +39,7 @@ async def test_setup_failure_on_connection(hass, caplog): await hass.async_block_till_done() assert "Identify failed at 172.100.123.4:80 ()" in caplog.text - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_config_entry(hass): @@ -57,4 +57,4 @@ async def test_unload_config_entry(hass): await hass.async_block_till_done() assert not hass.data.get(DOMAIN) - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/bond/test_init.py b/tests/components/bond/test_init.py index 0bba04b4d97..4ba105248df 100644 --- a/tests/components/bond/test_init.py +++ b/tests/components/bond/test_init.py @@ -5,11 +5,7 @@ from aiohttp import ClientConnectionError, ClientResponseError from bond_api import DeviceType from homeassistant.components.bond.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr @@ -47,7 +43,7 @@ async def test_async_setup_raises_entry_not_ready(hass: HomeAssistant): with patch_bond_version(side_effect=ClientConnectionError()): await hass.config_entries.async_setup(config_entry.entry_id) - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY async def test_async_setup_entry_sets_up_hub_and_supported_domains(hass: HomeAssistant): @@ -75,7 +71,7 @@ async def test_async_setup_entry_sets_up_hub_and_supported_domains(hass: HomeAss await hass.async_block_till_done() assert config_entry.entry_id in hass.data[DOMAIN] - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED assert config_entry.unique_id == "test-bond-id" # verify hub device is registered correctly @@ -115,7 +111,7 @@ async def test_unload_config_entry(hass: HomeAssistant): await hass.async_block_till_done() assert config_entry.entry_id not in hass.data[DOMAIN] - assert config_entry.state == ENTRY_STATE_NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED async def test_old_identifiers_are_removed(hass: HomeAssistant): @@ -159,7 +155,7 @@ async def test_old_identifiers_are_removed(hass: HomeAssistant): await hass.async_block_till_done() assert config_entry.entry_id in hass.data[DOMAIN] - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED assert config_entry.unique_id == "test-bond-id" # verify the device info is cleaned up @@ -201,7 +197,7 @@ async def test_smart_by_bond_device_suggested_area(hass: HomeAssistant): await hass.async_block_till_done() assert config_entry.entry_id in hass.data[DOMAIN] - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED assert config_entry.unique_id == "test-bond-id" device_registry = dr.async_get(hass) @@ -247,7 +243,7 @@ async def test_bridge_device_suggested_area(hass: HomeAssistant): await hass.async_block_till_done() assert config_entry.entry_id in hass.data[DOMAIN] - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED assert config_entry.unique_id == "test-bond-id" device_registry = dr.async_get(hass) diff --git a/tests/components/broadlink/test_device.py b/tests/components/broadlink/test_device.py index 8e53fd74c1c..2ee8f7a5218 100644 --- a/tests/components/broadlink/test_device.py +++ b/tests/components/broadlink/test_device.py @@ -5,12 +5,7 @@ import broadlink.exceptions as blke from homeassistant.components.broadlink.const import DOMAIN from homeassistant.components.broadlink.device import get_domains -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.helpers.entity_registry import async_entries_for_device from . import get_device @@ -29,7 +24,7 @@ async def test_device_setup(hass): ) as mock_init: mock_api, mock_entry = await device.setup_entry(hass) - assert mock_entry.state == ENTRY_STATE_LOADED + assert mock_entry.state == ConfigEntryState.LOADED assert mock_api.auth.call_count == 1 assert mock_api.get_fwversion.call_count == 1 forward_entries = {c[1][1] for c in mock_forward.mock_calls} @@ -52,7 +47,7 @@ async def test_device_setup_authentication_error(hass): ) as mock_init: mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_SETUP_ERROR + assert mock_entry.state == ConfigEntryState.SETUP_ERROR assert mock_api.auth.call_count == 1 assert mock_forward.call_count == 0 assert mock_init.call_count == 1 @@ -76,7 +71,7 @@ async def test_device_setup_network_timeout(hass): ) as mock_init: mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_SETUP_RETRY + assert mock_entry.state is ConfigEntryState.SETUP_RETRY assert mock_api.auth.call_count == 1 assert mock_forward.call_count == 0 assert mock_init.call_count == 0 @@ -95,7 +90,7 @@ async def test_device_setup_os_error(hass): ) as mock_init: mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_SETUP_RETRY + assert mock_entry.state is ConfigEntryState.SETUP_RETRY assert mock_api.auth.call_count == 1 assert mock_forward.call_count == 0 assert mock_init.call_count == 0 @@ -114,7 +109,7 @@ async def test_device_setup_broadlink_exception(hass): ) as mock_init: mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_SETUP_ERROR + assert mock_entry.state is ConfigEntryState.SETUP_ERROR assert mock_api.auth.call_count == 1 assert mock_forward.call_count == 0 assert mock_init.call_count == 0 @@ -133,7 +128,7 @@ async def test_device_setup_update_network_timeout(hass): ) as mock_init: mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_SETUP_RETRY + assert mock_entry.state is ConfigEntryState.SETUP_RETRY assert mock_api.auth.call_count == 1 assert mock_api.check_sensors.call_count == 1 assert mock_forward.call_count == 0 @@ -156,7 +151,7 @@ async def test_device_setup_update_authorization_error(hass): ) as mock_init: mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_LOADED + assert mock_entry.state is ConfigEntryState.LOADED assert mock_api.auth.call_count == 2 assert mock_api.check_sensors.call_count == 2 forward_entries = {c[1][1] for c in mock_forward.mock_calls} @@ -180,7 +175,7 @@ async def test_device_setup_update_authentication_error(hass): ) as mock_init: mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_SETUP_RETRY + assert mock_entry.state is ConfigEntryState.SETUP_RETRY assert mock_api.auth.call_count == 2 assert mock_api.check_sensors.call_count == 1 assert mock_forward.call_count == 0 @@ -205,7 +200,7 @@ async def test_device_setup_update_broadlink_exception(hass): ) as mock_init: mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_SETUP_RETRY + assert mock_entry.state is ConfigEntryState.SETUP_RETRY assert mock_api.auth.call_count == 1 assert mock_api.check_sensors.call_count == 1 assert mock_forward.call_count == 0 @@ -221,7 +216,7 @@ async def test_device_setup_get_fwversion_broadlink_exception(hass): with patch.object(hass.config_entries, "async_forward_entry_setup") as mock_forward: mock_api, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_LOADED + assert mock_entry.state is ConfigEntryState.LOADED forward_entries = {c[1][1] for c in mock_forward.mock_calls} domains = get_domains(mock_api.type) assert mock_forward.call_count == len(domains) @@ -237,7 +232,7 @@ async def test_device_setup_get_fwversion_os_error(hass): with patch.object(hass.config_entries, "async_forward_entry_setup") as mock_forward: _, mock_entry = await device.setup_entry(hass, mock_api=mock_api) - assert mock_entry.state == ENTRY_STATE_LOADED + assert mock_entry.state is ConfigEntryState.LOADED forward_entries = {c[1][1] for c in mock_forward.mock_calls} domains = get_domains(mock_api.type) assert mock_forward.call_count == len(domains) @@ -279,7 +274,7 @@ async def test_device_unload_works(hass): ) as mock_forward: await hass.config_entries.async_unload(mock_entry.entry_id) - assert mock_entry.state == ENTRY_STATE_NOT_LOADED + assert mock_entry.state is ConfigEntryState.NOT_LOADED forward_entries = {c[1][1] for c in mock_forward.mock_calls} domains = get_domains(mock_api.type) assert mock_forward.call_count == len(domains) @@ -302,7 +297,7 @@ async def test_device_unload_authentication_error(hass): ) as mock_forward: await hass.config_entries.async_unload(mock_entry.entry_id) - assert mock_entry.state == ENTRY_STATE_NOT_LOADED + assert mock_entry.state is ConfigEntryState.NOT_LOADED assert mock_forward.call_count == 0 @@ -320,7 +315,7 @@ async def test_device_unload_update_failed(hass): ) as mock_forward: await hass.config_entries.async_unload(mock_entry.entry_id) - assert mock_entry.state == ENTRY_STATE_NOT_LOADED + assert mock_entry.state is ConfigEntryState.NOT_LOADED assert mock_forward.call_count == 0 diff --git a/tests/components/brother/test_init.py b/tests/components/brother/test_init.py index 7b85586ce28..76b999c3e54 100644 --- a/tests/components/brother/test_init.py +++ b/tests/components/brother/test_init.py @@ -2,11 +2,7 @@ from unittest.mock import patch from homeassistant.components.brother.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_HOST, CONF_TYPE, STATE_UNAVAILABLE from tests.common import MockConfigEntry @@ -35,7 +31,7 @@ async def test_config_not_ready(hass): with patch("brother.Brother._get_data", side_effect=ConnectionError()): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass): @@ -43,10 +39,10 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) diff --git a/tests/components/bsblan/test_init.py b/tests/components/bsblan/test_init.py index b6096ced0ac..c7937daf786 100644 --- a/tests/components/bsblan/test_init.py +++ b/tests/components/bsblan/test_init.py @@ -2,7 +2,7 @@ import aiohttp from homeassistant.components.bsblan.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.components.bsblan import init_integration, init_integration_without_auth @@ -19,7 +19,7 @@ async def test_config_entry_not_ready( ) entry = await init_integration(hass, aioclient_mock) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_config_entry( @@ -44,4 +44,4 @@ async def test_config_entry_no_authentication( ) entry = await init_integration_without_auth(hass, aioclient_mock) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY diff --git a/tests/components/buienradar/test_init.py b/tests/components/buienradar/test_init.py index ea91291a3de..0c25fcc1886 100644 --- a/tests/components/buienradar/test_init.py +++ b/tests/components/buienradar/test_init.py @@ -3,6 +3,7 @@ from unittest.mock import patch from homeassistant import setup from homeassistant.components.buienradar.const import DOMAIN +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE from homeassistant.helpers.entity_registry import async_get_registry @@ -39,7 +40,7 @@ async def test_import_all(hass): entry = conf_entries[0] - assert entry.state == "loaded" + assert entry.state is ConfigEntryState.LOADED assert entry.data == { "latitude": hass.config.latitude, "longitude": hass.config.longitude, @@ -77,7 +78,7 @@ async def test_import_camera(hass): entry = conf_entries[0] - assert entry.state == "loaded" + assert entry.state is ConfigEntryState.LOADED assert entry.data == { "latitude": hass.config.latitude, "longitude": hass.config.longitude, @@ -112,9 +113,9 @@ async def test_load_unload(aioclient_mock, hass): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == "loaded" + assert entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == "not_loaded" + assert entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/canary/test_init.py b/tests/components/canary/test_init.py index a767eb0ec51..21b897509eb 100644 --- a/tests/components/canary/test_init.py +++ b/tests/components/canary/test_init.py @@ -5,11 +5,7 @@ from requests import ConnectTimeout from homeassistant.components.camera.const import DOMAIN as CAMERA_DOMAIN from homeassistant.components.canary.const import CONF_FFMPEG_ARGUMENTS, DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME from homeassistant.setup import async_setup_component @@ -64,12 +60,12 @@ async def test_unload_entry(hass, canary): assert entry assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) @@ -79,4 +75,4 @@ async def test_async_setup_raises_entry_not_ready(hass, canary): entry = await init_integration(hass) assert entry - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY diff --git a/tests/components/cert_expiry/test_init.py b/tests/components/cert_expiry/test_init.py index 1c62782107b..dbe5e74d891 100644 --- a/tests/components/cert_expiry/test_init.py +++ b/tests/components/cert_expiry/test_init.py @@ -4,7 +4,7 @@ from unittest.mock import patch from homeassistant.components.cert_expiry.const import DOMAIN from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN -from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ( CONF_HOST, CONF_PORT, @@ -63,7 +63,7 @@ async def test_update_unique_id(hass): assert await async_setup_component(hass, DOMAIN, {}) is True await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert entry.unique_id == f"{HOST}:{PORT}" @@ -89,7 +89,7 @@ async def test_unload_config_entry(mock_now, hass): assert await async_setup_component(hass, DOMAIN, {}) is True await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("sensor.cert_expiry_timestamp_example_com") assert state.state == timestamp.isoformat() assert state.attributes.get("error") == "None" @@ -97,7 +97,7 @@ async def test_unload_config_entry(mock_now, hass): await hass.config_entries.async_unload(entry.entry_id) - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED state = hass.states.get("sensor.cert_expiry_timestamp_example_com") assert state.state == STATE_UNAVAILABLE diff --git a/tests/components/cert_expiry/test_sensors.py b/tests/components/cert_expiry/test_sensors.py index 375b676eaf8..099fe78ca39 100644 --- a/tests/components/cert_expiry/test_sensors.py +++ b/tests/components/cert_expiry/test_sensors.py @@ -5,7 +5,7 @@ import ssl from unittest.mock import patch from homeassistant.components.cert_expiry.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_HOST, CONF_PORT, STATE_UNAVAILABLE, STATE_UNKNOWN from homeassistant.util.dt import utcnow @@ -81,7 +81,7 @@ async def test_async_setup_entry_host_unavailable(hass): assert await hass.config_entries.async_setup(entry.entry_id) is False await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY next_update = utcnow() + timedelta(seconds=45) async_fire_time_changed(hass, next_update) diff --git a/tests/components/cloudflare/test_init.py b/tests/components/cloudflare/test_init.py index 1fb4af7f9aa..5a42ca9f09c 100644 --- a/tests/components/cloudflare/test_init.py +++ b/tests/components/cloudflare/test_init.py @@ -2,11 +2,7 @@ from pycfdns.exceptions import CloudflareConnectionException from homeassistant.components.cloudflare.const import DOMAIN, SERVICE_UPDATE_RECORDS -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from . import ENTRY_CONFIG, init_integration @@ -18,12 +14,12 @@ async def test_unload_entry(hass, cfupdate): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) @@ -37,7 +33,7 @@ async def test_async_setup_raises_entry_not_ready(hass, cfupdate): instance.get_zone_id.side_effect = CloudflareConnectionException() await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_integration_services(hass, cfupdate): @@ -45,7 +41,7 @@ async def test_integration_services(hass, cfupdate): instance = cfupdate.return_value entry = await init_integration(hass) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.services.async_call( DOMAIN, diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 1ad2bd978fc..10fc3aadba0 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -64,7 +64,7 @@ async def test_get_entries(hass, client): domain="comp2", title="Test 2", source="bla2", - state=core_ce.ENTRY_STATE_SETUP_ERROR, + state=core_ce.ConfigEntryState.SETUP_ERROR, reason="Unsupported API", ).add_to_hass(hass) MockConfigEntry( @@ -84,7 +84,7 @@ async def test_get_entries(hass, client): "domain": "comp1", "title": "Test 1", "source": "bla", - "state": "not_loaded", + "state": core_ce.ConfigEntryState.NOT_LOADED.value, "supports_options": True, "supports_unload": True, "disabled_by": None, @@ -94,7 +94,7 @@ async def test_get_entries(hass, client): "domain": "comp2", "title": "Test 2", "source": "bla2", - "state": "setup_error", + "state": core_ce.ConfigEntryState.SETUP_ERROR.value, "supports_options": False, "supports_unload": False, "disabled_by": None, @@ -104,7 +104,7 @@ async def test_get_entries(hass, client): "domain": "comp3", "title": "Test 3", "source": "bla3", - "state": "not_loaded", + "state": core_ce.ConfigEntryState.NOT_LOADED.value, "supports_options": False, "supports_unload": False, "disabled_by": core_ce.DISABLED_USER, @@ -115,7 +115,7 @@ async def test_get_entries(hass, client): async def test_remove_entry(hass, client): """Test removing an entry via the API.""" - entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED) + entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED) entry.add_to_hass(hass) resp = await client.delete(f"/api/config/config_entries/entry/{entry.entry_id}") assert resp.status == 200 @@ -126,7 +126,7 @@ async def test_remove_entry(hass, client): async def test_reload_entry(hass, client): """Test reloading an entry via the API.""" - entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED) + entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED) entry.add_to_hass(hass) resp = await client.post( f"/api/config/config_entries/entry/{entry.entry_id}/reload" @@ -146,7 +146,7 @@ async def test_reload_invalid_entry(hass, client): async def test_remove_entry_unauth(hass, client, hass_admin_user): """Test removing an entry via the API.""" hass_admin_user.groups = [] - entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED) + entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED) entry.add_to_hass(hass) resp = await client.delete(f"/api/config/config_entries/entry/{entry.entry_id}") assert resp.status == 401 @@ -156,7 +156,7 @@ async def test_remove_entry_unauth(hass, client, hass_admin_user): async def test_reload_entry_unauth(hass, client, hass_admin_user): """Test reloading an entry via the API.""" hass_admin_user.groups = [] - entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED) + entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED) entry.add_to_hass(hass) resp = await client.post( f"/api/config/config_entries/entry/{entry.entry_id}/reload" @@ -167,7 +167,7 @@ async def test_reload_entry_unauth(hass, client, hass_admin_user): async def test_reload_entry_in_failed_state(hass, client, hass_admin_user): """Test reloading an entry via the API that has already failed to unload.""" - entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_FAILED_UNLOAD) + entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.FAILED_UNLOAD) entry.add_to_hass(hass) resp = await client.post( f"/api/config/config_entries/entry/{entry.entry_id}/reload" @@ -325,7 +325,7 @@ async def test_create_account(hass, client, enable_custom_integrations): "domain": "test", "entry_id": entries[0].entry_id, "source": core_ce.SOURCE_USER, - "state": "loaded", + "state": core_ce.ConfigEntryState.LOADED.value, "supports_options": False, "supports_unload": False, "title": "Test Entry", @@ -396,7 +396,7 @@ async def test_two_step_flow(hass, client, enable_custom_integrations): "domain": "test", "entry_id": entries[0].entry_id, "source": core_ce.SOURCE_USER, - "state": "loaded", + "state": core_ce.ConfigEntryState.LOADED.value, "supports_options": False, "supports_unload": False, "title": "user-title", @@ -788,7 +788,7 @@ async def test_disable_entry(hass, hass_ws_client): assert await async_setup_component(hass, "config", {}) ws_client = await hass_ws_client(hass) - entry = MockConfigEntry(domain="demo", state="loaded") + entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED) entry.add_to_hass(hass) assert entry.disabled_by is None @@ -806,7 +806,7 @@ async def test_disable_entry(hass, hass_ws_client): assert response["success"] assert response["result"] == {"require_restart": True} assert entry.disabled_by == core_ce.DISABLED_USER - assert entry.state == "failed_unload" + assert entry.state is core_ce.ConfigEntryState.FAILED_UNLOAD # Enable await ws_client.send_json( @@ -822,7 +822,7 @@ async def test_disable_entry(hass, hass_ws_client): assert response["success"] assert response["result"] == {"require_restart": True} assert entry.disabled_by is None - assert entry.state == "failed_unload" + assert entry.state == core_ce.ConfigEntryState.FAILED_UNLOAD # Enable again -> no op await ws_client.send_json( @@ -838,7 +838,7 @@ async def test_disable_entry(hass, hass_ws_client): assert response["success"] assert response["result"] == {"require_restart": False} assert entry.disabled_by is None - assert entry.state == "failed_unload" + assert entry.state == core_ce.ConfigEntryState.FAILED_UNLOAD async def test_disable_entry_nonexisting(hass, hass_ws_client): diff --git a/tests/components/coronavirus/test_init.py b/tests/components/coronavirus/test_init.py index c36255db9d1..eeb91e77239 100644 --- a/tests/components/coronavirus/test_init.py +++ b/tests/components/coronavirus/test_init.py @@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patch from aiohttp import ClientError from homeassistant.components.coronavirus.const import DOMAIN, OPTION_WORLDWIDE -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component @@ -69,4 +69,4 @@ async def test_config_entry_not_ready( assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY diff --git a/tests/components/devolo_home_control/test_init.py b/tests/components/devolo_home_control/test_init.py index 3f124ee2098..657836f9d16 100644 --- a/tests/components/devolo_home_control/test_init.py +++ b/tests/components/devolo_home_control/test_init.py @@ -4,12 +4,7 @@ from unittest.mock import patch from devolo_home_control_api.exceptions.gateway import GatewayOfflineError import pytest -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.components.devolo_home_control import configure_integration @@ -20,7 +15,7 @@ async def test_setup_entry(hass: HomeAssistant): entry = configure_integration(hass) with patch("homeassistant.components.devolo_home_control.HomeControl"): await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED @pytest.mark.credentials_invalid @@ -28,7 +23,7 @@ async def test_setup_entry_credentials_invalid(hass: HomeAssistant): """Test setup entry fails if credentials are invalid.""" entry = configure_integration(hass) await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_ERROR + assert entry.state is ConfigEntryState.SETUP_ERROR @pytest.mark.maintenance @@ -36,7 +31,7 @@ async def test_setup_entry_maintenance(hass: HomeAssistant): """Test setup entry fails if mydevolo is in maintenance mode.""" entry = configure_integration(hass) await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_setup_gateway_offline(hass: HomeAssistant): @@ -47,7 +42,7 @@ async def test_setup_gateway_offline(hass: HomeAssistant): side_effect=GatewayOfflineError, ): await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass: HomeAssistant): @@ -57,4 +52,4 @@ async def test_unload_entry(hass: HomeAssistant): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() await hass.config_entries.async_unload(entry.entry_id) - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/dexcom/test_init.py b/tests/components/dexcom/test_init.py index a155450bf26..2509ba25f33 100644 --- a/tests/components/dexcom/test_init.py +++ b/tests/components/dexcom/test_init.py @@ -4,7 +4,7 @@ from unittest.mock import patch from pydexcom import AccountError, SessionError from homeassistant.components.dexcom.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from tests.common import MockConfigEntry from tests.components.dexcom import CONFIG, init_integration @@ -55,10 +55,10 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) diff --git a/tests/components/directv/test_init.py b/tests/components/directv/test_init.py index 96fd27a30eb..3ef151f4257 100644 --- a/tests/components/directv/test_init.py +++ b/tests/components/directv/test_init.py @@ -1,10 +1,6 @@ """Tests for the DirecTV integration.""" from homeassistant.components.directv.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.components.directv import setup_integration @@ -19,7 +15,7 @@ async def test_config_entry_not_ready( """Test the DirecTV configuration entry not ready.""" entry = await setup_integration(hass, aioclient_mock, setup_error=True) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_config_entry( @@ -29,10 +25,10 @@ async def test_unload_config_entry( entry = await setup_integration(hass, aioclient_mock) assert entry.entry_id in hass.data[DOMAIN] - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() assert entry.entry_id not in hass.data[DOMAIN] - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/dsmr/test_sensor.py b/tests/components/dsmr/test_sensor.py index e037585f8ff..29ab29a0af6 100644 --- a/tests/components/dsmr/test_sensor.py +++ b/tests/components/dsmr/test_sensor.py @@ -11,6 +11,7 @@ from decimal import Decimal from itertools import chain, repeat from unittest.mock import DEFAULT, MagicMock +from homeassistant import config_entries from homeassistant.components.dsmr.const import DOMAIN from homeassistant.components.dsmr.sensor import DerivativeDSMREntity from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN @@ -59,7 +60,7 @@ async def test_setup_platform(hass, dsmr_connection_fixture): entry = conf_entries[0] - assert entry.state == "loaded" + assert entry.state == config_entries.ConfigEntryState.LOADED assert entry.data == {**entry_data, **serial_data} @@ -625,4 +626,4 @@ async def test_reconnect(hass, dsmr_connection_fixture): await hass.config_entries.async_unload(mock_entry.entry_id) - assert mock_entry.state == "not_loaded" + assert mock_entry.state == config_entries.ConfigEntryState.NOT_LOADED diff --git a/tests/components/dynalite/test_config_flow.py b/tests/components/dynalite/test_config_flow.py index e21c82d7c20..a513fe27567 100644 --- a/tests/components/dynalite/test_config_flow.py +++ b/tests/components/dynalite/test_config_flow.py @@ -13,9 +13,9 @@ from tests.common import MockConfigEntry @pytest.mark.parametrize( "first_con, second_con,exp_type, exp_result, exp_reason", [ - (True, True, "create_entry", "loaded", ""), - (False, False, "abort", "", "no_connection"), - (True, False, "create_entry", "setup_retry", ""), + (True, True, "create_entry", config_entries.ConfigEntryState.LOADED, ""), + (False, False, "abort", None, "no_connection"), + (True, False, "create_entry", config_entries.ConfigEntryState.SETUP_RETRY, ""), ], ) async def test_flow(hass, first_con, second_con, exp_type, exp_result, exp_reason): @@ -104,4 +104,4 @@ async def test_two_entries(hass): data={dynalite.CONF_HOST: host2}, ) assert result["type"] == "create_entry" - assert result["result"].state == "loaded" + assert result["result"].state == config_entries.ConfigEntryState.LOADED diff --git a/tests/components/eafm/test_sensor.py b/tests/components/eafm/test_sensor.py index 6f5dcaa9284..d8d48367a64 100644 --- a/tests/components/eafm/test_sensor.py +++ b/tests/components/eafm/test_sensor.py @@ -35,7 +35,7 @@ async def async_setup_test_fixture(hass, mock_get_station, initial_value): entry.add_to_hass(hass) assert await async_setup_component(hass, "eafm", {}) - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED await hass.async_block_till_done() async def poll(value): diff --git a/tests/components/elgato/test_init.py b/tests/components/elgato/test_init.py index 069e533c423..f764ecdba80 100644 --- a/tests/components/elgato/test_init.py +++ b/tests/components/elgato/test_init.py @@ -2,7 +2,7 @@ import aiohttp from homeassistant.components.elgato.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.components.elgato import init_integration @@ -18,7 +18,7 @@ async def test_config_entry_not_ready( ) entry = await init_integration(hass, aioclient_mock) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_config_entry( diff --git a/tests/components/freebox/test_init.py b/tests/components/freebox/test_init.py index 6b5589ac647..44af000f79a 100644 --- a/tests/components/freebox/test_init.py +++ b/tests/components/freebox/test_init.py @@ -5,7 +5,7 @@ from homeassistant.components.device_tracker import DOMAIN as DT_DOMAIN from homeassistant.components.freebox.const import DOMAIN as DOMAIN, SERVICE_REBOOT from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN -from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_HOST, CONF_PORT, STATE_UNAVAILABLE from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -85,7 +85,7 @@ async def test_unload_remove(hass: HomeAssistant, router: Mock): assert await async_setup_component(hass, DOMAIN, {}) is True await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state_dt = hass.states.get(entity_id_dt) assert state_dt state_sensor = hass.states.get(entity_id_sensor) @@ -95,7 +95,7 @@ async def test_unload_remove(hass: HomeAssistant, router: Mock): await hass.config_entries.async_unload(entry.entry_id) - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED state_dt = hass.states.get(entity_id_dt) assert state_dt.state == STATE_UNAVAILABLE state_sensor = hass.states.get(entity_id_sensor) @@ -110,7 +110,7 @@ async def test_unload_remove(hass: HomeAssistant, router: Mock): await hass.async_block_till_done() assert router().close.call_count == 1 - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED state_dt = hass.states.get(entity_id_dt) assert state_dt is None state_sensor = hass.states.get(entity_id_sensor) diff --git a/tests/components/fritzbox/test_init.py b/tests/components/fritzbox/test_init.py index 14df6f869f8..438335868cd 100644 --- a/tests/components/fritzbox/test_init.py +++ b/tests/components/fritzbox/test_init.py @@ -8,11 +8,7 @@ from requests.exceptions import HTTPError from homeassistant.components.fritzbox.const import DOMAIN as FB_DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ( CONF_DEVICES, CONF_HOST, @@ -94,14 +90,14 @@ async def test_unload_remove(hass: HomeAssistant, fritz: Mock): assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get(entity_id) assert state await hass.config_entries.async_unload(entry.entry_id) assert fritz().logout.call_count == 1 - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED state = hass.states.get(entity_id) assert state.state == STATE_UNAVAILABLE @@ -109,13 +105,13 @@ async def test_unload_remove(hass: HomeAssistant, fritz: Mock): await hass.async_block_till_done() assert fritz().logout.call_count == 1 - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED state = hass.states.get(entity_id) assert state is None async def test_raise_config_entry_not_ready_when_offline(hass: HomeAssistant): - """Config entry state is ENTRY_STATE_SETUP_RETRY when fritzbox is offline.""" + """Config entry state is SETUP_RETRY when fritzbox is offline.""" entry = MockConfigEntry( domain=FB_DOMAIN, data={CONF_HOST: "any", **MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0]}, @@ -132,4 +128,4 @@ async def test_raise_config_entry_not_ready_when_offline(hass: HomeAssistant): entries = hass.config_entries.async_entries() config_entry = entries[0] - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR diff --git a/tests/components/gios/test_init.py b/tests/components/gios/test_init.py index 85834571c86..08629608cd4 100644 --- a/tests/components/gios/test_init.py +++ b/tests/components/gios/test_init.py @@ -3,11 +3,7 @@ import json from unittest.mock import patch from homeassistant.components.gios.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE from . import STATIONS @@ -41,7 +37,7 @@ async def test_config_not_ready(hass): ): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass): @@ -49,12 +45,12 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) diff --git a/tests/components/gree/test_init.py b/tests/components/gree/test_init.py index 7443ae1e94c..82b082b03cb 100644 --- a/tests/components/gree/test_init.py +++ b/tests/components/gree/test_init.py @@ -2,7 +2,7 @@ from unittest.mock import patch from homeassistant.components.gree.const import DOMAIN as GREE_DOMAIN -from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry @@ -25,7 +25,7 @@ async def test_setup_simple(hass): assert len(climate_setup.mock_calls) == 1 assert len(switch_setup.mock_calls) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED # No flows started assert len(hass.config_entries.flow.async_progress()) == 0 @@ -43,4 +43,4 @@ async def test_unload_config_entry(hass): await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/home_plus_control/test_init.py b/tests/components/home_plus_control/test_init.py index e48a9dc1f85..4da913047a2 100644 --- a/tests/components/home_plus_control/test_init.py +++ b/tests/components/home_plus_control/test_init.py @@ -36,7 +36,7 @@ async def test_loading(hass, mock_config_entry): await hass.async_block_till_done() assert len(mock_check.mock_calls) == 1 - assert mock_config_entry.state == config_entries.ENTRY_STATE_LOADED + assert mock_config_entry.state is config_entries.ConfigEntryState.LOADED async def test_loading_with_no_config(hass, mock_config_entry): @@ -44,7 +44,7 @@ async def test_loading_with_no_config(hass, mock_config_entry): mock_config_entry.add_to_hass(hass) await setup.async_setup_component(hass, DOMAIN, {}) # Component setup fails because the oauth2 implementation could not be registered - assert mock_config_entry.state == config_entries.ENTRY_STATE_SETUP_ERROR + assert mock_config_entry.state is config_entries.ConfigEntryState.SETUP_ERROR async def test_unloading(hass, mock_config_entry): @@ -68,8 +68,8 @@ async def test_unloading(hass, mock_config_entry): await hass.async_block_till_done() assert len(mock_check.mock_calls) == 1 - assert mock_config_entry.state == config_entries.ENTRY_STATE_LOADED + assert mock_config_entry.state is config_entries.ConfigEntryState.LOADED # We now unload the entry assert await hass.config_entries.async_unload(mock_config_entry.entry_id) - assert mock_config_entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert mock_config_entry.state is config_entries.ConfigEntryState.NOT_LOADED diff --git a/tests/components/home_plus_control/test_switch.py b/tests/components/home_plus_control/test_switch.py index f699fe08d05..aec23f0d32a 100644 --- a/tests/components/home_plus_control/test_switch.py +++ b/tests/components/home_plus_control/test_switch.py @@ -388,7 +388,7 @@ async def test_initial_api_error( assert len(mock_check.mock_calls) == 1 # The component has been loaded - assert mock_config_entry.state == config_entries.ENTRY_STATE_LOADED + assert mock_config_entry.state is config_entries.ConfigEntryState.LOADED # Check the entities and devices - None have been configured entity_assertions(hass, num_exp_entities=0) @@ -421,7 +421,7 @@ async def test_update_with_api_error( assert len(mock_check.mock_calls) == 1 # The component has been loaded - assert mock_config_entry.state == config_entries.ENTRY_STATE_LOADED + assert mock_config_entry.state is config_entries.ConfigEntryState.LOADED # Check the entities and devices - all entities should be there entity_assertions( diff --git a/tests/components/homekit_controller/specific_devices/test_ecobee3.py b/tests/components/homekit_controller/specific_devices/test_ecobee3.py index ae050f67324..cc6c7ae4b9f 100644 --- a/tests/components/homekit_controller/specific_devices/test_ecobee3.py +++ b/tests/components/homekit_controller/specific_devices/test_ecobee3.py @@ -14,7 +14,7 @@ from homeassistant.components.climate.const import ( SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE, ) -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.helpers import device_registry as dr, entity_registry as er from tests.components.homekit_controller.common import ( @@ -143,7 +143,7 @@ async def test_ecobee3_setup_connection_failure(hass): # If there is no cached entity map and the accessory connection is # failing then we have to fail the config entry setup. config_entry, pairing = await setup_test_accessories(hass, accessories) - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY climate = entity_registry.async_get("climate.homew") assert climate is None diff --git a/tests/components/homematicip_cloud/test_hap.py b/tests/components/homematicip_cloud/test_hap.py index 1f85626980c..a8b3229e8db 100644 --- a/tests/components/homematicip_cloud/test_hap.py +++ b/tests/components/homematicip_cloud/test_hap.py @@ -18,7 +18,7 @@ from homeassistant.components.homematicip_cloud.hap import ( HomematicipAuth, HomematicipHAP, ) -from homeassistant.config_entries import ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from homeassistant.exceptions import ConfigEntryNotReady from .helper import HAPID, HAPPIN @@ -109,7 +109,7 @@ async def test_hap_reset_unloads_entry_if_setup(hass, default_mock_hap_factory): # hap_reset is called during unload await hass.config_entries.async_unload(config_entries[0].entry_id) # entry is unloaded - assert config_entries[0].state == ENTRY_STATE_NOT_LOADED + assert config_entries[0].state is ConfigEntryState.NOT_LOADED assert hass.data[HMIPC_DOMAIN] == {} diff --git a/tests/components/homematicip_cloud/test_init.py b/tests/components/homematicip_cloud/test_init.py index 250cba81637..5354070c062 100644 --- a/tests/components/homematicip_cloud/test_init.py +++ b/tests/components/homematicip_cloud/test_init.py @@ -13,12 +13,7 @@ from homeassistant.components.homematicip_cloud.const import ( HMIPC_NAME, ) from homeassistant.components.homematicip_cloud.hap import HomematicipHAP -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_NAME from homeassistant.setup import async_setup_component @@ -116,7 +111,7 @@ async def test_load_entry_fails_due_to_connection_error( assert await async_setup_component(hass, HMIPC_DOMAIN, {}) assert hass.data[HMIPC_DOMAIN][hmip_config_entry.unique_id] - assert hmip_config_entry.state == ENTRY_STATE_SETUP_RETRY + assert hmip_config_entry.state is ConfigEntryState.SETUP_RETRY async def test_load_entry_fails_due_to_generic_exception(hass, hmip_config_entry): @@ -132,7 +127,7 @@ async def test_load_entry_fails_due_to_generic_exception(hass, hmip_config_entry assert await async_setup_component(hass, HMIPC_DOMAIN, {}) assert hass.data[HMIPC_DOMAIN][hmip_config_entry.unique_id] - assert hmip_config_entry.state == ENTRY_STATE_SETUP_ERROR + assert hmip_config_entry.state is ConfigEntryState.SETUP_ERROR async def test_unload_entry(hass): @@ -157,9 +152,9 @@ async def test_unload_entry(hass): assert hass.data[HMIPC_DOMAIN]["ABC123"] config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN) assert len(config_entries) == 1 - assert config_entries[0].state == ENTRY_STATE_LOADED + assert config_entries[0].state is ConfigEntryState.LOADED await hass.config_entries.async_unload(config_entries[0].entry_id) - assert config_entries[0].state == ENTRY_STATE_NOT_LOADED + assert config_entries[0].state is ConfigEntryState.NOT_LOADED assert mock_hap.return_value.mock_calls[2][0] == "async_reset" # entry is unloaded assert hass.data[HMIPC_DOMAIN] == {} diff --git a/tests/components/huisbaasje/test_init.py b/tests/components/huisbaasje/test_init.py index 1c081936cb8..dde62a9c78b 100644 --- a/tests/components/huisbaasje/test_init.py +++ b/tests/components/huisbaasje/test_init.py @@ -4,11 +4,7 @@ from unittest.mock import patch from huisbaasje import HuisbaasjeException from homeassistant.components import huisbaasje -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_ID, CONF_PASSWORD, CONF_USERNAME, STATE_UNAVAILABLE from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -49,12 +45,12 @@ async def test_setup_entry(hass: HomeAssistant): ) config_entry.add_to_hass(hass) - assert config_entry.state == ENTRY_STATE_NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() # Assert integration is loaded - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED assert huisbaasje.DOMAIN in hass.config.components assert huisbaasje.DOMAIN in hass.data assert config_entry.entry_id in hass.data[huisbaasje.DOMAIN] @@ -89,12 +85,12 @@ async def test_setup_entry_error(hass: HomeAssistant): ) config_entry.add_to_hass(hass) - assert config_entry.state == ENTRY_STATE_NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() # Assert integration is loaded with error - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR assert huisbaasje.DOMAIN not in hass.data # Assert entities are not loaded @@ -133,13 +129,13 @@ async def test_unload_entry(hass: HomeAssistant): # Load config entry assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED entities = hass.states.async_entity_ids("sensor") assert len(entities) == 14 # Unload config entry await hass.config_entries.async_unload(config_entry.entry_id) - assert config_entry.state == ENTRY_STATE_NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED entities = hass.states.async_entity_ids("sensor") assert len(entities) == 14 for entity in entities: diff --git a/tests/components/hyperion/test_light.py b/tests/components/hyperion/test_light.py index de0110cb19f..0c6b2cf41df 100644 --- a/tests/components/hyperion/test_light.py +++ b/tests/components/hyperion/test_light.py @@ -25,10 +25,10 @@ from homeassistant.components.light import ( DOMAIN as LIGHT_DOMAIN, ) from homeassistant.config_entries import ( - ENTRY_STATE_SETUP_ERROR, RELOAD_AFTER_UPDATE_DELAY, SOURCE_REAUTH, ConfigEntry, + ConfigEntryState, ) from homeassistant.const import ( ATTR_ENTITY_ID, @@ -900,7 +900,7 @@ async def test_setup_entry_no_token_reauth(hass: HomeAssistant) -> None: }, data=config_entry.data, ) - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR async def test_setup_entry_bad_token_reauth(hass: HomeAssistant) -> None: @@ -928,7 +928,7 @@ async def test_setup_entry_bad_token_reauth(hass: HomeAssistant) -> None: }, data=config_entry.data, ) - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR async def test_priority_light_async_updates( diff --git a/tests/components/ialarm/test_init.py b/tests/components/ialarm/test_init.py index 8998b4e0d18..f33234c7256 100644 --- a/tests/components/ialarm/test_init.py +++ b/tests/components/ialarm/test_init.py @@ -5,11 +5,7 @@ from uuid import uuid4 import pytest from homeassistant.components.ialarm.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_HOST, CONF_PORT from tests.common import MockConfigEntry @@ -41,7 +37,7 @@ async def test_setup_entry(hass, ialarm_api, mock_config_entry): await hass.async_block_till_done() ialarm_api.return_value.get_mac.assert_called_once() - assert mock_config_entry.state == ENTRY_STATE_LOADED + assert mock_config_entry.state is ConfigEntryState.LOADED async def test_setup_not_ready(hass, ialarm_api, mock_config_entry): @@ -51,7 +47,7 @@ async def test_setup_not_ready(hass, ialarm_api, mock_config_entry): mock_config_entry.add_to_hass(hass) assert not await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() - assert mock_config_entry.state == ENTRY_STATE_SETUP_RETRY + assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass, ialarm_api, mock_config_entry): @@ -62,6 +58,6 @@ async def test_unload_entry(hass, ialarm_api, mock_config_entry): assert await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() - assert mock_config_entry.state == ENTRY_STATE_LOADED + assert mock_config_entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(mock_config_entry.entry_id) - assert mock_config_entry.state == ENTRY_STATE_NOT_LOADED + assert mock_config_entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/insteon/test_config_flow.py b/tests/components/insteon/test_config_flow.py index 796c9b69d59..172cb6936b3 100644 --- a/tests/components/insteon/test_config_flow.py +++ b/tests/components/insteon/test_config_flow.py @@ -110,7 +110,7 @@ async def test_fail_on_existing(hass: HomeAssistant): options={}, ) config_entry.add_to_hass(hass) - assert config_entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert config_entry.state is config_entries.ConfigEntryState.NOT_LOADED result = await hass.config_entries.flow.async_init( DOMAIN, @@ -276,7 +276,7 @@ async def test_import_existing(hass: HomeAssistant): options={}, ) config_entry.add_to_hass(hass) - assert config_entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert config_entry.state is config_entries.ConfigEntryState.NOT_LOADED result = await _import_config( hass, {**MOCK_IMPORT_MINIMUM_HUB_V2, CONF_PORT: 25105, CONF_HUB_VERSION: 2} diff --git a/tests/components/ipp/test_init.py b/tests/components/ipp/test_init.py index f06be4fc8b5..5caffc62d7b 100644 --- a/tests/components/ipp/test_init.py +++ b/tests/components/ipp/test_init.py @@ -1,10 +1,6 @@ """Tests for the IPP integration.""" from homeassistant.components.ipp.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.components.ipp import init_integration @@ -16,7 +12,7 @@ async def test_config_entry_not_ready( ) -> None: """Test the IPP configuration entry not ready.""" entry = await init_integration(hass, aioclient_mock, conn_error=True) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_config_entry( @@ -27,10 +23,10 @@ async def test_unload_config_entry( assert hass.data[DOMAIN] assert entry.entry_id in hass.data[DOMAIN] - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() assert entry.entry_id not in hass.data[DOMAIN] - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/islamic_prayer_times/test_init.py b/tests/components/islamic_prayer_times/test_init.py index 850edc4b76d..8ca16c50467 100644 --- a/tests/components/islamic_prayer_times/test_init.py +++ b/tests/components/islamic_prayer_times/test_init.py @@ -52,7 +52,7 @@ async def test_successful_config_entry(hass, legacy_patchable_time): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert entry.options == { islamic_prayer_times.CONF_CALC_METHOD: islamic_prayer_times.DEFAULT_CALC_METHOD } @@ -74,7 +74,7 @@ async def test_setup_failed(hass, legacy_patchable_time): ): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == config_entries.ENTRY_STATE_SETUP_RETRY + assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass, legacy_patchable_time): @@ -93,7 +93,7 @@ async def test_unload_entry(hass, legacy_patchable_time): assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert islamic_prayer_times.DOMAIN not in hass.data diff --git a/tests/components/kmtronic/test_config_flow.py b/tests/components/kmtronic/test_config_flow.py index 71482d6f7b2..b2f0f4b0515 100644 --- a/tests/components/kmtronic/test_config_flow.py +++ b/tests/components/kmtronic/test_config_flow.py @@ -5,7 +5,7 @@ from aiohttp import ClientConnectorError, ClientResponseError from homeassistant import config_entries, data_entry_flow, setup from homeassistant.components.kmtronic.const import CONF_REVERSE, DOMAIN -from homeassistant.config_entries import ENTRY_STATE_LOADED +from homeassistant.config_entries import ConfigEntryState from tests.common import MockConfigEntry @@ -65,7 +65,7 @@ async def test_form_options(hass, aioclient_mock): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED result = await hass.config_entries.options.async_init(config_entry.entry_id) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -80,7 +80,7 @@ async def test_form_options(hass, aioclient_mock): await hass.async_block_till_done() - assert config_entry.state == "loaded" + assert config_entry.state == config_entries.ConfigEntryState.LOADED async def test_form_invalid_auth(hass): diff --git a/tests/components/kmtronic/test_init.py b/tests/components/kmtronic/test_init.py index 1b9cf7cb407..da1efa25d58 100644 --- a/tests/components/kmtronic/test_init.py +++ b/tests/components/kmtronic/test_init.py @@ -2,11 +2,7 @@ import asyncio from homeassistant.components.kmtronic.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from tests.common import MockConfigEntry @@ -31,12 +27,12 @@ async def test_unload_config_entry(hass, aioclient_mock): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED async def test_config_entry_not_ready(hass, aioclient_mock): @@ -59,4 +55,4 @@ async def test_config_entry_not_ready(hass, aioclient_mock): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY diff --git a/tests/components/kodi/test_init.py b/tests/components/kodi/test_init.py index aa206270d35..6294eea45df 100644 --- a/tests/components/kodi/test_init.py +++ b/tests/components/kodi/test_init.py @@ -2,7 +2,7 @@ from unittest.mock import patch from homeassistant.components.kodi.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from . import init_integration @@ -16,10 +16,10 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) diff --git a/tests/components/litterrobot/test_init.py b/tests/components/litterrobot/test_init.py index 22a6ea21022..d8ca690d965 100644 --- a/tests/components/litterrobot/test_init.py +++ b/tests/components/litterrobot/test_init.py @@ -10,10 +10,7 @@ from homeassistant.components.vacuum import ( SERVICE_START, STATE_DOCKED, ) -from homeassistant.config_entries import ( - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ATTR_ENTITY_ID from .common import CONFIG, VACUUM_ENTITY_ID @@ -46,8 +43,8 @@ async def test_unload_entry(hass, mock_account): @pytest.mark.parametrize( "side_effect,expected_state", ( - (LitterRobotLoginException, ENTRY_STATE_SETUP_ERROR), - (LitterRobotException, ENTRY_STATE_SETUP_RETRY), + (LitterRobotLoginException, ConfigEntryState.SETUP_ERROR), + (LitterRobotException, ConfigEntryState.SETUP_RETRY), ), ) async def test_entry_not_setup(hass, side_effect, expected_state): @@ -63,4 +60,4 @@ async def test_entry_not_setup(hass, side_effect, expected_state): side_effect=side_effect, ): await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == expected_state + assert entry.state is expected_state diff --git a/tests/components/lyric/test_config_flow.py b/tests/components/lyric/test_config_flow.py index f5f41da08fd..c8197e9d678 100644 --- a/tests/components/lyric/test_config_flow.py +++ b/tests/components/lyric/test_config_flow.py @@ -109,7 +109,7 @@ async def test_full_flow( assert DOMAIN in hass.config.components entry = hass.config_entries.async_entries(DOMAIN)[0] - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(mock_setup.mock_calls) == 1 diff --git a/tests/components/mazda/test_init.py b/tests/components/mazda/test_init.py index c8c631b48af..c9370459f1c 100644 --- a/tests/components/mazda/test_init.py +++ b/tests/components/mazda/test_init.py @@ -6,12 +6,7 @@ from unittest.mock import patch from pymazda import MazdaAuthenticationException, MazdaException from homeassistant.components.mazda.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ( CONF_EMAIL, CONF_PASSWORD, @@ -44,7 +39,7 @@ async def test_config_entry_not_ready(hass: HomeAssistant) -> None: await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY async def test_init_auth_failure(hass: HomeAssistant): @@ -61,7 +56,7 @@ async def test_init_auth_failure(hass: HomeAssistant): entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_SETUP_ERROR + assert entries[0].state is ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 @@ -93,7 +88,7 @@ async def test_update_auth_failure(hass: HomeAssistant): entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_LOADED + assert entries[0].state is ConfigEntryState.LOADED with patch( "homeassistant.components.mazda.MazdaAPI.get_vehicles", @@ -132,7 +127,7 @@ async def test_update_general_failure(hass: HomeAssistant): entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_LOADED + assert entries[0].state is ConfigEntryState.LOADED with patch( "homeassistant.components.mazda.MazdaAPI.get_vehicles", @@ -153,11 +148,11 @@ async def test_unload_config_entry(hass: HomeAssistant) -> None: entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_LOADED + assert entries[0].state is ConfigEntryState.LOADED await hass.config_entries.async_unload(entries[0].entry_id) await hass.async_block_till_done() - assert entries[0].state == ENTRY_STATE_NOT_LOADED + assert entries[0].state is ConfigEntryState.NOT_LOADED async def test_device_nickname(hass): diff --git a/tests/components/met/test_init.py b/tests/components/met/test_init.py index 074293249c8..64323af56ce 100644 --- a/tests/components/met/test_init.py +++ b/tests/components/met/test_init.py @@ -5,11 +5,7 @@ from homeassistant.components.met.const import ( DOMAIN, ) from homeassistant.config import async_process_ha_core_config -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, -) +from homeassistant.config_entries import ConfigEntryState from . import init_integration @@ -19,12 +15,12 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) @@ -41,7 +37,7 @@ async def test_fail_default_home_entry(hass, caplog): entry = await init_integration(hass, track_home=True) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_SETUP_ERROR + assert entry.state is ConfigEntryState.SETUP_ERROR assert ( "Skip setting up met.no integration; No Home location has been set" diff --git a/tests/components/met_eireann/test_init.py b/tests/components/met_eireann/test_init.py index 8f95013cd72..c5d95ca14ca 100644 --- a/tests/components/met_eireann/test_init.py +++ b/tests/components/met_eireann/test_init.py @@ -1,6 +1,6 @@ """Test the Met Éireann integration init.""" from homeassistant.components.met_eireann.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from . import init_integration @@ -10,10 +10,10 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) diff --git a/tests/components/mikrotik/test_hub.py b/tests/components/mikrotik/test_hub.py index 27c53786519..859c7d20d04 100644 --- a/tests/components/mikrotik/test_hub.py +++ b/tests/components/mikrotik/test_hub.py @@ -86,7 +86,7 @@ async def test_hub_setup_failed(hass): await hass.config_entries.async_setup(config_entry.entry_id) - assert config_entry.state == config_entries.ENTRY_STATE_SETUP_RETRY + assert config_entry.state is config_entries.ConfigEntryState.SETUP_RETRY # error when username or password is invalid config_entry = MockConfigEntry(domain=mikrotik.DOMAIN, data=MOCK_DATA) diff --git a/tests/components/nam/test_init.py b/tests/components/nam/test_init.py index 01cf97fa6ab..943ea53f360 100644 --- a/tests/components/nam/test_init.py +++ b/tests/components/nam/test_init.py @@ -4,11 +4,7 @@ from unittest.mock import patch from nettigo_air_monitor import ApiError from homeassistant.components.nam.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE from tests.common import MockConfigEntry @@ -40,7 +36,7 @@ async def test_config_not_ready(hass): ): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass): @@ -48,10 +44,10 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) diff --git a/tests/components/neato/test_config_flow.py b/tests/components/neato/test_config_flow.py index 3650dae8a5c..3f07e4c4b0a 100644 --- a/tests/components/neato/test_config_flow.py +++ b/tests/components/neato/test_config_flow.py @@ -152,6 +152,6 @@ async def test_reauth( assert result3["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result3["reason"] == "reauth_successful" - assert new_entry.state == "loaded" + assert new_entry.state == config_entries.ConfigEntryState.LOADED assert len(hass.config_entries.async_entries(NEATO_DOMAIN)) == 1 assert len(mock_setup.mock_calls) == 1 diff --git a/tests/components/nest/test_init_sdm.py b/tests/components/nest/test_init_sdm.py index 27bc02e3ea8..db5e0c2fc33 100644 --- a/tests/components/nest/test_init_sdm.py +++ b/tests/components/nest/test_init_sdm.py @@ -11,12 +11,7 @@ from unittest.mock import patch from google_nest_sdm.exceptions import AuthException, GoogleNestException from homeassistant.components.nest import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.setup import async_setup_component from .common import CONFIG, async_setup_sdm_platform, create_config_entry @@ -32,7 +27,7 @@ async def test_setup_success(hass, caplog): entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_LOADED + assert entries[0].state is ConfigEntryState.LOADED async def async_setup_sdm(hass, config=CONFIG): @@ -54,7 +49,7 @@ async def test_setup_configuration_failure(hass, caplog): entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_SETUP_ERROR + assert entries[0].state is ConfigEntryState.SETUP_ERROR # This error comes from the python google-nest-sdm library, as a check added # to prevent common misconfigurations (e.g. confusing topic and subscriber) @@ -73,7 +68,7 @@ async def test_setup_susbcriber_failure(hass, caplog): entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_SETUP_RETRY + assert entries[0].state is ConfigEntryState.SETUP_RETRY async def test_setup_device_manager_failure(hass, caplog): @@ -89,7 +84,7 @@ async def test_setup_device_manager_failure(hass, caplog): entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_SETUP_RETRY + assert entries[0].state is ConfigEntryState.SETUP_RETRY async def test_subscriber_auth_failure(hass, caplog): @@ -103,7 +98,7 @@ async def test_subscriber_auth_failure(hass, caplog): entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_SETUP_ERROR + assert entries[0].state is ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 @@ -121,7 +116,7 @@ async def test_setup_missing_subscriber_id(hass, caplog): entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 - assert entries[0].state == ENTRY_STATE_NOT_LOADED + assert entries[0].state is ConfigEntryState.NOT_LOADED async def test_empty_config(hass, caplog): diff --git a/tests/components/netatmo/test_init.py b/tests/components/netatmo/test_init.py index b81c6f6ad16..fba85d9d45c 100644 --- a/tests/components/netatmo/test_init.py +++ b/tests/components/netatmo/test_init.py @@ -85,7 +85,7 @@ async def test_setup_component(hass): mock_impl.assert_called_once() mock_webhook.assert_called_once() - assert config_entry.state == config_entries.ENTRY_STATE_LOADED + assert config_entry.state is config_entries.ConfigEntryState.LOADED assert hass.config_entries.async_entries(DOMAIN) assert len(hass.states.async_all()) > 0 diff --git a/tests/components/nightscout/test_init.py b/tests/components/nightscout/test_init.py index 88ca141b999..04824139e20 100644 --- a/tests/components/nightscout/test_init.py +++ b/tests/components/nightscout/test_init.py @@ -4,11 +4,7 @@ from unittest.mock import patch from aiohttp import ClientError from homeassistant.components.nightscout.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_URL from tests.common import MockConfigEntry @@ -20,12 +16,12 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) @@ -42,4 +38,4 @@ async def test_async_setup_raises_entry_not_ready(hass): side_effect=ClientError(), ): await hass.config_entries.async_setup(config_entry.entry_id) - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY diff --git a/tests/components/nzbget/test_init.py b/tests/components/nzbget/test_init.py index 2dcdab5754e..e83672769da 100644 --- a/tests/components/nzbget/test_init.py +++ b/tests/components/nzbget/test_init.py @@ -4,11 +4,7 @@ from unittest.mock import patch from pynzbgetapi import NZBGetAPIException from homeassistant.components.nzbget.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT from homeassistant.setup import async_setup_component @@ -44,12 +40,12 @@ async def test_unload_entry(hass, nzbget_api): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) @@ -64,4 +60,4 @@ async def test_async_setup_raises_entry_not_ready(hass): ): await hass.config_entries.async_setup(config_entry.entry_id) - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY diff --git a/tests/components/onewire/test_init.py b/tests/components/onewire/test_init.py index c715adcc16b..01426e1faf1 100644 --- a/tests/components/onewire/test_init.py +++ b/tests/components/onewire/test_init.py @@ -5,12 +5,7 @@ from pyownet.protocol import ConnError, OwnetError from homeassistant.components.onewire.const import CONF_TYPE_OWSERVER, DOMAIN from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, - SOURCE_USER, -) +from homeassistant.config_entries import SOURCE_USER, ConfigEntryState from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component @@ -48,7 +43,7 @@ async def test_owserver_connect_failure(hass): await hass.async_block_till_done() assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert config_entry_owserver.state == ENTRY_STATE_SETUP_RETRY + assert config_entry_owserver.state is ConfigEntryState.SETUP_RETRY assert not hass.data.get(DOMAIN) @@ -81,15 +76,15 @@ async def test_unload_entry(hass): config_entry_sysbus = await setup_onewire_sysbus_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 2 - assert config_entry_owserver.state == ENTRY_STATE_LOADED - assert config_entry_sysbus.state == ENTRY_STATE_LOADED + assert config_entry_owserver.state is ConfigEntryState.LOADED + assert config_entry_sysbus.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(config_entry_owserver.entry_id) assert await hass.config_entries.async_unload(config_entry_sysbus.entry_id) await hass.async_block_till_done() - assert config_entry_owserver.state == ENTRY_STATE_NOT_LOADED - assert config_entry_sysbus.state == ENTRY_STATE_NOT_LOADED + assert config_entry_owserver.state is ConfigEntryState.NOT_LOADED + assert config_entry_sysbus.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) diff --git a/tests/components/openweathermap/test_config_flow.py b/tests/components/openweathermap/test_config_flow.py index daa38bc1dc7..ba1be4afb4c 100644 --- a/tests/components/openweathermap/test_config_flow.py +++ b/tests/components/openweathermap/test_config_flow.py @@ -10,7 +10,7 @@ from homeassistant.components.openweathermap.const import ( DEFAULT_LANGUAGE, DOMAIN, ) -from homeassistant.config_entries import SOURCE_USER +from homeassistant.config_entries import SOURCE_USER, ConfigEntryState from homeassistant.const import ( CONF_API_KEY, CONF_LATITUDE, @@ -57,11 +57,11 @@ async def test_form(hass): conf_entries = hass.config_entries.async_entries(DOMAIN) entry = conf_entries[0] - assert entry.state == "loaded" + assert entry.state == ConfigEntryState.LOADED await hass.config_entries.async_unload(conf_entries[0].entry_id) await hass.async_block_till_done() - assert entry.state == "not_loaded" + assert entry.state == ConfigEntryState.NOT_LOADED assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == CONFIG[CONF_NAME] @@ -86,7 +86,7 @@ async def test_form_options(hass): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == "loaded" + assert config_entry.state == ConfigEntryState.LOADED result = await hass.config_entries.options.async_init(config_entry.entry_id) @@ -105,7 +105,7 @@ async def test_form_options(hass): await hass.async_block_till_done() - assert config_entry.state == "loaded" + assert config_entry.state == ConfigEntryState.LOADED result = await hass.config_entries.options.async_init(config_entry.entry_id) @@ -124,7 +124,7 @@ async def test_form_options(hass): await hass.async_block_till_done() - assert config_entry.state == "loaded" + assert config_entry.state == ConfigEntryState.LOADED async def test_form_invalid_api_key(hass): diff --git a/tests/components/ozw/common.py b/tests/components/ozw/common.py index 2c1c81aea6d..450066c5aed 100644 --- a/tests/components/ozw/common.py +++ b/tests/components/ozw/common.py @@ -10,7 +10,9 @@ from tests.common import MockConfigEntry async def setup_ozw(hass, entry=None, fixture=None): """Set up OZW and load a dump.""" - mqtt_entry = MockConfigEntry(domain="mqtt", state=config_entries.ENTRY_STATE_LOADED) + mqtt_entry = MockConfigEntry( + domain="mqtt", state=config_entries.ConfigEntryState.LOADED + ) mqtt_entry.add_to_hass(hass) if entry is None: diff --git a/tests/components/ozw/conftest.py b/tests/components/ozw/conftest.py index 1df365054d4..d09259654de 100644 --- a/tests/components/ozw/conftest.py +++ b/tests/components/ozw/conftest.py @@ -4,7 +4,7 @@ from unittest.mock import patch import pytest -from homeassistant.config_entries import ENTRY_STATE_LOADED +from homeassistant.config_entries import ConfigEntryState from .common import MQTTMessage @@ -275,6 +275,6 @@ def mock_get_addon_discovery_info(): @pytest.fixture(name="mqtt") async def mock_mqtt_fixture(hass): """Mock the MQTT integration.""" - mqtt_entry = MockConfigEntry(domain="mqtt", state=ENTRY_STATE_LOADED) + mqtt_entry = MockConfigEntry(domain="mqtt", state=ConfigEntryState.LOADED) mqtt_entry.add_to_hass(hass) return mqtt_entry diff --git a/tests/components/ozw/test_init.py b/tests/components/ozw/test_init.py index e0232955997..9719c483800 100644 --- a/tests/components/ozw/test_init.py +++ b/tests/components/ozw/test_init.py @@ -65,16 +65,16 @@ async def test_unload_entry(hass, generic_data, switch_msg, caplog): title="Z-Wave", ) entry.add_to_hass(hass) - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED receive_message = await setup_ozw(hass, entry=entry, fixture=generic_data) - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert len(hass.states.async_entity_ids("switch")) == 1 await hass.config_entries.async_unload(entry.entry_id) - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED entities = hass.states.async_entity_ids("switch") assert len(entities) == 1 for entity in entities: @@ -98,7 +98,7 @@ async def test_unload_entry(hass, generic_data, switch_msg, caplog): await setup_ozw(hass, entry=entry, fixture=generic_data) await hass.async_block_till_done() - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert len(hass.states.async_entity_ids("switch")) == 1 for record in caplog.records: assert record.levelname != "ERROR" @@ -113,12 +113,12 @@ async def test_remove_entry(hass, stop_addon, uninstall_addon, caplog): data={"integration_created_addon": False}, ) entry.add_to_hass(hass) - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 1 await hass.config_entries.async_remove(entry.entry_id) - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 0 # test successful remove with created add-on @@ -134,7 +134,7 @@ async def test_remove_entry(hass, stop_addon, uninstall_addon, caplog): assert stop_addon.call_count == 1 assert uninstall_addon.call_count == 1 - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 0 stop_addon.reset_mock() uninstall_addon.reset_mock() @@ -148,7 +148,7 @@ async def test_remove_entry(hass, stop_addon, uninstall_addon, caplog): assert stop_addon.call_count == 1 assert uninstall_addon.call_count == 0 - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 0 assert "Failed to stop the OpenZWave add-on" in caplog.text stop_addon.side_effect = None @@ -164,7 +164,7 @@ async def test_remove_entry(hass, stop_addon, uninstall_addon, caplog): assert stop_addon.call_count == 1 assert uninstall_addon.call_count == 1 - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 0 assert "Failed to uninstall the OpenZWave add-on" in caplog.text @@ -210,7 +210,7 @@ async def test_setup_entry_without_addon_info(hass, get_addon_discovery_info): assert not await hass.config_entries.async_setup(entry.entry_id) assert mock_client.return_value.start_client.call_count == 0 - assert entry.state == config_entries.ENTRY_STATE_SETUP_RETRY + assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY async def test_unload_entry_with_addon( @@ -224,15 +224,15 @@ async def test_unload_entry_with_addon( ) entry.add_to_hass(hass) - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED with patch("homeassistant.components.ozw.MQTTClient", autospec=True) as mock_client: assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() assert mock_client.return_value.start_client.call_count == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED await hass.config_entries.async_unload(entry.entry_id) - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED diff --git a/tests/components/panasonic_viera/test_init.py b/tests/components/panasonic_viera/test_init.py index 7351b4e5544..0f30e315683 100644 --- a/tests/components/panasonic_viera/test_init.py +++ b/tests/components/panasonic_viera/test_init.py @@ -7,7 +7,7 @@ from homeassistant.components.panasonic_viera.const import ( DEFAULT_NAME, DOMAIN, ) -from homeassistant.config_entries import ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_HOST, STATE_UNAVAILABLE from homeassistant.setup import async_setup_component @@ -209,7 +209,7 @@ async def test_setup_unload_entry(hass, mock_remote): await hass.async_block_till_done() await hass.config_entries.async_unload(mock_entry.entry_id) - assert mock_entry.state == ENTRY_STATE_NOT_LOADED + assert mock_entry.state is ConfigEntryState.NOT_LOADED state_tv = hass.states.get("media_player.panasonic_viera_tv") state_remote = hass.states.get("remote.panasonic_viera_tv") diff --git a/tests/components/plex/test_config_flow.py b/tests/components/plex/test_config_flow.py index 05bf15b4729..716864c1cb1 100644 --- a/tests/components/plex/test_config_flow.py +++ b/tests/components/plex/test_config_flow.py @@ -23,10 +23,10 @@ from homeassistant.components.plex.const import ( SERVERS, ) from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, SOURCE_INTEGRATION_DISCOVERY, SOURCE_REAUTH, SOURCE_USER, + ConfigEntryState, ) from homeassistant.const import ( CONF_HOST, @@ -354,7 +354,7 @@ async def test_all_available_servers_configured( async def test_option_flow(hass, entry, mock_plex_server): """Test config options flow selection.""" assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED result = await hass.config_entries.options.async_init( entry.entry_id, context={"source": "test"}, data=None @@ -386,7 +386,7 @@ async def test_option_flow(hass, entry, mock_plex_server): async def test_missing_option_flow(hass, entry, mock_plex_server): """Test config options flow selection when no options stored.""" assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED result = await hass.config_entries.options.async_init( entry.entry_id, context={"source": "test"}, data=None @@ -676,7 +676,7 @@ async def test_setup_with_limited_credentials(hass, entry, setup_plex_server): assert plex_server.owner is None assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED async def test_integration_discovery(hass): @@ -707,7 +707,7 @@ async def test_trigger_reauth( """Test setup and reauthorization of a Plex token.""" await async_setup_component(hass, "persistent_notification", {}) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED with patch( "plexapi.server.PlexServer.clients", side_effect=plexapi.exceptions.Unauthorized @@ -716,7 +716,7 @@ async def test_trigger_reauth( await wait_for_debouncer(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state != ENTRY_STATE_LOADED + assert entry.state is not ConfigEntryState.LOADED flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 @@ -741,7 +741,7 @@ async def test_trigger_reauth( assert len(hass.config_entries.flow.async_progress()) == 0 assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert entry.data[CONF_SERVER] == mock_plex_server.friendly_name assert entry.data[CONF_SERVER_IDENTIFIER] == mock_plex_server.machine_identifier assert entry.data[PLEX_SERVER_CONFIG][CONF_URL] == PLEX_DIRECT_URL diff --git a/tests/components/plex/test_init.py b/tests/components/plex/test_init.py index dc46c2ca771..530f265f3f0 100644 --- a/tests/components/plex/test_init.py +++ b/tests/components/plex/test_init.py @@ -13,12 +13,7 @@ from homeassistant.components.plex.models import ( TRANSIENT_SECTION, UNKNOWN_SECTION, ) -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ( CONF_TOKEN, CONF_URL, @@ -38,7 +33,7 @@ from tests.common import MockConfigEntry, async_fire_time_changed async def test_set_config_entry_unique_id(hass, entry, mock_plex_server): """Test updating missing unique_id from config entry.""" assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert ( hass.config_entries.async_entries(const.DOMAIN)[0].unique_id @@ -57,7 +52,7 @@ async def test_setup_config_entry_with_error(hass, entry): await hass.async_block_till_done() assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY with patch( "homeassistant.components.plex.PlexServer.connect", @@ -68,7 +63,7 @@ async def test_setup_config_entry_with_error(hass, entry): await hass.async_block_till_done() assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_SETUP_ERROR + assert entry.state is ConfigEntryState.SETUP_ERROR async def test_setup_with_insecure_config_entry(hass, entry, setup_plex_server): @@ -80,7 +75,7 @@ async def test_setup_with_insecure_config_entry(hass, entry, setup_plex_server): await setup_plex_server(config_entry=entry) assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED async def test_unload_config_entry(hass, entry, mock_plex_server): @@ -88,7 +83,7 @@ async def test_unload_config_entry(hass, entry, mock_plex_server): config_entries = hass.config_entries.async_entries(const.DOMAIN) assert len(config_entries) == 1 assert entry is config_entries[0] - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED server_id = mock_plex_server.machine_identifier loaded_server = hass.data[const.DOMAIN][const.SERVERS][server_id] @@ -97,7 +92,7 @@ async def test_unload_config_entry(hass, entry, mock_plex_server): websocket = hass.data[const.DOMAIN][const.WEBSOCKETS][server_id] await hass.config_entries.async_unload(entry.entry_id) assert websocket.close.called - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED async def test_setup_with_photo_session(hass, entry, setup_plex_server): @@ -105,7 +100,7 @@ async def test_setup_with_photo_session(hass, entry, setup_plex_server): await setup_plex_server(session_type="photo") assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.async_block_till_done() media_player = hass.states.get( @@ -124,7 +119,7 @@ async def test_setup_with_live_tv_session(hass, entry, setup_plex_server): await setup_plex_server(session_type="live_tv") assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.async_block_till_done() media_player = hass.states.get( @@ -144,7 +139,7 @@ async def test_setup_with_transient_session(hass, entry, setup_plex_server): await setup_plex_server(session_type="transient") assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.async_block_till_done() media_player = hass.states.get( @@ -164,7 +159,7 @@ async def test_setup_with_unknown_session(hass, entry, setup_plex_server): await setup_plex_server(session_type="unknown") assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.async_block_till_done() media_player = hass.states.get( @@ -226,7 +221,7 @@ async def test_setup_when_certificate_changed( assert await hass.config_entries.async_setup(old_entry.entry_id) is False await hass.async_block_till_done() - assert old_entry.state == ENTRY_STATE_SETUP_ERROR + assert old_entry.state is ConfigEntryState.SETUP_ERROR await hass.config_entries.async_unload(old_entry.entry_id) # Test with no servers found @@ -236,7 +231,7 @@ async def test_setup_when_certificate_changed( assert await hass.config_entries.async_setup(old_entry.entry_id) is False await hass.async_block_till_done() - assert old_entry.state == ENTRY_STATE_SETUP_ERROR + assert old_entry.state is ConfigEntryState.SETUP_ERROR await hass.config_entries.async_unload(old_entry.entry_id) # Test with success @@ -249,7 +244,7 @@ async def test_setup_when_certificate_changed( await hass.async_block_till_done() assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1 - assert old_entry.state == ENTRY_STATE_LOADED + assert old_entry.state is ConfigEntryState.LOADED assert old_entry.data[const.PLEX_SERVER_CONFIG][CONF_URL] == new_url @@ -261,7 +256,7 @@ async def test_tokenless_server(entry, setup_plex_server): entry.data = TOKENLESS_DATA await setup_plex_server(config_entry=entry) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED async def test_bad_token_with_tokenless_server( @@ -272,7 +267,7 @@ async def test_bad_token_with_tokenless_server( await setup_plex_server() - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED # Ensure updates that rely on account return nothing trigger_plex_update(mock_websocket) diff --git a/tests/components/plugwise/test_binary_sensor.py b/tests/components/plugwise/test_binary_sensor.py index 6df5b90878a..5d802fb42a0 100644 --- a/tests/components/plugwise/test_binary_sensor.py +++ b/tests/components/plugwise/test_binary_sensor.py @@ -1,6 +1,6 @@ """Tests for the Plugwise binary_sensor integration.""" -from homeassistant.config_entries import ENTRY_STATE_LOADED +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_OFF, STATE_ON from tests.components.plugwise.common import async_init_integration @@ -9,7 +9,7 @@ from tests.components.plugwise.common import async_init_integration async def test_anna_climate_binary_sensor_entities(hass, mock_smile_anna): """Test creation of climate related binary_sensor entities.""" entry = await async_init_integration(hass, mock_smile_anna) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("binary_sensor.auxiliary_slave_boiler_state") assert str(state.state) == STATE_OFF @@ -21,7 +21,7 @@ async def test_anna_climate_binary_sensor_entities(hass, mock_smile_anna): async def test_anna_climate_binary_sensor_change(hass, mock_smile_anna): """Test change of climate related binary_sensor entities.""" entry = await async_init_integration(hass, mock_smile_anna) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED hass.states.async_set("binary_sensor.auxiliary_dhw_state", STATE_ON, {}) await hass.async_block_till_done() @@ -40,7 +40,7 @@ async def test_anna_climate_binary_sensor_change(hass, mock_smile_anna): async def test_adam_climate_binary_sensor_change(hass, mock_smile_adam): """Test change of climate related binary_sensor entities.""" entry = await async_init_integration(hass, mock_smile_adam) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("binary_sensor.adam_plugwise_notification") assert str(state.state) == STATE_ON diff --git a/tests/components/plugwise/test_climate.py b/tests/components/plugwise/test_climate.py index e85140660fd..2fed3d18fd2 100644 --- a/tests/components/plugwise/test_climate.py +++ b/tests/components/plugwise/test_climate.py @@ -3,7 +3,7 @@ from plugwise.exceptions import PlugwiseException from homeassistant.components.climate.const import HVAC_MODE_AUTO, HVAC_MODE_HEAT -from homeassistant.config_entries import ENTRY_STATE_LOADED +from homeassistant.config_entries import ConfigEntryState from tests.components.plugwise.common import async_init_integration @@ -11,7 +11,7 @@ from tests.components.plugwise.common import async_init_integration async def test_adam_climate_entity_attributes(hass, mock_smile_adam): """Test creation of adam climate device environment.""" entry = await async_init_integration(hass, mock_smile_adam) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("climate.zone_lisa_wk") attrs = state.attributes @@ -50,7 +50,7 @@ async def test_adam_climate_adjust_negative_testing(hass, mock_smile_adam): mock_smile_adam.set_schedule_state.side_effect = PlugwiseException mock_smile_adam.set_temperature.side_effect = PlugwiseException entry = await async_init_integration(hass, mock_smile_adam) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.services.async_call( "climate", @@ -85,7 +85,7 @@ async def test_adam_climate_adjust_negative_testing(hass, mock_smile_adam): async def test_adam_climate_entity_climate_changes(hass, mock_smile_adam): """Test handling of user requests in adam climate device environment.""" entry = await async_init_integration(hass, mock_smile_adam) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.services.async_call( "climate", @@ -138,7 +138,7 @@ async def test_adam_climate_entity_climate_changes(hass, mock_smile_adam): async def test_anna_climate_entity_attributes(hass, mock_smile_anna): """Test creation of anna climate device environment.""" entry = await async_init_integration(hass, mock_smile_anna) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("climate.anna") attrs = state.attributes @@ -163,7 +163,7 @@ async def test_anna_climate_entity_attributes(hass, mock_smile_anna): async def test_anna_climate_entity_climate_changes(hass, mock_smile_anna): """Test handling of user requests in anna climate device environment.""" entry = await async_init_integration(hass, mock_smile_anna) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.services.async_call( "climate", diff --git a/tests/components/plugwise/test_init.py b/tests/components/plugwise/test_init.py index eded1e55406..c4f7e1c6b3d 100644 --- a/tests/components/plugwise/test_init.py +++ b/tests/components/plugwise/test_init.py @@ -5,11 +5,7 @@ import asyncio from plugwise.exceptions import XMLDataMissingError from homeassistant.components.plugwise.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from tests.common import AsyncMock, MockConfigEntry from tests.components.plugwise.common import async_init_integration @@ -18,34 +14,34 @@ from tests.components.plugwise.common import async_init_integration async def test_smile_unauthorized(hass, mock_smile_unauth): """Test failing unauthorization by Smile.""" entry = await async_init_integration(hass, mock_smile_unauth) - assert entry.state == ENTRY_STATE_SETUP_ERROR + assert entry.state is ConfigEntryState.SETUP_ERROR async def test_smile_error(hass, mock_smile_error): """Test server error handling by Smile.""" entry = await async_init_integration(hass, mock_smile_error) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_smile_notconnect(hass, mock_smile_notconnect): """Connection failure error handling by Smile.""" mock_smile_notconnect.connect.return_value = False entry = await async_init_integration(hass, mock_smile_notconnect) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_smile_timeout(hass, mock_smile_notconnect): """Timeout error handling by Smile.""" mock_smile_notconnect.connect.side_effect = asyncio.TimeoutError entry = await async_init_integration(hass, mock_smile_notconnect) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_smile_adam_xmlerror(hass, mock_smile_adam): """Detect malformed XML by Smile in Adam environment.""" mock_smile_adam.full_update_device.side_effect = XMLDataMissingError entry = await async_init_integration(hass, mock_smile_adam) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass, mock_smile_adam): @@ -55,7 +51,7 @@ async def test_unload_entry(hass, mock_smile_adam): mock_smile_adam.async_reset = AsyncMock(return_value=True) await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data[DOMAIN] @@ -66,4 +62,4 @@ async def test_async_setup_entry_fail(hass): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_ERROR + assert entry.state is ConfigEntryState.SETUP_ERROR diff --git a/tests/components/plugwise/test_sensor.py b/tests/components/plugwise/test_sensor.py index a2bf4ebc50e..3b5bff781e5 100644 --- a/tests/components/plugwise/test_sensor.py +++ b/tests/components/plugwise/test_sensor.py @@ -1,6 +1,6 @@ """Tests for the Plugwise Sensor integration.""" -from homeassistant.config_entries import ENTRY_STATE_LOADED +from homeassistant.config_entries import ConfigEntryState from tests.common import Mock from tests.components.plugwise.common import async_init_integration @@ -9,7 +9,7 @@ from tests.components.plugwise.common import async_init_integration async def test_adam_climate_sensor_entities(hass, mock_smile_adam): """Test creation of climate related sensor entities.""" entry = await async_init_integration(hass, mock_smile_adam) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("sensor.adam_outdoor_temperature") assert float(state.state) == 7.81 @@ -34,7 +34,7 @@ async def test_adam_climate_sensor_entities(hass, mock_smile_adam): async def test_anna_as_smt_climate_sensor_entities(hass, mock_smile_anna): """Test creation of climate related sensor entities.""" entry = await async_init_integration(hass, mock_smile_anna) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("sensor.auxiliary_outdoor_temperature") assert float(state.state) == 18.0 @@ -50,7 +50,7 @@ async def test_anna_climate_sensor_entities(hass, mock_smile_anna): """Test creation of climate related sensor entities as single master thermostat.""" mock_smile_anna.single_master_thermostat.side_effect = Mock(return_value=False) entry = await async_init_integration(hass, mock_smile_anna) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("sensor.auxiliary_outdoor_temperature") assert float(state.state) == 18.0 @@ -59,7 +59,7 @@ async def test_anna_climate_sensor_entities(hass, mock_smile_anna): async def test_p1_dsmr_sensor_entities(hass, mock_smile_p1): """Test creation of power related sensor entities.""" entry = await async_init_integration(hass, mock_smile_p1) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("sensor.p1_net_electricity_point") assert float(state.state) == -2761.0 @@ -80,7 +80,7 @@ async def test_p1_dsmr_sensor_entities(hass, mock_smile_p1): async def test_stretch_sensor_entities(hass, mock_stretch): """Test creation of power related sensor entities.""" entry = await async_init_integration(hass, mock_stretch) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("sensor.koelkast_92c4a_electricity_consumed") assert float(state.state) == 50.5 diff --git a/tests/components/plugwise/test_switch.py b/tests/components/plugwise/test_switch.py index b7237a26150..6355362fbd9 100644 --- a/tests/components/plugwise/test_switch.py +++ b/tests/components/plugwise/test_switch.py @@ -2,7 +2,7 @@ from plugwise.exceptions import PlugwiseException -from homeassistant.config_entries import ENTRY_STATE_LOADED +from homeassistant.config_entries import ConfigEntryState from tests.components.plugwise.common import async_init_integration @@ -10,7 +10,7 @@ from tests.components.plugwise.common import async_init_integration async def test_adam_climate_switch_entities(hass, mock_smile_adam): """Test creation of climate related switch entities.""" entry = await async_init_integration(hass, mock_smile_adam) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("switch.cv_pomp") assert str(state.state) == "on" @@ -23,7 +23,7 @@ async def test_adam_climate_switch_negative_testing(hass, mock_smile_adam): """Test exceptions of climate related switch entities.""" mock_smile_adam.set_relay_state.side_effect = PlugwiseException entry = await async_init_integration(hass, mock_smile_adam) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.services.async_call( "switch", @@ -47,7 +47,7 @@ async def test_adam_climate_switch_negative_testing(hass, mock_smile_adam): async def test_adam_climate_switch_changes(hass, mock_smile_adam): """Test changing of climate related switch entities.""" entry = await async_init_integration(hass, mock_smile_adam) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.services.async_call( "switch", @@ -80,7 +80,7 @@ async def test_adam_climate_switch_changes(hass, mock_smile_adam): async def test_stretch_switch_entities(hass, mock_stretch): """Test creation of climate related switch entities.""" entry = await async_init_integration(hass, mock_stretch) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED state = hass.states.get("switch.koelkast_92c4a") assert str(state.state) == "on" @@ -92,7 +92,7 @@ async def test_stretch_switch_entities(hass, mock_stretch): async def test_stretch_switch_changes(hass, mock_stretch): """Test changing of power related switch entities.""" entry = await async_init_integration(hass, mock_stretch) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.services.async_call( "switch", diff --git a/tests/components/rfxtrx/test_switch.py b/tests/components/rfxtrx/test_switch.py index ee4fd265fc9..12064911bb6 100644 --- a/tests/components/rfxtrx/test_switch.py +++ b/tests/components/rfxtrx/test_switch.py @@ -3,6 +3,7 @@ from unittest.mock import call import pytest +from homeassistant import config_entries from homeassistant.components.rfxtrx import DOMAIN from homeassistant.core import State @@ -168,4 +169,4 @@ async def test_unknown_event_code(hass, rfxtrx): assert len(conf_entries) == 1 entry = conf_entries[0] - assert entry.state == "loaded" + assert entry.state == config_entries.ConfigEntryState.LOADED diff --git a/tests/components/roku/test_init.py b/tests/components/roku/test_init.py index be9131d5f91..fc624f5cb64 100644 --- a/tests/components/roku/test_init.py +++ b/tests/components/roku/test_init.py @@ -2,11 +2,7 @@ from unittest.mock import patch from homeassistant.components.roku.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.components.roku import setup_integration @@ -19,7 +15,7 @@ async def test_config_entry_not_ready( """Test the Roku configuration entry not ready.""" entry = await setup_integration(hass, aioclient_mock, error=True) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_config_entry( @@ -36,10 +32,10 @@ async def test_unload_config_entry( entry = await setup_integration(hass, aioclient_mock) assert hass.data[DOMAIN][entry.entry_id] - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() assert entry.entry_id not in hass.data[DOMAIN] - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/ruckus_unleashed/test_init.py b/tests/components/ruckus_unleashed/test_init.py index 0340f72891a..e9ac9ec7cd8 100644 --- a/tests/components/ruckus_unleashed/test_init.py +++ b/tests/components/ruckus_unleashed/test_init.py @@ -14,11 +14,7 @@ from homeassistant.components.ruckus_unleashed import ( DOMAIN, MANUFACTURER, ) -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.helpers import device_registry as dr from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC @@ -56,7 +52,7 @@ async def test_setup_entry_connection_error(hass): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_router_device_setup(hass): @@ -84,12 +80,12 @@ async def test_unload_entry(hass): entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.data.get(DOMAIN) @@ -113,4 +109,4 @@ async def test_config_not_ready_during_setup(hass): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY diff --git a/tests/components/smart_meter_texas/test_init.py b/tests/components/smart_meter_texas/test_init.py index 7db4113e3cf..0c49e6285ae 100644 --- a/tests/components/smart_meter_texas/test_init.py +++ b/tests/components/smart_meter_texas/test_init.py @@ -6,12 +6,7 @@ from homeassistant.components.homeassistant import ( SERVICE_UPDATE_ENTITY, ) from homeassistant.components.smart_meter_texas.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ATTR_ENTITY_ID from homeassistant.setup import async_setup_component @@ -31,14 +26,14 @@ async def test_auth_failure(hass, config_entry, aioclient_mock): """Test if user's username or password is not accepted.""" await setup_integration(hass, config_entry, aioclient_mock, auth_fail=True) - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR async def test_api_timeout(hass, config_entry, aioclient_mock): """Test that a timeout results in ConfigEntryNotReady.""" await setup_integration(hass, config_entry, aioclient_mock, auth_timeout=True) - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY async def test_update_failure(hass, config_entry, aioclient_mock): @@ -64,9 +59,9 @@ async def test_unload_config_entry(hass, config_entry, aioclient_mock): config_entries = hass.config_entries.async_entries(DOMAIN) assert len(config_entries) == 1 assert config_entries[0] is config_entry - assert config_entry.state == ENTRY_STATE_LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/smarttub/test_init.py b/tests/components/smarttub/test_init.py index df44edb3da3..f316a66c5d1 100644 --- a/tests/components/smarttub/test_init.py +++ b/tests/components/smarttub/test_init.py @@ -7,11 +7,7 @@ from smarttub import LoginFailed from homeassistant.components import smarttub from homeassistant.components.smarttub.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, - SOURCE_REAUTH, -) +from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState from homeassistant.setup import async_setup_component @@ -30,7 +26,7 @@ async def test_setup_entry_not_ready(setup_component, hass, config_entry, smartt config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY async def test_setup_auth_failed(setup_component, hass, config_entry, smarttub_api): @@ -40,7 +36,7 @@ async def test_setup_auth_failed(setup_component, hass, config_entry, smarttub_a config_entry.add_to_hass(hass) with patch.object(hass.config_entries.flow, "async_init") as mock_flow_init: await hass.config_entries.async_setup(config_entry.entry_id) - assert config_entry.state == ENTRY_STATE_SETUP_ERROR + assert config_entry.state is ConfigEntryState.SETUP_ERROR mock_flow_init.assert_called_with( DOMAIN, context={ diff --git a/tests/components/somfy/test_config_flow.py b/tests/components/somfy/test_config_flow.py index 4e969358b2a..b7d78883706 100644 --- a/tests/components/somfy/test_config_flow.py +++ b/tests/components/somfy/test_config_flow.py @@ -97,10 +97,10 @@ async def test_full_flow( assert DOMAIN in hass.config.components entry = hass.config_entries.async_entries(DOMAIN)[0] - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert await hass.config_entries.async_unload(entry.entry_id) - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED async def test_abort_if_authorization_timeout(hass, current_request_with_host): diff --git a/tests/components/sonarr/test_init.py b/tests/components/sonarr/test_init.py index 0e9c253f1b8..6dfce4ee2fe 100644 --- a/tests/components/sonarr/test_init.py +++ b/tests/components/sonarr/test_init.py @@ -2,13 +2,7 @@ from unittest.mock import patch from homeassistant.components.sonarr.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, - SOURCE_REAUTH, -) +from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState from homeassistant.const import CONF_SOURCE from homeassistant.core import HomeAssistant @@ -21,7 +15,7 @@ async def test_config_entry_not_ready( ) -> None: """Test the configuration entry not ready.""" entry = await setup_integration(hass, aioclient_mock, connection_error=True) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_config_entry_reauth( @@ -31,7 +25,7 @@ async def test_config_entry_reauth( with patch.object(hass.config_entries.flow, "async_init") as mock_flow_init: entry = await setup_integration(hass, aioclient_mock, invalid_auth=True) - assert entry.state == ENTRY_STATE_SETUP_ERROR + assert entry.state is ConfigEntryState.SETUP_ERROR mock_flow_init.assert_called_once_with( DOMAIN, @@ -56,10 +50,10 @@ async def test_unload_config_entry( assert hass.data[DOMAIN] assert entry.entry_id in hass.data[DOMAIN] - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() assert entry.entry_id not in hass.data[DOMAIN] - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/speedtestdotnet/test_init.py b/tests/components/speedtestdotnet/test_init.py index 72bcb743a8d..30d3d2a1d63 100644 --- a/tests/components/speedtestdotnet/test_init.py +++ b/tests/components/speedtestdotnet/test_init.py @@ -38,7 +38,7 @@ async def test_successful_config_entry(hass): ) as forward_entry_setup: await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert forward_entry_setup.mock_calls[0][1] == ( entry, "sensor", @@ -58,7 +58,7 @@ async def test_setup_failed(hass): await hass.config_entries.async_setup(entry.entry_id) - assert entry.state == config_entries.ENTRY_STATE_SETUP_RETRY + assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass): @@ -75,5 +75,5 @@ async def test_unload_entry(hass): assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert speedtestdotnet.DOMAIN not in hass.data diff --git a/tests/components/srp_energy/test_init.py b/tests/components/srp_energy/test_init.py index 8e758d05114..8c8d87674fe 100644 --- a/tests/components/srp_energy/test_init.py +++ b/tests/components/srp_energy/test_init.py @@ -1,4 +1,5 @@ """Tests for Srp Energy component Init.""" +from homeassistant import config_entries from homeassistant.components import srp_energy from tests.components.srp_energy import init_integration @@ -7,7 +8,7 @@ from tests.components.srp_energy import init_integration async def test_setup_entry(hass): """Test setup entry fails if deCONZ is not available.""" config_entry = await init_integration(hass) - assert config_entry.state == "loaded" + assert config_entry.state == config_entries.ConfigEntryState.LOADED assert hass.data[srp_energy.SRP_ENERGY_DOMAIN] diff --git a/tests/components/subaru/conftest.py b/tests/components/subaru/conftest.py index 1b8d1439e68..1ca7926cea2 100644 --- a/tests/components/subaru/conftest.py +++ b/tests/components/subaru/conftest.py @@ -18,7 +18,7 @@ from homeassistant.components.subaru.const import ( VEHICLE_HAS_SAFETY_SERVICE, VEHICLE_NAME, ) -from homeassistant.config_entries import ENTRY_STATE_LOADED +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_DEVICE_ID, CONF_PASSWORD, CONF_PIN, CONF_USERNAME from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -144,5 +144,5 @@ async def ev_entry(hass): assert DOMAIN in hass.config_entries.async_domains() assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert hass.config_entries.async_get_entry(entry.entry_id) - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED return entry diff --git a/tests/components/subaru/test_init.py b/tests/components/subaru/test_init.py index 13b510e8c40..cd87ed40315 100644 --- a/tests/components/subaru/test_init.py +++ b/tests/components/subaru/test_init.py @@ -8,12 +8,7 @@ from homeassistant.components.homeassistant import ( SERVICE_UPDATE_ENTITY, ) from homeassistant.components.subaru.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_ERROR, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ATTR_ENTITY_ID from homeassistant.setup import async_setup_component @@ -44,7 +39,7 @@ async def test_setup_ev(hass, ev_entry): """Test setup with an EV vehicle.""" check_entry = hass.config_entries.async_get_entry(ev_entry.entry_id) assert check_entry - assert check_entry.state == ENTRY_STATE_LOADED + assert check_entry.state is ConfigEntryState.LOADED async def test_setup_g2(hass): @@ -57,7 +52,7 @@ async def test_setup_g2(hass): ) check_entry = hass.config_entries.async_get_entry(entry.entry_id) assert check_entry - assert check_entry.state == ENTRY_STATE_LOADED + assert check_entry.state is ConfigEntryState.LOADED async def test_setup_g1(hass): @@ -67,7 +62,7 @@ async def test_setup_g1(hass): ) check_entry = hass.config_entries.async_get_entry(entry.entry_id) assert check_entry - assert check_entry.state == ENTRY_STATE_LOADED + assert check_entry.state is ConfigEntryState.LOADED async def test_unsuccessful_connect(hass): @@ -81,7 +76,7 @@ async def test_unsuccessful_connect(hass): ) check_entry = hass.config_entries.async_get_entry(entry.entry_id) assert check_entry - assert check_entry.state == ENTRY_STATE_SETUP_RETRY + assert check_entry.state is ConfigEntryState.SETUP_RETRY async def test_invalid_credentials(hass): @@ -95,7 +90,7 @@ async def test_invalid_credentials(hass): ) check_entry = hass.config_entries.async_get_entry(entry.entry_id) assert check_entry - assert check_entry.state == ENTRY_STATE_SETUP_ERROR + assert check_entry.state is ConfigEntryState.SETUP_ERROR async def test_update_skip_unsubscribed(hass): @@ -147,7 +142,7 @@ async def test_fetch_failed(hass): async def test_unload_entry(hass, ev_entry): """Test that entry is unloaded.""" - assert ev_entry.state == ENTRY_STATE_LOADED + assert ev_entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(ev_entry.entry_id) await hass.async_block_till_done() - assert ev_entry.state == ENTRY_STATE_NOT_LOADED + assert ev_entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/totalconnect/test_init.py b/tests/components/totalconnect/test_init.py index b8024dbe70d..ba33d996a9b 100644 --- a/tests/components/totalconnect/test_init.py +++ b/tests/components/totalconnect/test_init.py @@ -2,7 +2,7 @@ from unittest.mock import patch from homeassistant.components.totalconnect.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_SETUP_ERROR +from homeassistant.config_entries import ConfigEntryState from homeassistant.setup import async_setup_component from .common import CONFIG_DATA @@ -26,4 +26,4 @@ async def test_reauth_started(hass): assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() - assert mock_entry.state == ENTRY_STATE_SETUP_ERROR + assert mock_entry.state is ConfigEntryState.SETUP_ERROR diff --git a/tests/components/vera/test_init.py b/tests/components/vera/test_init.py index c828ef55fcd..2008912bae2 100644 --- a/tests/components/vera/test_init.py +++ b/tests/components/vera/test_init.py @@ -11,7 +11,7 @@ from homeassistant.components.vera import ( CONF_LIGHTS, DOMAIN, ) -from homeassistant.config_entries import ENTRY_STATE_NOT_LOADED +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er @@ -148,7 +148,7 @@ async def test_unload( for config_entry in entries: assert await hass.config_entries.async_unload(config_entry.entry_id) - assert config_entry.state == ENTRY_STATE_NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED async def test_async_setup_entry_error( diff --git a/tests/components/volumio/test_config_flow.py b/tests/components/volumio/test_config_flow.py index fed967f9ffc..b4b3c8f24ed 100644 --- a/tests/components/volumio/test_config_flow.py +++ b/tests/components/volumio/test_config_flow.py @@ -242,7 +242,7 @@ async def test_discovery_updates_unique_id(hass): "name": "dummy", "id": TEST_DISCOVERY_RESULT["id"], }, - state=config_entries.ENTRY_STATE_SETUP_RETRY, + state=config_entries.ConfigEntryState.SETUP_RETRY, ) entry.add_to_hass(hass) diff --git a/tests/components/wilight/test_init.py b/tests/components/wilight/test_init.py index 4f6654d3436..24efdaaa8e1 100644 --- a/tests/components/wilight/test_init.py +++ b/tests/components/wilight/test_init.py @@ -5,11 +5,7 @@ import pytest import pywilight from pywilight.const import DOMAIN -from homeassistant.config_entries import ( - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.components.wilight import ( @@ -47,7 +43,7 @@ async def test_config_entry_not_ready(hass: HomeAssistant) -> None: """Test the WiLight configuration entry not ready.""" entry = await setup_integration(hass) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_config_entry(hass: HomeAssistant, dummy_device_from_host) -> None: @@ -55,11 +51,11 @@ async def test_unload_config_entry(hass: HomeAssistant, dummy_device_from_host) entry = await setup_integration(hass) assert entry.entry_id in hass.data[DOMAIN] - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() if DOMAIN in hass.data: assert entry.entry_id not in hass.data[DOMAIN] - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED diff --git a/tests/components/wled/test_init.py b/tests/components/wled/test_init.py index edce49cfd80..8db7e266e80 100644 --- a/tests/components/wled/test_init.py +++ b/tests/components/wled/test_init.py @@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patch from wled import WLEDConnectionError from homeassistant.components.wled.const import DOMAIN -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.components.wled import init_integration @@ -17,7 +17,7 @@ async def test_config_entry_not_ready( ) -> None: """Test the WLED configuration entry not ready.""" entry = await init_integration(hass, aioclient_mock) - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_config_entry( diff --git a/tests/components/yeelight/test_init.py b/tests/components/yeelight/test_init.py index 3c25852810d..8a37c2b283e 100644 --- a/tests/components/yeelight/test_init.py +++ b/tests/components/yeelight/test_init.py @@ -11,7 +11,7 @@ from homeassistant.components.yeelight import ( DOMAIN, NIGHTLIGHT_SWITCH_TYPE_LIGHT, ) -from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ( CONF_DEVICES, CONF_HOST, @@ -110,7 +110,7 @@ async def test_ip_changes_id_missing_cannot_fallback(hass: HomeAssistant): assert not await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ENTRY_STATE_SETUP_RETRY + assert config_entry.state is ConfigEntryState.SETUP_RETRY async def test_setup_discovery(hass: HomeAssistant): diff --git a/tests/components/zwave_js/test_init.py b/tests/components/zwave_js/test_init.py index 80b37301383..c4f35941a25 100644 --- a/tests/components/zwave_js/test_init.py +++ b/tests/components/zwave_js/test_init.py @@ -9,12 +9,7 @@ from zwave_js_server.model.node import Node from homeassistant.components.hassio.handler import HassioAPIError from homeassistant.components.zwave_js.const import DOMAIN from homeassistant.components.zwave_js.helpers import get_device_id -from homeassistant.config_entries import ( - DISABLED_USER, - ENTRY_STATE_LOADED, - ENTRY_STATE_NOT_LOADED, - ENTRY_STATE_SETUP_RETRY, -) +from homeassistant.config_entries import DISABLED_USER, ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE from homeassistant.helpers import device_registry as dr, entity_registry as er @@ -39,12 +34,12 @@ async def test_entry_setup_unload(hass, client, integration): entry = integration assert client.connect.call_count == 1 - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.config_entries.async_unload(entry.entry_id) assert client.disconnect.call_count == 1 - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED async def test_home_assistant_stop(hass, client, integration): @@ -62,7 +57,7 @@ async def test_initialized_timeout(hass, client, connect_timeout): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_enabled_statistics(hass, client): @@ -130,7 +125,7 @@ async def test_listen_failure(hass, client, error): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY async def test_on_node_added_ready( @@ -590,7 +585,7 @@ async def test_start_addon( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY assert install_addon.call_count == 0 assert set_addon_options.call_count == 1 assert set_addon_options.call_args == call( @@ -621,7 +616,7 @@ async def test_install_addon( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY assert install_addon.call_count == 1 assert install_addon.call_args == call(hass, "core_zwave_js") assert set_addon_options.call_count == 1 @@ -654,7 +649,7 @@ async def test_addon_info_failure( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY assert install_addon.call_count == 0 assert start_addon.call_count == 0 @@ -708,7 +703,7 @@ async def test_update_addon( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_SETUP_RETRY + assert entry.state is ConfigEntryState.SETUP_RETRY assert create_shapshot.call_count == snapshot_calls assert update_addon.call_count == update_calls @@ -716,8 +711,8 @@ async def test_update_addon( @pytest.mark.parametrize( "stop_addon_side_effect, entry_state", [ - (None, ENTRY_STATE_NOT_LOADED), - (HassioAPIError("Boom"), ENTRY_STATE_LOADED), + (None, ConfigEntryState.NOT_LOADED), + (HassioAPIError("Boom"), ConfigEntryState.LOADED), ], ) async def test_stop_addon( @@ -749,7 +744,7 @@ async def test_stop_addon( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state == ENTRY_STATE_LOADED + assert entry.state is ConfigEntryState.LOADED await hass.config_entries.async_set_disabled_by(entry.entry_id, DISABLED_USER) await hass.async_block_till_done() @@ -770,12 +765,12 @@ async def test_remove_entry( data={"integration_created_addon": False}, ) entry.add_to_hass(hass) - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 1 await hass.config_entries.async_remove(entry.entry_id) - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 0 # test successful remove with created add-on @@ -799,7 +794,7 @@ async def test_remove_entry( ) assert uninstall_addon.call_count == 1 assert uninstall_addon.call_args == call(hass, "core_zwave_js") - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 0 stop_addon.reset_mock() create_shapshot.reset_mock() @@ -816,7 +811,7 @@ async def test_remove_entry( assert stop_addon.call_args == call(hass, "core_zwave_js") assert create_shapshot.call_count == 0 assert uninstall_addon.call_count == 0 - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 0 assert "Failed to stop the Z-Wave JS add-on" in caplog.text stop_addon.side_effect = None @@ -840,7 +835,7 @@ async def test_remove_entry( partial=True, ) assert uninstall_addon.call_count == 0 - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 0 assert "Failed to create a snapshot of the Z-Wave JS add-on" in caplog.text create_shapshot.side_effect = None @@ -865,7 +860,7 @@ async def test_remove_entry( ) assert uninstall_addon.call_count == 1 assert uninstall_addon.call_args == call(hass, "core_zwave_js") - assert entry.state == ENTRY_STATE_NOT_LOADED + assert entry.state is ConfigEntryState.NOT_LOADED assert len(hass.config_entries.async_entries(DOMAIN)) == 0 assert "Failed to uninstall the Z-Wave JS add-on" in caplog.text diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 77f4fdd0361..042bec418ac 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -86,7 +86,7 @@ async def test_call_setup_entry(hass): assert result assert len(mock_migrate_entry.mock_calls) == 0 assert len(mock_setup_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert entry.supports_unload @@ -115,7 +115,7 @@ async def test_call_setup_entry_without_reload_support(hass): assert result assert len(mock_migrate_entry.mock_calls) == 0 assert len(mock_setup_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert not entry.supports_unload @@ -145,7 +145,7 @@ async def test_call_async_migrate_entry(hass): assert result assert len(mock_migrate_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert entry.supports_unload @@ -173,7 +173,7 @@ async def test_call_async_migrate_entry_failure_false(hass): assert result assert len(mock_migrate_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 0 - assert entry.state == config_entries.ENTRY_STATE_MIGRATION_ERROR + assert entry.state is config_entries.ConfigEntryState.MIGRATION_ERROR assert not entry.supports_unload @@ -201,7 +201,7 @@ async def test_call_async_migrate_entry_failure_exception(hass): assert result assert len(mock_migrate_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 0 - assert entry.state == config_entries.ENTRY_STATE_MIGRATION_ERROR + assert entry.state is config_entries.ConfigEntryState.MIGRATION_ERROR assert not entry.supports_unload @@ -229,7 +229,7 @@ async def test_call_async_migrate_entry_failure_not_bool(hass): assert result assert len(mock_migrate_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 0 - assert entry.state == config_entries.ENTRY_STATE_MIGRATION_ERROR + assert entry.state is config_entries.ConfigEntryState.MIGRATION_ERROR assert not entry.supports_unload @@ -248,7 +248,7 @@ async def test_call_async_migrate_entry_failure_not_supported(hass): result = await async_setup_component(hass, "comp", {}) assert result assert len(mock_setup_entry.mock_calls) == 0 - assert entry.state == config_entries.ENTRY_STATE_MIGRATION_ERROR + assert entry.state is config_entries.ConfigEntryState.MIGRATION_ERROR assert not entry.supports_unload @@ -380,7 +380,7 @@ async def test_remove_entry_raises(hass, manager): MockConfigEntry(domain="test", entry_id="test1").add_to_manager(manager) MockConfigEntry( - domain="comp", entry_id="test2", state=config_entries.ENTRY_STATE_LOADED + domain="comp", entry_id="test2", state=config_entries.ConfigEntryState.LOADED ).add_to_manager(manager) MockConfigEntry(domain="test", entry_id="test3").add_to_manager(manager) @@ -796,7 +796,7 @@ async def test_updating_entry_data(manager): entry = MockConfigEntry( domain="test", data={"first": True}, - state=config_entries.ENTRY_STATE_SETUP_ERROR, + state=config_entries.ConfigEntryState.SETUP_ERROR, ) entry.add_to_manager(manager) @@ -812,7 +812,7 @@ async def test_updating_entry_system_options(manager): entry = MockConfigEntry( domain="test", data={"first": True}, - state=config_entries.ENTRY_STATE_SETUP_ERROR, + state=config_entries.ConfigEntryState.SETUP_ERROR, system_options={"disable_new_entities": True}, ) entry.add_to_manager(manager) @@ -861,14 +861,14 @@ async def test_setup_raise_not_ready(hass, caplog): assert p_hass is hass assert p_wait_time == 5 - assert entry.state == config_entries.ENTRY_STATE_SETUP_RETRY + assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY assert entry.reason == "The internet connection is offline" mock_setup_entry.side_effect = None mock_setup_entry.return_value = True await p_setup(None) - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert entry.reason is None @@ -905,12 +905,12 @@ async def test_setup_retrying_during_unload(hass): with patch("homeassistant.helpers.event.async_call_later") as mock_call: await entry.async_setup(hass) - assert entry.state == config_entries.ENTRY_STATE_SETUP_RETRY + assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY assert len(mock_call.return_value.mock_calls) == 0 await entry.async_unload(hass) - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert len(mock_call.return_value.mock_calls) == 1 @@ -927,7 +927,7 @@ async def test_setup_retrying_during_unload_before_started(hass): await entry.async_setup(hass) await hass.async_block_till_done() - assert entry.state == config_entries.ENTRY_STATE_SETUP_RETRY + assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY assert ( hass.bus.async_listeners()[EVENT_HOMEASSISTANT_STARTED] == initial_listeners + 1 ) @@ -935,7 +935,7 @@ async def test_setup_retrying_during_unload_before_started(hass): await entry.async_unload(hass) await hass.async_block_till_done() - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED assert ( hass.bus.async_listeners()[EVENT_HOMEASSISTANT_STARTED] == initial_listeners + 0 ) @@ -1057,7 +1057,9 @@ async def test_entry_options_abort(hass, manager): async def test_entry_setup_succeed(hass, manager): """Test that we can setup an entry.""" - entry = MockConfigEntry(domain="comp", state=config_entries.ENTRY_STATE_NOT_LOADED) + entry = MockConfigEntry( + domain="comp", state=config_entries.ConfigEntryState.NOT_LOADED + ) entry.add_to_hass(hass) mock_setup = AsyncMock(return_value=True) @@ -1072,17 +1074,17 @@ async def test_entry_setup_succeed(hass, manager): assert await manager.async_setup(entry.entry_id) assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED @pytest.mark.parametrize( "state", ( - config_entries.ENTRY_STATE_LOADED, - config_entries.ENTRY_STATE_SETUP_ERROR, - config_entries.ENTRY_STATE_MIGRATION_ERROR, - config_entries.ENTRY_STATE_SETUP_RETRY, - config_entries.ENTRY_STATE_FAILED_UNLOAD, + config_entries.ConfigEntryState.LOADED, + config_entries.ConfigEntryState.SETUP_ERROR, + config_entries.ConfigEntryState.MIGRATION_ERROR, + config_entries.ConfigEntryState.SETUP_RETRY, + config_entries.ConfigEntryState.FAILED_UNLOAD, ), ) async def test_entry_setup_invalid_state(hass, manager, state): @@ -1103,12 +1105,12 @@ async def test_entry_setup_invalid_state(hass, manager, state): assert len(mock_setup.mock_calls) == 0 assert len(mock_setup_entry.mock_calls) == 0 - assert entry.state == state + assert entry.state is state async def test_entry_unload_succeed(hass, manager): """Test that we can unload an entry.""" - entry = MockConfigEntry(domain="comp", state=config_entries.ENTRY_STATE_LOADED) + entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) entry.add_to_hass(hass) async_unload_entry = AsyncMock(return_value=True) @@ -1117,15 +1119,15 @@ async def test_entry_unload_succeed(hass, manager): assert await manager.async_unload(entry.entry_id) assert len(async_unload_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED @pytest.mark.parametrize( "state", ( - config_entries.ENTRY_STATE_NOT_LOADED, - config_entries.ENTRY_STATE_SETUP_ERROR, - config_entries.ENTRY_STATE_SETUP_RETRY, + config_entries.ConfigEntryState.NOT_LOADED, + config_entries.ConfigEntryState.SETUP_ERROR, + config_entries.ConfigEntryState.SETUP_RETRY, ), ) async def test_entry_unload_failed_to_load(hass, manager, state): @@ -1139,14 +1141,14 @@ async def test_entry_unload_failed_to_load(hass, manager, state): assert await manager.async_unload(entry.entry_id) assert len(async_unload_entry.mock_calls) == 0 - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED @pytest.mark.parametrize( "state", ( - config_entries.ENTRY_STATE_MIGRATION_ERROR, - config_entries.ENTRY_STATE_FAILED_UNLOAD, + config_entries.ConfigEntryState.MIGRATION_ERROR, + config_entries.ConfigEntryState.FAILED_UNLOAD, ), ) async def test_entry_unload_invalid_state(hass, manager, state): @@ -1162,12 +1164,12 @@ async def test_entry_unload_invalid_state(hass, manager, state): assert await manager.async_unload(entry.entry_id) assert len(async_unload_entry.mock_calls) == 0 - assert entry.state == state + assert entry.state is state async def test_entry_reload_succeed(hass, manager): """Test that we can reload an entry.""" - entry = MockConfigEntry(domain="comp", state=config_entries.ENTRY_STATE_LOADED) + entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) entry.add_to_hass(hass) async_setup = AsyncMock(return_value=True) @@ -1189,15 +1191,15 @@ async def test_entry_reload_succeed(hass, manager): assert len(async_unload_entry.mock_calls) == 1 assert len(async_setup.mock_calls) == 1 assert len(async_setup_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED @pytest.mark.parametrize( "state", ( - config_entries.ENTRY_STATE_NOT_LOADED, - config_entries.ENTRY_STATE_SETUP_ERROR, - config_entries.ENTRY_STATE_SETUP_RETRY, + config_entries.ConfigEntryState.NOT_LOADED, + config_entries.ConfigEntryState.SETUP_ERROR, + config_entries.ConfigEntryState.SETUP_RETRY, ), ) async def test_entry_reload_not_loaded(hass, manager, state): @@ -1224,14 +1226,14 @@ async def test_entry_reload_not_loaded(hass, manager, state): assert len(async_unload_entry.mock_calls) == 0 assert len(async_setup.mock_calls) == 1 assert len(async_setup_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED @pytest.mark.parametrize( "state", ( - config_entries.ENTRY_STATE_MIGRATION_ERROR, - config_entries.ENTRY_STATE_FAILED_UNLOAD, + config_entries.ConfigEntryState.MIGRATION_ERROR, + config_entries.ConfigEntryState.FAILED_UNLOAD, ), ) async def test_entry_reload_error(hass, manager, state): @@ -1265,7 +1267,7 @@ async def test_entry_reload_error(hass, manager, state): async def test_entry_disable_succeed(hass, manager): """Test that we can disable an entry.""" - entry = MockConfigEntry(domain="comp", state=config_entries.ENTRY_STATE_LOADED) + entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) entry.add_to_hass(hass) async_setup = AsyncMock(return_value=True) @@ -1290,19 +1292,19 @@ async def test_entry_disable_succeed(hass, manager): assert len(async_unload_entry.mock_calls) == 1 assert len(async_setup.mock_calls) == 0 assert len(async_setup_entry.mock_calls) == 0 - assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED # Enable assert await manager.async_set_disabled_by(entry.entry_id, None) assert len(async_unload_entry.mock_calls) == 1 assert len(async_setup.mock_calls) == 1 assert len(async_setup_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED async def test_entry_disable_without_reload_support(hass, manager): """Test that we can disable an entry without reload support.""" - entry = MockConfigEntry(domain="comp", state=config_entries.ENTRY_STATE_LOADED) + entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) entry.add_to_hass(hass) async_setup = AsyncMock(return_value=True) @@ -1324,14 +1326,14 @@ async def test_entry_disable_without_reload_support(hass, manager): ) assert len(async_setup.mock_calls) == 0 assert len(async_setup_entry.mock_calls) == 0 - assert entry.state == config_entries.ENTRY_STATE_FAILED_UNLOAD + assert entry.state is config_entries.ConfigEntryState.FAILED_UNLOAD # Enable with pytest.raises(config_entries.OperationNotAllowed): await manager.async_set_disabled_by(entry.entry_id, None) assert len(async_setup.mock_calls) == 0 assert len(async_setup_entry.mock_calls) == 0 - assert entry.state == config_entries.ENTRY_STATE_FAILED_UNLOAD + assert entry.state is config_entries.ConfigEntryState.FAILED_UNLOAD async def test_entry_enable_without_reload_support(hass, manager): @@ -1356,7 +1358,7 @@ async def test_entry_enable_without_reload_support(hass, manager): assert await manager.async_set_disabled_by(entry.entry_id, None) assert len(async_setup.mock_calls) == 1 assert len(async_setup_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED # Disable assert not await manager.async_set_disabled_by( @@ -1364,7 +1366,7 @@ async def test_entry_enable_without_reload_support(hass, manager): ) assert len(async_setup.mock_calls) == 1 assert len(async_setup_entry.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_FAILED_UNLOAD + assert entry.state is config_entries.ConfigEntryState.FAILED_UNLOAD async def test_init_custom_integration(hass): @@ -1408,7 +1410,7 @@ async def test_reload_entry_entity_registry_works(hass): registry = mock_registry(hass) config_entry = MockConfigEntry( - domain="comp", state=config_entries.ENTRY_STATE_LOADED + domain="comp", state=config_entries.ConfigEntryState.LOADED ) config_entry.supports_unload = True config_entry.add_to_hass(hass) @@ -1488,7 +1490,7 @@ async def test_unique_id_existing_entry(hass, manager): hass.config.components.add("comp") MockConfigEntry( domain="comp", - state=config_entries.ENTRY_STATE_LOADED, + state=config_entries.ConfigEntryState.LOADED, unique_id="mock-unique-id", ).add_to_hass(hass) @@ -1543,7 +1545,7 @@ async def test_entry_id_existing_entry(hass, manager): MockConfigEntry( entry_id=collide_entry_id, domain="comp", - state=config_entries.ENTRY_STATE_LOADED, + state=config_entries.ConfigEntryState.LOADED, unique_id="mock-unique-id", ).add_to_hass(hass) @@ -1580,7 +1582,7 @@ async def test_unique_id_update_existing_entry_without_reload(hass, manager): domain="comp", data={"additional": "data", "host": "0.0.0.0"}, unique_id="mock-unique-id", - state=config_entries.ENTRY_STATE_LOADED, + state=config_entries.ConfigEntryState.LOADED, ) entry.add_to_hass(hass) @@ -1624,7 +1626,7 @@ async def test_unique_id_update_existing_entry_with_reload(hass, manager): domain="comp", data={"additional": "data", "host": "0.0.0.0"}, unique_id="mock-unique-id", - state=config_entries.ENTRY_STATE_LOADED, + state=config_entries.ConfigEntryState.LOADED, ) entry.add_to_hass(hass) @@ -1663,7 +1665,7 @@ async def test_unique_id_update_existing_entry_with_reload(hass, manager): # Test we don't reload if entry not started updates["host"] = "2.2.2.2" - entry.state = config_entries.ENTRY_STATE_NOT_LOADED + entry.state = config_entries.ConfigEntryState.NOT_LOADED with patch.dict(config_entries.HANDLERS, {"comp": TestFlow}), patch( "homeassistant.config_entries.ConfigEntries.async_reload" ) as async_reload: @@ -1842,7 +1844,7 @@ async def test_manual_add_overrides_ignored_entry(hass, manager): domain="comp", data={"additional": "data", "host": "0.0.0.0"}, unique_id="mock-unique-id", - state=config_entries.ENTRY_STATE_LOADED, + state=config_entries.ConfigEntryState.LOADED, source=config_entries.SOURCE_IGNORE, ) entry.add_to_hass(hass) @@ -1885,7 +1887,7 @@ async def test_manual_add_overrides_ignored_entry_singleton(hass, manager): hass.config.components.add("comp") entry = MockConfigEntry( domain="comp", - state=config_entries.ENTRY_STATE_LOADED, + state=config_entries.ConfigEntryState.LOADED, source=config_entries.SOURCE_IGNORE, ) entry.add_to_hass(hass) @@ -1924,7 +1926,7 @@ async def test__async_current_entries_does_not_skip_ignore_non_user(hass, manage hass.config.components.add("comp") entry = MockConfigEntry( domain="comp", - state=config_entries.ENTRY_STATE_LOADED, + state=config_entries.ConfigEntryState.LOADED, source=config_entries.SOURCE_IGNORE, ) entry.add_to_hass(hass) @@ -1959,7 +1961,7 @@ async def test__async_current_entries_explict_skip_ignore(hass, manager): hass.config.components.add("comp") entry = MockConfigEntry( domain="comp", - state=config_entries.ENTRY_STATE_LOADED, + state=config_entries.ConfigEntryState.LOADED, source=config_entries.SOURCE_IGNORE, ) entry.add_to_hass(hass) @@ -1998,7 +2000,7 @@ async def test__async_current_entries_explict_include_ignore(hass, manager): hass.config.components.add("comp") entry = MockConfigEntry( domain="comp", - state=config_entries.ENTRY_STATE_LOADED, + state=config_entries.ConfigEntryState.LOADED, source=config_entries.SOURCE_IGNORE, ) entry.add_to_hass(hass) @@ -2254,7 +2256,7 @@ async def test_async_setup_init_entry(hass): entries = hass.config_entries.async_entries("comp") assert len(entries) == 1 - assert entries[0].state == config_entries.ENTRY_STATE_LOADED + assert entries[0].state is config_entries.ConfigEntryState.LOADED async def test_async_setup_update_entry(hass): @@ -2309,7 +2311,7 @@ async def test_async_setup_update_entry(hass): entries = hass.config_entries.async_entries("comp") assert len(entries) == 1 - assert entries[0].state == config_entries.ENTRY_STATE_LOADED + assert entries[0].state is config_entries.ConfigEntryState.LOADED assert entries[0].data == {"value": "updated"} @@ -2501,7 +2503,7 @@ async def test_updating_entry_with_and_without_changes(manager): title="thetitle", options={"option": True}, unique_id="abc123", - state=config_entries.ENTRY_STATE_SETUP_ERROR, + state=config_entries.ConfigEntryState.SETUP_ERROR, ) entry.add_to_manager(manager) @@ -2552,7 +2554,7 @@ async def test_updating_entry_with_and_without_changes(manager): async def test_entry_reload_calls_on_unload_listeners(hass, manager): """Test reload calls the on unload listeners.""" - entry = MockConfigEntry(domain="comp", state=config_entries.ENTRY_STATE_LOADED) + entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) entry.add_to_hass(hass) async_setup = AsyncMock(return_value=True) @@ -2578,7 +2580,7 @@ async def test_entry_reload_calls_on_unload_listeners(hass, manager): assert len(async_unload_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_unload_callback.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED assert await manager.async_reload(entry.entry_id) assert len(async_unload_entry.mock_calls) == 2 @@ -2586,7 +2588,7 @@ async def test_entry_reload_calls_on_unload_listeners(hass, manager): # Since we did not register another async_on_unload it should # have only been called once assert len(mock_unload_callback.mock_calls) == 1 - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED async def test_setup_raise_auth_failed(hass, caplog): @@ -2603,7 +2605,7 @@ async def test_setup_raise_auth_failed(hass, caplog): await hass.async_block_till_done() assert "could not authenticate: The password is no longer valid" in caplog.text - assert entry.state == config_entries.ENTRY_STATE_SETUP_ERROR + assert entry.state is config_entries.ConfigEntryState.SETUP_ERROR assert entry.reason == "The password is no longer valid" flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 @@ -2611,7 +2613,7 @@ async def test_setup_raise_auth_failed(hass, caplog): assert flows[0]["context"]["source"] == config_entries.SOURCE_REAUTH caplog.clear() - entry.state = config_entries.ENTRY_STATE_NOT_LOADED + entry.state = config_entries.ConfigEntryState.NOT_LOADED entry.reason = None await entry.async_setup(hass) @@ -2619,7 +2621,7 @@ async def test_setup_raise_auth_failed(hass, caplog): assert "could not authenticate: The password is no longer valid" in caplog.text # Verify multiple ConfigEntryAuthFailed does not generate a second flow - assert entry.state == config_entries.ENTRY_STATE_SETUP_ERROR + assert entry.state is config_entries.ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 @@ -2652,21 +2654,21 @@ async def test_setup_raise_auth_failed_from_first_coordinator_update(hass, caplo await hass.async_block_till_done() assert "could not authenticate: The password is no longer valid" in caplog.text - assert entry.state == config_entries.ENTRY_STATE_SETUP_ERROR + assert entry.state is config_entries.ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 assert flows[0]["context"]["entry_id"] == entry.entry_id assert flows[0]["context"]["source"] == config_entries.SOURCE_REAUTH caplog.clear() - entry.state = config_entries.ENTRY_STATE_NOT_LOADED + entry.state = config_entries.ConfigEntryState.NOT_LOADED await entry.async_setup(hass) await hass.async_block_till_done() assert "could not authenticate: The password is no longer valid" in caplog.text # Verify multiple ConfigEntryAuthFailed does not generate a second flow - assert entry.state == config_entries.ENTRY_STATE_SETUP_ERROR + assert entry.state is config_entries.ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 @@ -2700,14 +2702,14 @@ async def test_setup_raise_auth_failed_from_future_coordinator_update(hass, capl assert "Authentication failed while fetching" in caplog.text assert "The password is no longer valid" in caplog.text - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 assert flows[0]["context"]["entry_id"] == entry.entry_id assert flows[0]["context"]["source"] == config_entries.SOURCE_REAUTH caplog.clear() - entry.state = config_entries.ENTRY_STATE_NOT_LOADED + entry.state = config_entries.ConfigEntryState.NOT_LOADED await entry.async_setup(hass) await hass.async_block_till_done() @@ -2715,7 +2717,7 @@ async def test_setup_raise_auth_failed_from_future_coordinator_update(hass, capl assert "The password is no longer valid" in caplog.text # Verify multiple ConfigEntryAuthFailed does not generate a second flow - assert entry.state == config_entries.ENTRY_STATE_LOADED + assert entry.state is config_entries.ConfigEntryState.LOADED flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 @@ -2743,7 +2745,7 @@ async def test_setup_retrying_during_shutdown(hass): with patch("homeassistant.helpers.event.async_call_later") as mock_call: await entry.async_setup(hass) - assert entry.state == config_entries.ENTRY_STATE_SETUP_RETRY + assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY assert len(mock_call.return_value.mock_calls) == 0 hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)