Skip to content

Commit 35323f5

Browse files
committed
New config version with data stored in options
1 parent 04b5366 commit 35323f5

5 files changed

Lines changed: 28 additions & 14 deletions

File tree

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
from bluecon import INotificationInfoStorage
22
from homeassistant.config_entries import ConfigEntry
3+
from homeassistant.core import HomeAssistant
34
from typing import Any
45

56
class ConfigEntryNotificationInfoStorage(INotificationInfoStorage):
6-
def __init__(self, entry: ConfigEntry):
7+
def __init__(self, hass: HomeAssistant, entry: ConfigEntry):
78
self.__entry = entry
9+
self.__hass = hass
810

911
def retrieveCredentials(self) -> dict[str, dict[str, Any]] | None:
10-
return self.__entry.data["credentials"]
12+
return self.__entry.options["credentials"]
1113

1214
def storeCredentials(self, credentials: dict[str, dict[str, Any]]):
13-
self.__entry.data["credentials"] = credentials
15+
new = {**self.__entry.options,
16+
"credentials": credentials}
17+
self.__hass.config_entries.async_update_entry(self.__entry, options=new)
1418

1519
def retrievePersistentIds(self) -> list[str] | None:
16-
return self.__entry.data["persistentIds"]
20+
return self.__entry.options["persistentIds"]
1721

1822
def storePersistentId(self, persistentId: str):
19-
stored_persistent_ids = self.__entry.data["persistentIds"]
23+
stored_persistent_ids = self.__entry.options["persistentIds"]
2024
if stored_persistent_ids is None:
2125
stored_persistent_ids = []
2226

2327
stored_persistent_ids.append(persistentId)
2428

25-
self.__entry.data["persistentIds"] = stored_persistent_ids
29+
new = {**self.__entry.options,
30+
"persistentIds": stored_persistent_ids}
31+
self.__hass.config_entries.async_update_entry(self.__entry, options=new)
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from bluecon import IOAuthTokenStorage, OAuthToken
22
from homeassistant.config_entries import ConfigEntry
3+
from homeassistant.core import HomeAssistant
34

45
class ConfigEntryOAuthTokenStorage(IOAuthTokenStorage):
5-
def __init__(self, entry: ConfigEntry):
6+
def __init__(self, hass: HomeAssistant, entry: ConfigEntry):
67
self.__entry = entry
8+
self.__hass = hass
79

810
def retrieveOAuthToken(self) -> OAuthToken:
9-
return OAuthToken.fromJson(self.__entry.data["token"])
11+
return OAuthToken.fromJson(self.__entry.options["token"])
1012

1113
def storeOAuthToken(self, oAuthToken: OAuthToken):
12-
self.__entry.data["token"] = oAuthToken.toJson()
14+
new = {**self.__entry.options,
15+
"token": oAuthToken.toJson()}
16+
self.__hass.config_entries.async_update_entry(self.__entry, options=new)

custom_components/bluecon/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
6161
"credentials": credentials,
6262
"persistentIds": persistentIds
6363
}
64-
config_entry.version = 2
65-
hass.config_entries.async_update_entry(config_entry, data=new)
64+
config_entry.version = 3
65+
hass.config_entries.async_update_entry(config_entry, data={}, options=new)
66+
if config_entry.version == 2:
67+
new = {**config_entry.data}
68+
config_entry.version = 3
69+
hass.config_entries.async_update_entry(config_entry, data={}, options=new)
6670

6771
return True

custom_components/bluecon/config_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from . import DOMAIN
1414

1515
class BlueConConfigFlow(ConfigFlow, domain = DOMAIN):
16-
VERSION = 2
16+
VERSION = 3
1717

1818
async def async_step_user(self, user_input: dict[str, Any] | None = None) -> FlowResult:
1919
error_info: dict[str, str] = {}
@@ -44,4 +44,4 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Flo
4444

4545
@callback
4646
def _async_finish_flow(self):
47-
return self.async_create_entry(title = DOMAIN, data = {"token": self.__oAuthToken, "credentials": None, "persistentIds": None})
47+
return self.async_create_entry(title = DOMAIN, data = {}, options = {"token": self.__oAuthToken, "credentials": None, "persistentIds": None})

custom_components/bluecon/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "bluecon",
33
"name": "Fermax Blue",
4-
"version": "0.1.3",
4+
"version": "0.1.4",
55
"documentation": "https://hass-bluecon.afonsogarcia.dev/",
66
"issue_tracker": "https://github.com/AfonsoFGarcia/hass-bluecon/issues",
77
"requirements": ["bluecon==0.1.0", "aiohttp", "oscrypto", "protobuf", "http-ece"],

0 commit comments

Comments
 (0)