forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add velbus cover platform testcases (home-assistant#134654)
- Loading branch information
Showing
3 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# serializer version: 1 | ||
# name: test_entities[cover.covername-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': None, | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'cover', | ||
'entity_category': None, | ||
'entity_id': 'cover.covername', | ||
'has_entity_name': False, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'labels': set({ | ||
}), | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': None, | ||
'original_icon': None, | ||
'original_name': 'CoverName', | ||
'platform': 'velbus', | ||
'previous_unique_id': None, | ||
'supported_features': <CoverEntityFeature: 15>, | ||
'translation_key': None, | ||
'unique_id': '1234-2', | ||
'unit_of_measurement': None, | ||
}) | ||
# --- | ||
# name: test_entities[cover.covername-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'current_position': 50, | ||
'friendly_name': 'CoverName', | ||
'supported_features': <CoverEntityFeature: 15>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'cover.covername', | ||
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': 'open', | ||
}) | ||
# --- | ||
# name: test_entities[cover.covernamenopos-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': None, | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'cover', | ||
'entity_category': None, | ||
'entity_id': 'cover.covernamenopos', | ||
'has_entity_name': False, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'labels': set({ | ||
}), | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': None, | ||
'original_icon': None, | ||
'original_name': 'CoverNameNoPos', | ||
'platform': 'velbus', | ||
'previous_unique_id': None, | ||
'supported_features': <CoverEntityFeature: 11>, | ||
'translation_key': None, | ||
'unique_id': '12345-1', | ||
'unit_of_measurement': None, | ||
}) | ||
# --- | ||
# name: test_entities[cover.covernamenopos-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'assumed_state': True, | ||
'friendly_name': 'CoverNameNoPos', | ||
'supported_features': <CoverEntityFeature: 11>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'cover.covernamenopos', | ||
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': 'opening', | ||
}) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"""Velbus cover platform tests.""" | ||
|
||
from unittest.mock import AsyncMock, patch | ||
|
||
import pytest | ||
from syrupy.assertion import SnapshotAssertion | ||
|
||
from homeassistant.components.cover import ATTR_POSITION, DOMAIN as COVER_DOMAIN | ||
from homeassistant.const import ( | ||
ATTR_ENTITY_ID, | ||
SERVICE_CLOSE_COVER, | ||
SERVICE_OPEN_COVER, | ||
SERVICE_SET_COVER_POSITION, | ||
SERVICE_STOP_COVER, | ||
Platform, | ||
) | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import entity_registry as er | ||
|
||
from . import init_integration | ||
|
||
from tests.common import MockConfigEntry, snapshot_platform | ||
|
||
|
||
async def test_entities( | ||
hass: HomeAssistant, | ||
snapshot: SnapshotAssertion, | ||
config_entry: MockConfigEntry, | ||
entity_registry: er.EntityRegistry, | ||
) -> None: | ||
"""Test all entities.""" | ||
with patch("homeassistant.components.velbus.PLATFORMS", [Platform.COVER]): | ||
await init_integration(hass, config_entry) | ||
|
||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("entity_id", "entity_num"), | ||
[ | ||
("cover.covername", 0), | ||
("cover.covernamenopos", 1), | ||
], | ||
) | ||
async def test_actions( | ||
hass: HomeAssistant, | ||
config_entry: MockConfigEntry, | ||
entity_id: str, | ||
entity_num: int, | ||
) -> None: | ||
"""Test the cover actions.""" | ||
await init_integration(hass, config_entry) | ||
entity = config_entry.runtime_data.controller.get_all_cover()[entity_num] | ||
await hass.services.async_call( | ||
COVER_DOMAIN, | ||
SERVICE_CLOSE_COVER, | ||
{ATTR_ENTITY_ID: entity_id}, | ||
blocking=True, | ||
) | ||
entity.close.assert_called_once() | ||
await hass.services.async_call( | ||
COVER_DOMAIN, | ||
SERVICE_OPEN_COVER, | ||
{ATTR_ENTITY_ID: entity_id}, | ||
blocking=True, | ||
) | ||
entity.open.assert_called_once() | ||
await hass.services.async_call( | ||
COVER_DOMAIN, | ||
SERVICE_STOP_COVER, | ||
{ATTR_ENTITY_ID: entity_id}, | ||
blocking=True, | ||
) | ||
entity.stop.assert_called_once() | ||
|
||
|
||
async def test_position( | ||
hass: HomeAssistant, | ||
config_entry: MockConfigEntry, | ||
mock_cover: AsyncMock, | ||
) -> None: | ||
"""Test the set_postion over action.""" | ||
await init_integration(hass, config_entry) | ||
await hass.services.async_call( | ||
COVER_DOMAIN, | ||
SERVICE_SET_COVER_POSITION, | ||
{ATTR_ENTITY_ID: "cover.covername", ATTR_POSITION: 25}, | ||
blocking=True, | ||
) | ||
mock_cover.set_position.assert_called_once_with(75) |