-
-
Notifications
You must be signed in to change notification settings - Fork 37.1k
Use DeviceInfo in velbus #58622
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
Merged
Merged
Use DeviceInfo in velbus #58622
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
37417a4
Use DeviceInfo in velbus
epenet bf818a6
Add type ignore for invalid identifier
epenet bffd1cb
Update identifiers
epenet 58f055a
Migrate device identifiers
epenet 2b4006b
Add type hints to tests
epenet e562b79
Add tests for load/unload
epenet 537014b
Add tests for migration
epenet 44a7f64
Adjust headers
epenet 423ff2f
Patch async_setup_entry in config_flow
epenet 0b90bcc
Assert old device entry is gone
epenet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """Fixtures for the Velbus tests.""" | ||
| from unittest.mock import AsyncMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from homeassistant.components.velbus.const import DOMAIN | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import CONF_NAME, CONF_PORT | ||
| from homeassistant.core import HomeAssistant | ||
|
|
||
| from tests.common import MockConfigEntry | ||
| from tests.components.velbus.const import PORT_TCP | ||
|
|
||
|
|
||
| @pytest.fixture(name="controller") | ||
| def mock_controller(): | ||
| """Mock a successful velbus controller.""" | ||
| controller = AsyncMock() | ||
| with patch("velbusaio.controller.Velbus", return_value=controller): | ||
| yield controller | ||
|
|
||
|
|
||
| @pytest.fixture(name="config_entry") | ||
| def mock_config_entry(hass: HomeAssistant) -> ConfigEntry: | ||
| """Create and register mock config entry.""" | ||
| config_entry = MockConfigEntry( | ||
| domain=DOMAIN, | ||
| data={CONF_PORT: PORT_TCP, CONF_NAME: "velbus home"}, | ||
| ) | ||
| config_entry.add_to_hass(hass) | ||
| return config_entry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """Constants for the Velbus tests.""" | ||
| PORT_SERIAL = "/dev/ttyACME100" | ||
| PORT_TCP = "127.0.1.0.1:3788" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Tests for the Velbus component initialisation.""" | ||
| import pytest | ||
|
|
||
| from homeassistant.components.velbus.const import DOMAIN | ||
| from homeassistant.config_entries import ConfigEntry, ConfigEntryState | ||
| from homeassistant.core import HomeAssistant | ||
|
|
||
| from tests.common import mock_device_registry | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("controller") | ||
| async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry): | ||
| """Test being able to unload an entry.""" | ||
| await hass.config_entries.async_setup(config_entry.entry_id) | ||
| await hass.async_block_till_done() | ||
|
|
||
| assert len(hass.config_entries.async_entries(DOMAIN)) == 1 | ||
| assert config_entry.state is ConfigEntryState.LOADED | ||
|
|
||
| assert await hass.config_entries.async_unload(config_entry.entry_id) | ||
| await hass.async_block_till_done() | ||
|
|
||
| assert config_entry.state is ConfigEntryState.NOT_LOADED | ||
| assert not hass.data.get(DOMAIN) | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("controller") | ||
| async def test_device_identifier_migration( | ||
| hass: HomeAssistant, config_entry: ConfigEntry | ||
| ): | ||
| """Test being able to unload an entry.""" | ||
| original_identifiers = {(DOMAIN, "module_address", "module_serial")} | ||
| target_identifiers = {(DOMAIN, "module_address")} | ||
|
|
||
| device_registry = mock_device_registry(hass) | ||
| device_registry.async_get_or_create( | ||
| config_entry_id=config_entry.entry_id, | ||
| identifiers=original_identifiers, | ||
| name="channel_name", | ||
| manufacturer="Velleman", | ||
| model="module_type_name", | ||
| sw_version="module_sw_version", | ||
| ) | ||
| assert device_registry.async_get_device(original_identifiers) | ||
| assert not device_registry.async_get_device(target_identifiers) | ||
|
|
||
| await hass.config_entries.async_setup(config_entry.entry_id) | ||
| await hass.async_block_till_done() | ||
|
|
||
| assert not device_registry.async_get_device(original_identifiers) | ||
| device_entry = device_registry.async_get_device(target_identifiers) | ||
| assert device_entry | ||
| assert device_entry.name == "channel_name" | ||
| assert device_entry.manufacturer == "Velleman" | ||
| assert device_entry.model == "module_type_name" | ||
| assert device_entry.sw_version == "module_sw_version" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a material change in the identifier ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also: #58622 (comment)
I needs migration imho