Skip to content

Commit

Permalink
Fix Tami4 device name is None (#123156)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Resch <[email protected]>
  • Loading branch information
2 people authored and frenck committed Aug 6, 2024
1 parent e9fe98f commit a09d011
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
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"
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

0 comments on commit a09d011

Please sign in to comment.