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
This commit is contained in:
Ville Skyttä 2021-05-20 20:19:20 +03:00 committed by GitHub
parent 0e7409e617
commit 19d25cd901
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
101 changed files with 557 additions and 688 deletions

View file

@ -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)