Use None as default value for strict connection cloud store (#116219)
parent
49d8ac0811
commit
67f6a84f5d
|
@ -365,13 +365,16 @@ class CloudPreferences:
|
||||||
@property
|
@property
|
||||||
def strict_connection(self) -> http.const.StrictConnectionMode:
|
def strict_connection(self) -> http.const.StrictConnectionMode:
|
||||||
"""Return the strict connection mode."""
|
"""Return the strict connection mode."""
|
||||||
mode = self._prefs.get(
|
mode = self._prefs.get(PREF_STRICT_CONNECTION)
|
||||||
PREF_STRICT_CONNECTION, http.const.StrictConnectionMode.DISABLED
|
|
||||||
)
|
|
||||||
|
|
||||||
if not isinstance(mode, http.const.StrictConnectionMode):
|
if mode is None:
|
||||||
|
# Set to default value
|
||||||
|
# We store None in the store as the default value to detect if the user has changed the
|
||||||
|
# value or not.
|
||||||
|
mode = http.const.StrictConnectionMode.DISABLED
|
||||||
|
elif not isinstance(mode, http.const.StrictConnectionMode):
|
||||||
mode = http.const.StrictConnectionMode(mode)
|
mode = http.const.StrictConnectionMode(mode)
|
||||||
return mode # type: ignore[no-any-return]
|
return mode
|
||||||
|
|
||||||
async def get_cloud_user(self) -> str:
|
async def get_cloud_user(self) -> str:
|
||||||
"""Return ID of Home Assistant Cloud system user."""
|
"""Return ID of Home Assistant Cloud system user."""
|
||||||
|
@ -430,5 +433,5 @@ class CloudPreferences:
|
||||||
PREF_REMOTE_DOMAIN: None,
|
PREF_REMOTE_DOMAIN: None,
|
||||||
PREF_REMOTE_ALLOW_REMOTE_ENABLE: True,
|
PREF_REMOTE_ALLOW_REMOTE_ENABLE: True,
|
||||||
PREF_USERNAME: username,
|
PREF_USERNAME: username,
|
||||||
PREF_STRICT_CONNECTION: http.const.StrictConnectionMode.DISABLED,
|
PREF_STRICT_CONNECTION: None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,3 +197,21 @@ async def test_strict_connection_convertion(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert cloud.client.prefs.strict_connection is mode
|
assert cloud.client.prefs.strict_connection is mode
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("storage_data", [{}, {PREF_STRICT_CONNECTION: None}])
|
||||||
|
async def test_strict_connection_default(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
cloud: MagicMock,
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
|
storage_data: dict[str, Any],
|
||||||
|
) -> None:
|
||||||
|
"""Test strict connection default values."""
|
||||||
|
hass_storage[STORAGE_KEY] = {
|
||||||
|
"version": 1,
|
||||||
|
"data": storage_data,
|
||||||
|
}
|
||||||
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert cloud.client.prefs.strict_connection is StrictConnectionMode.DISABLED
|
||||||
|
|
Loading…
Reference in New Issue