Tweak title of zha config entry created by yellow hw (#73797)

pull/73805/head
Erik Montnemery 2022-06-21 22:21:31 +02:00 committed by GitHub
parent 67618311fa
commit 274f585646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 2 deletions

View File

@ -23,12 +23,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"zha",
context={"source": "hardware"},
data={
"radio_type": "efr32",
"name": "Yellow",
"port": {
"path": "/dev/ttyAMA1",
"baudrate": 115200,
"flow_control": "hardware",
},
"radio_type": "efr32",
},
)

View File

@ -269,7 +269,7 @@ class ZhaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
except vol.Invalid:
return self.async_abort(reason="invalid_hardware_data")
self._title = data["port"]["path"]
self._title = data.get("name", data["port"]["path"])
self._set_confirm_only()
return await self.async_step_confirm_hardware()

View File

@ -41,6 +41,41 @@ async def test_setup_entry(
assert len(hass.config_entries.flow.async_progress_by_handler("zha")) == num_flows
async def test_setup_zha(hass: HomeAssistant) -> None:
"""Test zha gets the right config."""
mock_integration(hass, MockModule("hassio"))
# Setup the config entry
config_entry = MockConfigEntry(
data={},
domain=DOMAIN,
options={},
title="Home Assistant Yellow",
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.homeassistant_yellow.get_os_info",
return_value={"board": "yellow"},
) as mock_get_os_info, patch(
"homeassistant.components.onboarding.async_is_onboarded", return_value=False
):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_get_os_info.mock_calls) == 1
config_entry = hass.config_entries.async_entries("zha")[0]
assert config_entry.data == {
"device": {
"baudrate": 115200,
"flow_control": "hardware",
"path": "/dev/ttyAMA1",
},
"radio_type": "ezsp",
}
assert config_entry.options == {}
assert config_entry.title == "Yellow"
async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
"""Test setup of a config entry with wrong board type."""
mock_integration(hass, MockModule("hassio"))