further test and small fixes

This commit is contained in:
Taraman17 2025-02-05 08:59:05 +00:00
parent 3299bb914a
commit d8bb74c4b6
3 changed files with 629 additions and 6 deletions

View File

@ -201,7 +201,7 @@
"switch_type": {
"name": "Switch Type"
},
"ventilate_ipulse": {
"ventilate_impulse": {
"name": "Ventilate Impulse"
},
"watchdog_on_off": {

View File

@ -0,0 +1,564 @@
# serializer version: 1
# name: test_switch_snapshot[switch.homee_00055511eecc_1_11-entry]
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.homee_00055511eecc_1_11',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.OUTLET: 'outlet'>,
'original_icon': None,
'original_name': None,
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00055511EECC-1-11',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.homee_00055511eecc_1_11-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'outlet',
}),
'context': <ANY>,
'entity_id': 'switch.homee_00055511eecc_1_11',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_snapshot[switch.none_identification_mode-entry]
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': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'switch.none_identification_mode',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Identification Mode',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'identification_mode',
'unique_id': '00055511EECC-1-4',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_identification_mode-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Identification Mode',
}),
'context': <ANY>,
'entity_id': 'switch.none_identification_mode',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_switch_snapshot[switch.none_impulse_1-entry]
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.none_impulse_1',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Impulse 1',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'impulse_instance',
'unique_id': '00055511EECC-1-5',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_impulse_1-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Impulse 1',
}),
'context': <ANY>,
'entity_id': 'switch.none_impulse_1',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_snapshot[switch.none_impulse_2-entry]
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.none_impulse_2',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Impulse 2',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'impulse_instance',
'unique_id': '00055511EECC-1-6',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_impulse_2-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Impulse 2',
}),
'context': <ANY>,
'entity_id': 'switch.none_impulse_2',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_snapshot[switch.none_light_impulse-entry]
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.none_light_impulse',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Light Impulse',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'light_impulse',
'unique_id': '00055511EECC-1-7',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_light_impulse-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Light Impulse',
}),
'context': <ANY>,
'entity_id': 'switch.none_light_impulse',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_snapshot[switch.none_manual_operation-entry]
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.none_manual_operation',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Manual Operation',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'manual_operation',
'unique_id': '00055511EECC-1-8',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_manual_operation-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Manual Operation',
}),
'context': <ANY>,
'entity_id': 'switch.none_manual_operation',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_snapshot[switch.none_motor_rotation_direction-entry]
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': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.none_motor_rotation_direction',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Motor rotation direction',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'motor_rotation',
'unique_id': '00055511EECC-1-9',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_motor_rotation_direction-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Motor rotation direction',
}),
'context': <ANY>,
'entity_id': 'switch.none_motor_rotation_direction',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_snapshot[switch.none_open_partial_impulse-entry]
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.none_open_partial_impulse',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Open Partial Impulse',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'open_partial_impulse',
'unique_id': '00055511EECC-1-10',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_open_partial_impulse-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Open Partial Impulse',
}),
'context': <ANY>,
'entity_id': 'switch.none_open_partial_impulse',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_snapshot[switch.none_reset_meter_1-entry]
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': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.none_reset_meter_1',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Reset Meter 1',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'reset_meter_instance',
'unique_id': '00055511EECC-1-13',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_reset_meter_1-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Reset Meter 1',
}),
'context': <ANY>,
'entity_id': 'switch.none_reset_meter_1',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_snapshot[switch.none_restore_last_known_state-entry]
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': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.none_restore_last_known_state',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Restore last known state',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'restore_last_known_state',
'unique_id': '00055511EECC-1-14',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_restore_last_known_state-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Restore last known state',
}),
'context': <ANY>,
'entity_id': 'switch.none_restore_last_known_state',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_switch_snapshot[switch.none_ventilate_impulse-entry]
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.none_ventilate_impulse',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Ventilate Impulse',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'ventilate_impulse',
'unique_id': '00055511EECC-1-17',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_ventilate_impulse-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Ventilate Impulse',
}),
'context': <ANY>,
'entity_id': 'switch.none_ventilate_impulse',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_snapshot[switch.none_watchdog-entry]
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': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.none_watchdog',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'Watchdog',
'platform': 'homee',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'watchdog_on_off',
'unique_id': '00055511EECC-1-18',
'unit_of_measurement': None,
})
# ---
# name: test_switch_snapshot[switch.none_watchdog-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Watchdog',
}),
'context': <ANY>,
'entity_id': 'switch.none_watchdog',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---

View File

@ -1,18 +1,23 @@
"""Test Homee switches."""
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.switch import (
DOMAIN as SWITCH_DOMAIN,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
SwitchDeviceClass,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.const import ATTR_ENTITY_ID, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import build_mock_node, setup_integration
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, snapshot_platform
async def test_switch_on(
@ -24,6 +29,7 @@ async def test_switch_on(
mock_homee.nodes = [build_mock_node("switches.json")]
await setup_integration(hass, mock_config_entry)
assert hass.states.get("switch.test_switch").state is not STATE_ON
await hass.services.async_call(
SWITCH_DOMAIN,
SERVICE_TURN_ON,
@ -31,7 +37,7 @@ async def test_switch_on(
blocking=True,
)
assert mock_homee.set_value.assert_called_once_with(1, 11, 1)
mock_homee.set_value.assert_called_once_with(1, 11, 1)
async def test_switch_off(
@ -43,11 +49,64 @@ async def test_switch_off(
mock_homee.nodes = [build_mock_node("switches.json")]
await setup_integration(hass, mock_config_entry)
assert hass.states.get("switch.test_switch_identification_mode").state is STATE_ON
await hass.services.async_call(
SWITCH_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: "switch.test_switch_identification_mode"},
blocking=True,
)
mock_homee.set_value.assert_called_once_with(1, 4, 0)
assert mock_homee.set_value.assert_called_once_with(1, 4, 0)
async def test_switch_device_class(
hass: HomeAssistant,
mock_homee: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test if device class gets set correctly."""
mock_homee.nodes = [build_mock_node("switches.json")]
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
await setup_integration(hass, mock_config_entry)
assert (
hass.states.get("switch.test_switch").attributes["device_class"]
== SwitchDeviceClass.OUTLET
)
assert (
hass.states.get("switch.test_switch_impulse_2").attributes["device_class"]
== SwitchDeviceClass.SWITCH
)
async def test_switch_device_class_no_outlet(
hass: HomeAssistant,
mock_homee: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test if on_off device class gets set correctly if node-profile is not a plug."""
mock_homee.nodes = [build_mock_node("switches.json")]
mock_homee.nodes[0].profile = 2002
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
await setup_integration(hass, mock_config_entry)
assert (
hass.states.get("switch.test_switch").attributes["device_class"]
== SwitchDeviceClass.SWITCH
)
async def test_switch_snapshot(
hass: HomeAssistant,
mock_homee: MagicMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test the multisensor snapshot."""
mock_homee.nodes = [build_mock_node("switches.json")]
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
with patch("homeassistant.components.homee.PLATFORMS", [Platform.SWITCH]):
await setup_integration(hass, mock_config_entry)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)