-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
Forbid to choose state in Ukraine Alarm integration #156183
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
joostlek
merged 6 commits into
home-assistant:dev
from
PaulAnnekov:ukraine-alarm-forbid-to-choose-state
Nov 11, 2025
+172
−100
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e05e0c8
Forbid to choose state in Ukraine Alarm integration
PaulAnnekov 06ef37b
Fix copilot requests
PaulAnnekov 2ade65b
Fix missing end line
PaulAnnekov 7d555a0
Fix double end line
PaulAnnekov 8d3e551
Review fix
PaulAnnekov 2802d6f
Merge remote-tracking branch 'upstream/dev' into ukraine-alarm-forbid…
PaulAnnekov 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
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 |
|---|---|---|
| @@ -1 +1,27 @@ | ||
| """Tests for the Ukraine Alarm integration.""" | ||
|
|
||
|
|
||
| def _region(rid, recurse=0, depth=0): | ||
| """Create a test region with optional nested structure.""" | ||
| if depth == 0: | ||
| name_prefix = "State" | ||
| elif depth == 1: | ||
| name_prefix = "District" | ||
| else: | ||
| name_prefix = "Community" | ||
|
|
||
| name = f"{name_prefix} {rid}" | ||
| region = {"regionId": rid, "regionName": name, "regionChildIds": []} | ||
|
|
||
| if not recurse: | ||
| return region | ||
|
|
||
| for i in range(1, 4): | ||
| region["regionChildIds"].append(_region(f"{rid}.{i}", recurse - 1, depth + 1)) | ||
|
|
||
| return region | ||
|
|
||
|
|
||
| REGIONS = { | ||
| "states": [_region(f"{i}", i - 1) for i in range(1, 4)], | ||
| } |
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,63 @@ | ||
| """Test the Ukraine Alarm integration initialization.""" | ||
|
|
||
| from unittest.mock import patch | ||
|
|
||
| from homeassistant.components.ukraine_alarm import async_migrate_entry | ||
| from homeassistant.components.ukraine_alarm.const import DOMAIN | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers import issue_registry as ir | ||
|
|
||
| from . import REGIONS | ||
|
|
||
| from tests.common import MockConfigEntry | ||
|
|
||
|
|
||
| async def test_migration_v1_to_v2_state_without_districts(hass: HomeAssistant) -> None: | ||
| """Test migration allows states without districts.""" | ||
| entry = MockConfigEntry( | ||
| domain=DOMAIN, | ||
| version=1, | ||
| data={"region": "1", "name": "State 1"}, | ||
| unique_id="1", | ||
| ) | ||
| entry.add_to_hass(hass) | ||
|
|
||
| with patch( | ||
| "homeassistant.components.ukraine_alarm.Client.get_regions", | ||
| return_value=REGIONS, | ||
| ): | ||
| result = await async_migrate_entry(hass, entry) | ||
| assert result is True | ||
PaulAnnekov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert entry.version == 2 | ||
|
|
||
| issue_registry = ir.async_get(hass) | ||
PaulAnnekov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert ( | ||
| DOMAIN, | ||
| f"deprecated_state_region_{entry.entry_id}", | ||
| ) not in issue_registry.issues | ||
|
|
||
|
|
||
| async def test_migration_v1_to_v2_state_with_districts_fails( | ||
| hass: HomeAssistant, | ||
| ) -> None: | ||
| """Test migration rejects states with districts.""" | ||
| entry = MockConfigEntry( | ||
| domain=DOMAIN, | ||
| version=1, | ||
| data={"region": "2", "name": "State 2"}, | ||
| unique_id="2", | ||
| ) | ||
| entry.add_to_hass(hass) | ||
|
|
||
| with patch( | ||
| "homeassistant.components.ukraine_alarm.Client.get_regions", | ||
| return_value=REGIONS, | ||
| ): | ||
| result = await async_migrate_entry(hass, entry) | ||
| assert result is False | ||
|
|
||
| issue_registry = ir.async_get(hass) | ||
| assert ( | ||
| DOMAIN, | ||
| f"deprecated_state_region_{entry.entry_id}", | ||
| ) in issue_registry.issues | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.