mirror of
https://github.com/home-assistant/core.git
synced 2026-12-04 12:50:45 -04:00
Use update release notes messages in Matter (#193204)
This commit is contained in:
@@ -782,6 +782,12 @@
|
||||
"name": "Visual alarm enabled"
|
||||
}
|
||||
},
|
||||
"update": {
|
||||
"release_notes_messages": {
|
||||
"non_main_net_update_source": "Update provided by {update_source}. Installing this update is at your own risk and you may run into unexpected problems such as the need to re-add and factory reset your device.",
|
||||
"update_duration": "The update process can take a while, especially for battery powered devices. Please be patient and wait until the update process is fully completed. The device may restart during the update process and be unavailable for several minutes."
|
||||
}
|
||||
},
|
||||
"vacuum": {
|
||||
"vacuum": {
|
||||
"name": "[%key:component::vacuum::title%]"
|
||||
|
||||
@@ -9,19 +9,23 @@ from matter_server.common.errors import UpdateCheckError, UpdateError
|
||||
from matter_server.common.models import MatterSoftwareVersion, UpdateSource
|
||||
|
||||
from homeassistant.components.update import (
|
||||
RELEASE_NOTES_MESSAGE_DO_NOT_INTERRUPT,
|
||||
UpdateDeviceClass,
|
||||
UpdateEntity,
|
||||
UpdateEntityDescription,
|
||||
UpdateEntityFeature,
|
||||
UpdateEntityStateAttribute,
|
||||
UpdateReleaseNotesMessage,
|
||||
UpdateReleaseNotesMessageSeverity,
|
||||
)
|
||||
from homeassistant.const import STATE_ON, Platform
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
from homeassistant.helpers.restore_state import ExtraStoredData
|
||||
|
||||
from .const import DOMAIN
|
||||
from .entity import MatterEntity, MatterEntityDescription
|
||||
from .helpers import MatterConfigEntry
|
||||
from .models import MatterDiscoverySchema
|
||||
@@ -31,6 +35,11 @@ POLL_AFTER_INSTALL = 10
|
||||
|
||||
ATTR_SOFTWARE_UPDATE = "software_update"
|
||||
|
||||
RELEASE_NOTES_MESSAGE_UPDATE_DURATION = UpdateReleaseNotesMessage(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="update_duration",
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class MatterUpdateExtraStoredData(ExtraStoredData):
|
||||
@@ -161,42 +170,40 @@ class MatterUpdate(MatterEntity, UpdateEntity):
|
||||
except UpdateCheckError as err:
|
||||
raise HomeAssistantError(f"Error finding applicable update: {err}") from err
|
||||
|
||||
@property
|
||||
@override
|
||||
def release_notes_messages(self) -> tuple[UpdateReleaseNotesMessage, ...]:
|
||||
"""Messages shown before the release notes."""
|
||||
messages: tuple[UpdateReleaseNotesMessage, ...] = (
|
||||
RELEASE_NOTES_MESSAGE_DO_NOT_INTERRUPT,
|
||||
RELEASE_NOTES_MESSAGE_UPDATE_DURATION,
|
||||
)
|
||||
if (
|
||||
self._software_update is not None
|
||||
and self._software_update.update_source is not UpdateSource.MAIN_NET_DCL
|
||||
):
|
||||
# Extra heavy warning in case the update is not from the main net
|
||||
messages = (
|
||||
UpdateReleaseNotesMessage(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="non_main_net_update_source",
|
||||
severity=UpdateReleaseNotesMessageSeverity.WARNING,
|
||||
translation_placeholders={
|
||||
"update_source": self._software_update.update_source.value
|
||||
},
|
||||
),
|
||||
*messages,
|
||||
)
|
||||
return messages
|
||||
|
||||
@override
|
||||
async def async_release_notes(self) -> str | None:
|
||||
"""Return full release notes.
|
||||
|
||||
This is suitable for a long changelog that does not fit in the release_summary
|
||||
property. The returned string can contain markdown.
|
||||
Matter provides no release notes; the guidance is in the release notes
|
||||
messages.
|
||||
"""
|
||||
if self._software_update is None:
|
||||
return None
|
||||
if self.state != STATE_ON:
|
||||
return None
|
||||
|
||||
release_notes = ""
|
||||
|
||||
# insert extra heavy warning case the update is not from the main net
|
||||
if self._software_update.update_source is not UpdateSource.MAIN_NET_DCL:
|
||||
release_notes += (
|
||||
"\n\n<ha-alert alert-type='warning'>"
|
||||
"Update provided by "
|
||||
f"{self._software_update.update_source.value}. "
|
||||
"Installing this update is at your own risk "
|
||||
"and you may run into unexpected "
|
||||
"problems such as the need to re-add and "
|
||||
"factory reset your device.</ha-alert>\n\n"
|
||||
)
|
||||
return release_notes + (
|
||||
"\n\n<ha-alert alert-type='info'>"
|
||||
"The update process can take a while, "
|
||||
"especially for battery powered devices. "
|
||||
"Please be patient and wait until the update "
|
||||
"process is fully completed. Do not remove power "
|
||||
"from the device while it's updating. "
|
||||
"The device may restart during the update process "
|
||||
"and be unavailable for several minutes."
|
||||
"</ha-alert>\n\n"
|
||||
)
|
||||
return None
|
||||
|
||||
@override
|
||||
async def async_added_to_hass(self) -> None:
|
||||
|
||||
@@ -15,6 +15,7 @@ from pytest_homeassistant.common import (
|
||||
async_mock_restore_state_shutdown_restart,
|
||||
mock_restore_cache_with_extra_data,
|
||||
)
|
||||
from pytest_homeassistant.typing import WebSocketGenerator
|
||||
|
||||
from homeassistant.components.homeassistant import (
|
||||
DOMAIN as HA_DOMAIN,
|
||||
@@ -218,6 +219,108 @@ async def test_update_check_with_same_version_string(
|
||||
assert state.attributes.get("release_url") is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("update_source", "expected_source_warning"),
|
||||
[
|
||||
(UpdateSource.MAIN_NET_DCL, []),
|
||||
(
|
||||
UpdateSource.LOCAL,
|
||||
[
|
||||
{
|
||||
"severity": "warning",
|
||||
"message": (
|
||||
"Update provided by local. Installing this update is at"
|
||||
" your own risk and you may run into unexpected problems"
|
||||
" such as the need to re-add and factory reset your device."
|
||||
),
|
||||
}
|
||||
],
|
||||
),
|
||||
(
|
||||
UpdateSource.TEST_NET_DCL,
|
||||
[
|
||||
{
|
||||
"severity": "warning",
|
||||
"message": (
|
||||
"Update provided by test-net-dcl. Installing this update is"
|
||||
" at your own risk and you may run into unexpected problems"
|
||||
" such as the need to re-add and factory reset your device."
|
||||
),
|
||||
}
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("node_fixture", ["mock_dimmable_light"])
|
||||
async def test_release_notes(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
check_node_update: AsyncMock,
|
||||
matter_node: MatterNode,
|
||||
update_source: UpdateSource,
|
||||
expected_source_warning: list[dict[str, str]],
|
||||
) -> None:
|
||||
"""Test the release notes messages."""
|
||||
entity_id = "update.mock_dimmable_light_firmware"
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
# No messages while no update is available
|
||||
await ws_client.send_json(
|
||||
{"id": 1, "type": "update/release_notes", "entity_id": entity_id}
|
||||
)
|
||||
result = await ws_client.receive_json()
|
||||
assert result["success"] is True
|
||||
assert result["result"] == {"release_notes": None, "messages": []}
|
||||
|
||||
check_node_update.return_value = MatterSoftwareVersion(
|
||||
vid=65521,
|
||||
pid=32768,
|
||||
software_version=2,
|
||||
software_version_string="v2.0",
|
||||
firmware_information="",
|
||||
min_applicable_software_version=0,
|
||||
max_applicable_software_version=1,
|
||||
release_notes_url="http://home-assistant.io/non-existing-product",
|
||||
update_source=update_source,
|
||||
)
|
||||
await async_setup_component(hass, HA_DOMAIN, {})
|
||||
await hass.services.async_call(
|
||||
HA_DOMAIN,
|
||||
SERVICE_UPDATE_ENTITY,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
|
||||
await ws_client.send_json(
|
||||
{"id": 2, "type": "update/release_notes", "entity_id": entity_id}
|
||||
)
|
||||
result = await ws_client.receive_json()
|
||||
assert result["success"] is True
|
||||
assert result["result"] == {
|
||||
"release_notes": None,
|
||||
"messages": [
|
||||
*expected_source_warning,
|
||||
{
|
||||
"severity": "warning",
|
||||
"message": (
|
||||
"Do not restart, remove power from, or otherwise interrupt the"
|
||||
" device while the update is in progress."
|
||||
),
|
||||
},
|
||||
{
|
||||
"severity": "info",
|
||||
"message": (
|
||||
"The update process can take a while, especially for battery"
|
||||
" powered devices. Please be patient and wait until the update"
|
||||
" process is fully completed. The device may restart during the"
|
||||
" update process and be unavailable for several minutes."
|
||||
),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("node_fixture", ["mock_dimmable_light"])
|
||||
async def test_update_check_with_same_numeric_version(
|
||||
hass: HomeAssistant,
|
||||
@@ -486,6 +589,7 @@ async def test_update_state_save_and_restore(
|
||||
|
||||
async def test_update_state_restore(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
matter_client: MagicMock,
|
||||
check_node_update: AsyncMock,
|
||||
update_node: AsyncMock,
|
||||
@@ -520,6 +624,26 @@ async def test_update_state_restore(
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("latest_version") == "v2.0"
|
||||
|
||||
# The update source warning is based on the restored extra data
|
||||
ws_client = await hass_ws_client(hass)
|
||||
await ws_client.send_json(
|
||||
{
|
||||
"id": 1,
|
||||
"type": "update/release_notes",
|
||||
"entity_id": "update.mock_dimmable_light_firmware",
|
||||
}
|
||||
)
|
||||
result = await ws_client.receive_json()
|
||||
assert result["success"] is True
|
||||
assert result["result"]["messages"][0] == {
|
||||
"severity": "warning",
|
||||
"message": (
|
||||
"Update provided by local. Installing this update is at your own risk"
|
||||
" and you may run into unexpected problems such as the need to re-add"
|
||||
" and factory reset your device."
|
||||
),
|
||||
}
|
||||
|
||||
await hass.services.async_call(
|
||||
UPDATE_DOMAIN,
|
||||
UpdateService.INSTALL,
|
||||
|
||||
Reference in New Issue
Block a user