-
-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store access token in entry for Fyta (#116260)
* save access_token and expiration date in ConfigEntry * add MINOR_VERSION and async_migrate_entry * shorten reading of expiration from config entry * add additional consts and test for config entry migration * Update homeassistant/components/fyta/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/fyta/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * omit check for datetime data type * Update homeassistant/components/fyta/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/fyta/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
- Loading branch information
Showing
7 changed files
with
179 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"""Const for fyta integration.""" | ||
|
||
DOMAIN = "fyta" | ||
CONF_EXPIRATION = "expiration" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Test the initialization.""" | ||
|
||
from unittest.mock import AsyncMock | ||
|
||
from homeassistant.components.fyta.const import CONF_EXPIRATION, DOMAIN | ||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_PASSWORD, CONF_USERNAME | ||
from homeassistant.core import HomeAssistant | ||
|
||
from .test_config_flow import ACCESS_TOKEN, PASSWORD, USERNAME | ||
|
||
from tests.common import MockConfigEntry | ||
|
||
|
||
async def test_migrate_config_entry( | ||
hass: HomeAssistant, | ||
mock_fyta_init: AsyncMock, | ||
) -> None: | ||
"""Test successful migration of entry data.""" | ||
entry = MockConfigEntry( | ||
domain=DOMAIN, | ||
title=USERNAME, | ||
data={ | ||
CONF_USERNAME: USERNAME, | ||
CONF_PASSWORD: PASSWORD, | ||
}, | ||
version=1, | ||
minor_version=1, | ||
) | ||
entry.add_to_hass(hass) | ||
|
||
assert entry.version == 1 | ||
assert entry.minor_version == 1 | ||
|
||
await hass.config_entries.async_setup(entry.entry_id) | ||
await hass.async_block_till_done() | ||
|
||
assert entry.version == 1 | ||
assert entry.minor_version == 2 | ||
assert entry.data[CONF_USERNAME] == USERNAME | ||
assert entry.data[CONF_PASSWORD] == PASSWORD | ||
assert entry.data[CONF_ACCESS_TOKEN] == ACCESS_TOKEN | ||
assert entry.data[CONF_EXPIRATION] == "2024-12-31T10:00:00+00:00" |