Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tami4 device name is None #123156

Merged
merged 9 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion homeassistant/components/tami4/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ async def async_step_otp(
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
device_name = api.device_metadata.name
if device_name is None:
device_name = "Tami4"
edenhaus marked this conversation as resolved.
Show resolved Hide resolved
return self.async_create_entry(
title=api.device_metadata.name,
title=device_name,
data={CONF_REFRESH_TOKEN: refresh_token},
)

Expand Down
25 changes: 25 additions & 0 deletions tests/components/tami4/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ def mock__get_devices_metadata(request: pytest.FixtureRequest) -> Generator[None
yield


@pytest.fixture
def mock__get_devices_metadata_no_name(
request: pytest.FixtureRequest,
) -> Generator[None]:
"""Fixture to mock _get_devices which makes a call to the API."""

side_effect = getattr(request, "param", None)

device_metadata = DeviceMetadata(
id=1,
name=None,
connected=True,
psn="psn",
type="type",
device_firmware="v1.1",
)

with patch(
"Tami4EdgeAPI.Tami4EdgeAPI.Tami4EdgeAPI._get_devices_metadata",
return_value=[device_metadata],
side_effect=side_effect,
):
yield


@pytest.fixture
def mock_get_device(
request: pytest.FixtureRequest,
Expand Down
33 changes: 33 additions & 0 deletions tests/components/tami4/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,39 @@ async def test_step_otp_valid(
assert "refresh_token" in result["data"]


@pytest.mark.usefixtures(
"mock_setup_entry",
"mock_request_otp",
"mock_submit_otp",
"mock__get_devices_metadata_no_name",
)
async def test_step_otp_valid_device_no_name(hass: HomeAssistant) -> None:
"""Test user step with valid phone number."""

result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={CONF_PHONE: "+972555555555"},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "otp"
assert result["errors"] == {}

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={"otp": "123456"},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Tami4"
assert "refresh_token" in result["data"]


@pytest.mark.parametrize(
("mock_submit_otp", "expected_error"),
[
Expand Down