-
-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove device from known_devices upon import in ping device tracker (#…
…105009) Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
- Loading branch information
Showing
4 changed files
with
168 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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 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,44 @@ | ||
"""Tests for the legacy device tracker component.""" | ||
from unittest.mock import mock_open, patch | ||
|
||
from homeassistant.components.device_tracker import legacy | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.util.yaml import dump | ||
|
||
from tests.common import patch_yaml_files | ||
|
||
|
||
def test_remove_device_from_config(hass: HomeAssistant): | ||
"""Test the removal of a device from a config.""" | ||
yaml_devices = { | ||
"test": { | ||
"hide_if_away": True, | ||
"mac": "00:11:22:33:44:55", | ||
"name": "Test name", | ||
"picture": "/local/test.png", | ||
"track": True, | ||
}, | ||
"test2": { | ||
"hide_if_away": True, | ||
"mac": "00:ab:cd:33:44:55", | ||
"name": "Test2", | ||
"picture": "/local/test2.png", | ||
"track": True, | ||
}, | ||
} | ||
mopen = mock_open() | ||
|
||
files = {legacy.YAML_DEVICES: dump(yaml_devices)} | ||
with patch_yaml_files(files, True), patch( | ||
"homeassistant.components.device_tracker.legacy.open", mopen | ||
): | ||
legacy.remove_device_from_config(hass, "test") | ||
|
||
mopen().write.assert_called_once_with( | ||
"test2:\n" | ||
" hide_if_away: true\n" | ||
" mac: 00:ab:cd:33:44:55\n" | ||
" name: Test2\n" | ||
" picture: /local/test2.png\n" | ||
" track: true\n" | ||
) |
This file contains 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