@@ -29,16 +29,22 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
29
29
session = aiohttp_client .async_get_clientsession (hass )
30
30
if (config_dir := hass .config .config_dir ) is None :
31
31
raise ValueError ("Missing Config Dir" )
32
- hon = await Hon (
33
- entry .data [CONF_EMAIL ],
34
- entry .data [CONF_PASSWORD ],
35
- mobile_id = MOBILE_ID ,
36
- session = session ,
37
- refresh_token = entry .data [CONF_REFRESH_TOKEN ],
38
- test_data_path = Path (config_dir ),
39
- ).create ()
32
+ kwargs = {
33
+ "email" : entry .data [CONF_EMAIL ],
34
+ "password" : entry .data [CONF_PASSWORD ],
35
+ "mobile_id" : MOBILE_ID ,
36
+ "session" : session ,
37
+ "test_data_path" : Path (config_dir ),
38
+ }
39
+ if refresh_token := entry .data .get (CONF_REFRESH_TOKEN ):
40
+ kwargs ["refresh_token" ] = refresh_token
41
+ hon = await Hon (** kwargs ).create ()
40
42
hass .data .setdefault (DOMAIN , {})
41
43
hass .data [DOMAIN ][entry .unique_id ] = hon
44
+
45
+ hass .config_entries .async_update_entry (
46
+ entry , data = {** entry .data , CONF_REFRESH_TOKEN : hon .api .auth .refresh_token }
47
+ )
42
48
hass .data [DOMAIN ]["coordinators" ] = {}
43
49
44
50
for platform in PLATFORMS :
@@ -49,7 +55,11 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
49
55
50
56
51
57
async def async_unload_entry (hass : HomeAssistantType , entry : ConfigEntry ) -> bool :
52
- entry .data [CONF_REFRESH_TOKEN ] = hass .data [DOMAIN ][entry .unique_id ].api .auth .refresh_token
58
+ refresh_token = hass .data [DOMAIN ][entry .unique_id ].api .auth .refresh_token
59
+
60
+ hass .config_entries .async_update_entry (
61
+ entry , data = {** entry .data , CONF_REFRESH_TOKEN : refresh_token }
62
+ )
53
63
unload = await hass .config_entries .async_unload_platforms (entry , PLATFORMS )
54
64
if unload :
55
65
if not hass .data [DOMAIN ]:
0 commit comments