mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Use SnapshotAssertion in gree switch tests (#90222)
This commit is contained in:
parent
1baadc1d09
commit
a036e31495
206
tests/components/gree/snapshots/test_switch.ambr
Normal file
206
tests/components/gree/snapshots/test_switch.ambr
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_entity_state
|
||||||
|
list([
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'switch',
|
||||||
|
'friendly_name': 'fake-device-1 Panel Light',
|
||||||
|
'icon': 'mdi:lightbulb',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'switch.fake_device_1_panel_light',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'on',
|
||||||
|
}),
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'switch',
|
||||||
|
'friendly_name': 'fake-device-1 Quiet',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'switch.fake_device_1_quiet',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'off',
|
||||||
|
}),
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'switch',
|
||||||
|
'friendly_name': 'fake-device-1 Fresh Air',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'switch.fake_device_1_fresh_air',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'on',
|
||||||
|
}),
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'switch',
|
||||||
|
'friendly_name': 'fake-device-1 XFan',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'switch.fake_device_1_xfan',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'on',
|
||||||
|
}),
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'switch',
|
||||||
|
'friendly_name': 'fake-device-1 Health mode',
|
||||||
|
'icon': 'mdi:pine-tree',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'switch.fake_device_1_health_mode',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'on',
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
# ---
|
||||||
|
# name: test_registry_settings
|
||||||
|
list([
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'switch',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'switch.fake_device_1_panel_light',
|
||||||
|
'has_entity_name': False,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||||
|
'original_icon': 'mdi:lightbulb',
|
||||||
|
'original_name': 'fake-device-1 Panel Light',
|
||||||
|
'platform': 'gree',
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': 'aabbcc112233_Panel Light',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
}),
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'switch',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'switch.fake_device_1_quiet',
|
||||||
|
'has_entity_name': False,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'fake-device-1 Quiet',
|
||||||
|
'platform': 'gree',
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': 'aabbcc112233_Quiet',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
}),
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'switch',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'switch.fake_device_1_fresh_air',
|
||||||
|
'has_entity_name': False,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'fake-device-1 Fresh Air',
|
||||||
|
'platform': 'gree',
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': 'aabbcc112233_Fresh Air',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
}),
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'switch',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'switch.fake_device_1_xfan',
|
||||||
|
'has_entity_name': False,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'fake-device-1 XFan',
|
||||||
|
'platform': 'gree',
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': 'aabbcc112233_XFan',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
}),
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
|
||||||
|
'domain': 'switch',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'switch.fake_device_1_health_mode',
|
||||||
|
'has_entity_name': False,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||||
|
'original_icon': 'mdi:pine-tree',
|
||||||
|
'original_name': 'fake-device-1 Health mode',
|
||||||
|
'platform': 'gree',
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': 'aabbcc112233_Health mode',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
# ---
|
@ -1,13 +1,14 @@
|
|||||||
"""Tests for gree component."""
|
"""Tests for gree component."""
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from greeclimate.exceptions import DeviceTimeoutError
|
from greeclimate.exceptions import DeviceTimeoutError
|
||||||
import pytest
|
import pytest
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.gree.const import DOMAIN as GREE_DOMAIN
|
from homeassistant.components.gree.const import DOMAIN as GREE_DOMAIN
|
||||||
from homeassistant.components.switch import DOMAIN
|
from homeassistant.components.switch import DOMAIN
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_FRIENDLY_NAME,
|
|
||||||
SERVICE_TOGGLE,
|
SERVICE_TOGGLE,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
@ -27,21 +28,26 @@ ENTITY_ID_FRESH_AIR = f"{DOMAIN}.fake_device_1_fresh_air"
|
|||||||
ENTITY_ID_XFAN = f"{DOMAIN}.fake_device_1_xfan"
|
ENTITY_ID_XFAN = f"{DOMAIN}.fake_device_1_xfan"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_gree(hass):
|
async def async_setup_gree(hass: HomeAssistant) -> MockConfigEntry:
|
||||||
"""Set up the gree switch platform."""
|
"""Set up the gree switch platform."""
|
||||||
MockConfigEntry(domain=GREE_DOMAIN).add_to_hass(hass)
|
entry = MockConfigEntry(domain=GREE_DOMAIN)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
await async_setup_component(hass, GREE_DOMAIN, {GREE_DOMAIN: {DOMAIN: {}}})
|
await async_setup_component(hass, GREE_DOMAIN, {GREE_DOMAIN: {DOMAIN: {}}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
return entry
|
||||||
|
|
||||||
|
|
||||||
async def test_health_mode_disabled_by_default(hass):
|
@patch("homeassistant.components.gree.PLATFORMS", [DOMAIN])
|
||||||
"""Test for making sure health mode is disabled on first load."""
|
async def test_registry_settings(
|
||||||
await async_setup_gree(hass)
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test for entity registry settings (disabled_by, unique_id)."""
|
||||||
|
entry = await async_setup_gree(hass)
|
||||||
|
|
||||||
assert (
|
state = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
|
||||||
er.async_get(hass).async_get(ENTITY_ID_HEALTH_MODE).disabled_by
|
assert state == snapshot
|
||||||
== er.RegistryEntryDisabler.INTEGRATION
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -183,20 +189,14 @@ async def test_send_switch_toggle(
|
|||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
("entity", "name"),
|
async def test_entity_state(
|
||||||
[
|
hass: HomeAssistant,
|
||||||
(ENTITY_ID_LIGHT_PANEL, "Panel Light"),
|
entity_registry: er.EntityRegistry,
|
||||||
(ENTITY_ID_HEALTH_MODE, "Health mode"),
|
snapshot: SnapshotAssertion,
|
||||||
(ENTITY_ID_QUIET, "Quiet"),
|
|
||||||
(ENTITY_ID_FRESH_AIR, "Fresh Air"),
|
|
||||||
(ENTITY_ID_XFAN, "XFan"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_entity_name(
|
|
||||||
hass: HomeAssistant, entity, name, entity_registry_enabled_by_default: None
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for name property."""
|
"""Test for entity registry settings (disabled_by, unique_id)."""
|
||||||
await async_setup_gree(hass)
|
await async_setup_gree(hass)
|
||||||
state = hass.states.get(entity)
|
|
||||||
assert state.attributes[ATTR_FRIENDLY_NAME] == f"fake-device-1 {name}"
|
state = hass.states.async_all(DOMAIN)
|
||||||
|
assert state == snapshot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user