Use snapshot in devolo_home_network update tests (#101442)

This commit is contained in:
Guido Schmitz 2023-10-05 20:09:52 +02:00 committed by GitHub
parent 62ea4b36cd
commit 285ad10624
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 19 deletions

View File

@ -0,0 +1,54 @@
# serializer version: 1
# name: test_update_firmware
StateSnapshot({
'attributes': ReadOnlyDict({
'auto_update': False,
'device_class': 'firmware',
'entity_picture': 'https://brands.home-assistant.io/_/devolo_home_network/icon.png',
'friendly_name': 'Mock Title Firmware',
'in_progress': False,
'installed_version': '5.6.1',
'latest_version': '5.6.2',
'release_summary': None,
'release_url': None,
'skipped_version': None,
'supported_features': <UpdateEntityFeature: 5>,
'title': None,
}),
'context': <ANY>,
'entity_id': 'update.mock_title_firmware',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_update_firmware.1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'update',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'update.mock_title_firmware',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <UpdateDeviceClass.FIRMWARE: 'firmware'>,
'original_icon': None,
'original_name': 'Firmware',
'platform': 'devolo_home_network',
'supported_features': <UpdateEntityFeature: 5>,
'translation_key': 'regular_firmware',
'unique_id': '1234567890_regular_firmware',
'unit_of_measurement': None,
})
# ---

View File

@ -3,25 +3,20 @@ from devolo_plc_api.device_api import UPDATE_NOT_AVAILABLE, UpdateFirmwareCheck
from devolo_plc_api.exceptions.device import DevicePasswordProtected, DeviceUnavailable
from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.devolo_home_network.const import (
DOMAIN,
FIRMWARE_UPDATE_INTERVAL,
)
from homeassistant.components.update import (
DOMAIN as PLATFORM,
SERVICE_INSTALL,
UpdateDeviceClass,
)
from homeassistant.components.update import DOMAIN as PLATFORM, SERVICE_INSTALL
from homeassistant.config_entries import SOURCE_REAUTH
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, STATE_UNAVAILABLE
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity import EntityCategory
from . import configure_integration
from .const import FIRMWARE_UPDATE_AVAILABLE
from .mock import MockDevice
from tests.common import async_fire_time_changed
@ -45,6 +40,7 @@ async def test_update_firmware(
mock_device: MockDevice,
entity_registry: er.EntityRegistry,
freezer: FrozenDateTimeFactory,
snapshot: SnapshotAssertion,
) -> None:
"""Test updating a device."""
entry = configure_integration(hass)
@ -54,17 +50,8 @@ async def test_update_firmware(
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(state_key)
assert state is not None
assert state.state == STATE_ON
assert state.attributes["device_class"] == UpdateDeviceClass.FIRMWARE
assert state.attributes["installed_version"] == mock_device.firmware_version
assert (
state.attributes["latest_version"]
== FIRMWARE_UPDATE_AVAILABLE.new_firmware_version.split("_")[0]
)
assert entity_registry.async_get(state_key).entity_category == EntityCategory.CONFIG
assert hass.states.get(state_key) == snapshot
assert entity_registry.async_get(state_key) == snapshot
await hass.services.async_call(
PLATFORM,