Skip to content

Commit

Permalink
use senor_type instead of switchbot model + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal4K committed Sep 2, 2024
1 parent b7f7932 commit be85e29
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/switchbot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
SwitchbotApiError,
SwitchbotAuthenticationError,
SwitchbotLock,
SwitchbotModel,
parse_advertisement_data,
)
import voluptuous as vol
Expand Down Expand Up @@ -48,6 +47,7 @@
NON_CONNECTABLE_SUPPORTED_MODEL_TYPES,
SUPPORTED_LOCK_MODELS,
SUPPORTED_MODEL_TYPES,
SupportedModels,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -366,7 +366,7 @@ async def async_step_init(
),
): int
}
if self.config_entry.runtime_data.model == SwitchbotModel.LOCK_PRO:
if self.config_entry.data.get(CONF_SENSOR_TYPE) == SupportedModels.LOCK_PRO:
options.update(
{
vol.Optional(
Expand Down
63 changes: 63 additions & 0 deletions tests/components/switchbot/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from homeassistant.components.switchbot.const import (
CONF_ENCRYPTION_KEY,
CONF_KEY_ID,
CONF_LOCK_NIGHTLATCH,
CONF_RETRY_COUNT,
)
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_USER
Expand Down Expand Up @@ -782,3 +783,65 @@ async def test_options_flow(hass: HomeAssistant) -> None:
assert len(mock_setup_entry.mock_calls) == 1

assert entry.options[CONF_RETRY_COUNT] == 6


async def test_options_flow_lock_pro(hass: HomeAssistant) -> None:
"""Test updating options."""
entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
CONF_NAME: "test-name",
CONF_PASSWORD: "test-password",
CONF_SENSOR_TYPE: "lock_pro",
},
options={CONF_RETRY_COUNT: 10},
unique_id="aabbccddeeff",
)
entry.add_to_hass(hass)

# Test Force night_latch should be disabled by default.
with patch_async_setup_entry() as mock_setup_entry:
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

result = await hass.config_entries.options.async_init(entry.entry_id)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
assert result["errors"] is None

result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
CONF_RETRY_COUNT: 3,
},
)
await hass.async_block_till_done()

assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"][CONF_LOCK_NIGHTLATCH] is False

assert len(mock_setup_entry.mock_calls) == 1

# Test Set force night_latch to be enabled.

with patch_async_setup_entry() as mock_setup_entry:
result = await hass.config_entries.options.async_init(entry.entry_id)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
assert result["errors"] is None

result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
CONF_LOCK_NIGHTLATCH: True,
},
)
await hass.async_block_till_done()

assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"][CONF_LOCK_NIGHTLATCH] is True

assert len(mock_setup_entry.mock_calls) == 0

assert entry.options[CONF_LOCK_NIGHTLATCH] is True

0 comments on commit be85e29

Please sign in to comment.