-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dad2bae
commit a808e71
Showing
2 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
tests/components/niko_home_control/snapshots/test_cover.ambr
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,108 @@ | ||
# serializer version: 1 | ||
# name: test_entities[cover.cover-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.cover', | ||
'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': 'dimmable cover', | ||
'platform': 'niko_home_control', | ||
'previous_unique_id': None, | ||
'supported_features': 0, | ||
'translation_key': None, | ||
'unique_id': '01JFN93M7KRA38V5AMPCJ2JYYV-2', | ||
'unit_of_measurement': None, | ||
}) | ||
# --- | ||
# name: test_entities[cover.cover-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'brightness': 255, | ||
'color_mode': <ColorMode.BRIGHTNESS: 'brightness'>, | ||
'friendly_name': 'dimmable cover', | ||
'supported_color_modes': list([ | ||
<ColorMode.BRIGHTNESS: 'brightness'>, | ||
]), | ||
'supported_features': <CoverEntityFeature: 255>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'cover.cover', | ||
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': 'open', | ||
}) | ||
# --- | ||
# name: test_entities[cover.cover-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': dict({ | ||
'supported_color_modes': list([ | ||
<ColorMode.ONOFF: 'onoff'>, | ||
]), | ||
}), | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'cover', | ||
'entity_category': None, | ||
'entity_id': 'cover.cover', | ||
'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': 'cover', | ||
'platform': 'niko_home_control', | ||
'previous_unique_id': None, | ||
'supported_features': 0, | ||
'translation_key': None, | ||
'unique_id': '01JFN93M7KRA38V5AMPCJ2JYYV-1', | ||
'unit_of_measurement': None, | ||
}) | ||
# --- | ||
# name: test_entities[cover.cover-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'color_mode': <ColorMode.ONOFF: 'onoff'>, | ||
'friendly_name': 'cover', | ||
'supported_color_modes': list([ | ||
<ColorMode.ONOFF: 'onoff'>, | ||
]), | ||
'supported_features': <CoverEntityFeature: 255>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'cover.cover', | ||
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': 'open', | ||
}) | ||
# --- |
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,123 @@ | ||
"""Tests for the Niko Home Control Light platform.""" | ||
|
||
from unittest.mock import AsyncMock, patch | ||
|
||
import pytest | ||
from syrupy import SnapshotAssertion | ||
|
||
from homeassistant.components.cover import DOMAIN as COVER_DOMAIN | ||
from homeassistant.const import ( | ||
ATTR_ENTITY_ID, | ||
SERVICE_CLOSE_COVER, | ||
SERVICE_OPEN_COVER, | ||
Platform, | ||
) | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import entity_registry as er | ||
|
||
from . import setup_integration | ||
|
||
from tests.common import MockConfigEntry, snapshot_platform | ||
|
||
|
||
async def test_cover( | ||
hass: HomeAssistant, | ||
snapshot: SnapshotAssertion, | ||
mock_niko_home_control_connection: AsyncMock, | ||
mock_config_entry: MockConfigEntry, | ||
entity_registry: er.EntityRegistry, | ||
) -> None: | ||
"""Test all entities.""" | ||
with patch( | ||
"homeassistant.components.niko_home_control.PLATFORMS", [Platform.COVER] | ||
): | ||
await setup_integration(hass, mock_config_entry) | ||
|
||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) | ||
Check failure on line 36 in tests/components/niko_home_control/test_cover.py GitHub Actions / Run tests Python 3.12 (niko_home_control)
|
||
|
||
|
||
@pytest.mark.parametrize( | ||
("cover_id", "entity_id"), | ||
[ | ||
(0, "cover.cover"), | ||
], | ||
) | ||
async def test_open_cover( | ||
hass: HomeAssistant, | ||
mock_niko_home_control_connection: AsyncMock, | ||
mock_config_entry: MockConfigEntry, | ||
cover_id: int, | ||
entity_id: int, | ||
) -> None: | ||
"""Test opening the cover.""" | ||
await setup_integration(hass, mock_config_entry) | ||
|
||
await hass.services.async_call( | ||
Check failure on line 55 in tests/components/niko_home_control/test_cover.py GitHub Actions / Run tests Python 3.12 (niko_home_control)
|
||
COVER_DOMAIN, | ||
SERVICE_OPEN_COVER, | ||
{ATTR_ENTITY_ID: entity_id}, | ||
blocking=True, | ||
) | ||
mock_niko_home_control_connection.covers[ | ||
cover_id | ||
].open_cover().assert_called_once_with(set_position=100) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("cover_id", "entity_id"), | ||
[ | ||
(0, "cover.cover"), | ||
], | ||
) | ||
async def test_close_cover( | ||
hass: HomeAssistant, | ||
mock_niko_home_control_connection: AsyncMock, | ||
mock_config_entry: MockConfigEntry, | ||
cover_id: int, | ||
entity_id: str, | ||
) -> None: | ||
"""Test closing the cover.""" | ||
await setup_integration(hass, mock_config_entry) | ||
|
||
await hass.services.async_call( | ||
Check failure on line 82 in tests/components/niko_home_control/test_cover.py GitHub Actions / Run tests Python 3.12 (niko_home_control)
|
||
COVER_DOMAIN, | ||
SERVICE_CLOSE_COVER, | ||
{ATTR_ENTITY_ID: entity_id}, | ||
blocking=True, | ||
) | ||
mock_niko_home_control_connection.covers[ | ||
cover_id | ||
].close_cover.assert_called_once_with() | ||
|
||
|
||
async def test_updating( | ||
hass: HomeAssistant, | ||
mock_niko_home_control_connection: AsyncMock, | ||
mock_config_entry: MockConfigEntry, | ||
) -> None: | ||
"""Test turning on the light.""" | ||
await setup_integration(hass, mock_config_entry) | ||
|
||
# assert hass.states.get("light.light").state == STATE_ON | ||
|
||
# await mock_niko_home_control_connection.register_callback.call_args_list[0][0][1](0) | ||
# await hass.async_block_till_done() | ||
|
||
# assert hass.states.get("light.light").state == STATE_OFF | ||
|
||
# assert hass.states.get("light.dimmable_light").state == STATE_ON | ||
# assert hass.states.get("light.dimmable_light").attributes[ATTR_BRIGHTNESS] == 255 | ||
|
||
# await mock_niko_home_control_connection.register_callback.call_args_list[1][0][1]( | ||
# 80 | ||
# ) | ||
# await hass.async_block_till_done() | ||
|
||
# assert hass.states.get("light.dimmable_light").state == STATE_ON | ||
# assert hass.states.get("light.dimmable_light").attributes[ATTR_BRIGHTNESS] == 204 | ||
|
||
# await mock_niko_home_control_connection.register_callback.call_args_list[1][0][1](0) | ||
# await hass.async_block_till_done() | ||
|
||
# assert hass.states.get("light.dimmable_light").state == STATE_OFF | ||
# assert hass.states.get("light.dimmable_light").attributes[ATTR_BRIGHTNESS] is None |