Make smlight repair issues unique per config entry (#190315)

This commit is contained in:
Erik Montnemery
2026-11-05 00:28:40 +00:00
committed by GitHub
parent f2a7d3dceb
commit 64488cf8e4
3 changed files with 71 additions and 4 deletions
@@ -114,17 +114,22 @@ class SmBaseDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
self.unique_id = format_mac(info.MAC)
self.legacy_api = info.legacy_api
issue_id = f"unsupported_firmware_{self.config_entry.entry_id}"
if info.legacy_api == 2:
ir.async_create_issue(
self.hass,
DOMAIN,
"unsupported_firmware",
issue_id,
is_fixable=False,
is_persistent=False,
learn_more_url="https://smlight.tech/flasher/#SLZB-06",
severity=IssueSeverity.ERROR,
translation_key="unsupported_firmware",
translation_placeholders={"name": self.config_entry.title},
config_entry_id=self.config_entry.entry_id,
)
else:
ir.async_delete_issue(self.hass, DOMAIN, issue_id)
@override
async def _async_update_data(self) -> _DataT:
@@ -203,7 +203,7 @@
},
"issues": {
"unsupported_firmware": {
"description": "Your SMLIGHT SLZB-06x device is running an unsupported core firmware version. Please update it to the latest version to enjoy all the features of this integration.",
"description": "Your SMLIGHT SLZB-06x device \"{name}\" is running an unsupported core firmware version. Please update it to the latest version to enjoy all the features of this integration.",
"title": "SLZB core firmware update required"
}
},
+64 -2
View File
@@ -286,11 +286,73 @@ async def test_device_legacy_firmware(
assert LEGACY_VERSION in device_entry.sw_version
issue = issue_registry.async_get_issue(
domain=DOMAIN, issue_id="unsupported_firmware"
domain=DOMAIN, issue_id=f"unsupported_firmware_{entry.entry_id}"
)
assert issue is not None
assert issue.domain == DOMAIN
assert issue.issue_id == "unsupported_firmware"
assert issue.translation_key == "unsupported_firmware"
assert issue.config_entry_id == entry.entry_id
assert issue.translation_placeholders == {"name": entry.title}
async def test_legacy_firmware_issue_per_entry(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_smlight_client: MagicMock,
issue_registry: IssueRegistry,
) -> None:
"""Test each entry gets its own legacy firmware issue, removed with the entry."""
mock_smlight_client.get_info.side_effect = None
mock_smlight_client.get_info.return_value = Info(
legacy_api=2, sw_version="v0.9.9", MAC="AA:BB:CC:DD:EE:FF"
)
other_entry = MockConfigEntry(
domain=DOMAIN,
title="Other SLZB",
data=mock_config_entry.data,
unique_id="aa:bb:cc:dd:ee:00",
)
other_entry.add_to_hass(hass)
await setup_integration(hass, mock_config_entry)
for entry in (mock_config_entry, other_entry):
issue = issue_registry.async_get_issue(
DOMAIN, f"unsupported_firmware_{entry.entry_id}"
)
assert issue is not None
assert issue.config_entry_id == entry.entry_id
assert issue.translation_placeholders == {"name": entry.title}
await hass.config_entries.async_remove(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert {
issue_id for domain, issue_id in issue_registry.issues if domain == DOMAIN
} == {f"unsupported_firmware_{other_entry.entry_id}"}
async def test_legacy_firmware_issue_deleted_after_update(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_smlight_client: MagicMock,
issue_registry: IssueRegistry,
) -> None:
"""Test the legacy firmware issue is deleted once the firmware is updated."""
default_get_info = mock_smlight_client.get_info.side_effect
mock_smlight_client.get_info.side_effect = None
mock_smlight_client.get_info.return_value = Info(
legacy_api=2, sw_version="v0.9.9", MAC="AA:BB:CC:DD:EE:FF"
)
await setup_integration(hass, mock_config_entry)
issue_id = f"unsupported_firmware_{mock_config_entry.entry_id}"
assert (DOMAIN, issue_id) in issue_registry.issues
mock_smlight_client.get_info.side_effect = default_get_info
await hass.config_entries.async_reload(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert mock_config_entry.state is ConfigEntryState.LOADED
assert (DOMAIN, issue_id) not in issue_registry.issues
async def test_async_execute_command_auth_failed(