Skip to content

Commit a89f909

Browse files
committed
Delete a previous repair issue so if it was dismissed it doesn't impact the new one
1 parent 565b1f6 commit a89f909

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

custom_components/patch/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,15 @@ def _format_files(self, files: list[PatchType]) -> str:
267267

268268
def _repair(self, files: list[PatchType]) -> None:
269269
"""Report an issue of base file mismatch."""
270+
ir.async_delete_issue(
271+
self._hass,
272+
DOMAIN,
273+
"patch_file_base_mismatch",
274+
)
270275
ir.async_create_issue(
271276
self._hass,
272277
DOMAIN,
273-
"patch_file_base_mismatch_" + str(int(dt_util.now().timestamp())),
278+
"patch_file_base_mismatch",
274279
is_fixable=False,
275280
learn_more_url="https://github.com/amitfin/patch#configuration",
276281
severity=ir.IssueSeverity.ERROR,
@@ -280,10 +285,15 @@ def _repair(self, files: list[PatchType]) -> None:
280285

281286
def _applied(self, files: list[PatchType]) -> None:
282287
"""Report the system was patched."""
288+
ir.async_delete_issue(
289+
self._hass,
290+
DOMAIN,
291+
"system_was_patched",
292+
)
283293
ir.async_create_issue(
284294
self._hass,
285295
DOMAIN,
286-
"system_was_patched_" + str(int(dt_util.now().timestamp())),
296+
"system_was_patched",
287297
is_fixable=False,
288298
is_persistent=True,
289299
learn_more_url="https://github.com/amitfin/patch#configuration",

tests/test_init.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async def test_patch( # noqa: PLR0913
171171
if update:
172172
assert repairs[0].data["action"] == "create"
173173
assert repairs[0].data["domain"] == DOMAIN
174-
assert repairs[0].data["issue_id"].startswith("system_was_patched")
174+
assert repairs[0].data["issue_id"] == "system_was_patched"
175175
if restart:
176176
assert async_call_mock.await_args_list[0].args[0] == ha.DOMAIN
177177
assert (
@@ -185,7 +185,7 @@ async def test_patch( # noqa: PLR0913
185185
assert "is different than its base" in caplog.text
186186
assert repairs[0].data["action"] == "create"
187187
assert repairs[0].data["domain"] == DOMAIN
188-
assert repairs[0].data["issue_id"].startswith("patch_file_base_mismatch")
188+
assert repairs[0].data["issue_id"] == "patch_file_base_mismatch"
189189

190190

191191
@patch("homeassistant.core.ServiceRegistry.async_call")
@@ -226,7 +226,7 @@ async def test_patch_url(
226226
with (Path(destination) / "file").open(encoding="ascii") as file:
227227
assert file.read() == "new"
228228
assert async_call_mock.call_count == 1
229-
assert repairs[0].data["issue_id"].startswith("system_was_patched")
229+
assert repairs[0].data["issue_id"] == "system_was_patched"
230230

231231

232232
@pytest.mark.allowed_logs(
@@ -459,4 +459,4 @@ async def test_immediate_base_mismatch(hass: HomeAssistant) -> None:
459459
Loader=yaml.SafeLoader,
460460
),
461461
)
462-
assert repairs[0].data["issue_id"].startswith("patch_file_base_mismatch")
462+
assert repairs[0].data["issue_id"] == "patch_file_base_mismatch"

0 commit comments

Comments
 (0)