mirror of
https://github.com/home-assistant/core.git
synced 2026-07-01 11:46:40 +01:00
e99cb27015
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
85 lines
2.4 KiB
Python
85 lines
2.4 KiB
Python
"""Blebox button entities tests."""
|
|
|
|
import logging
|
|
from unittest.mock import PropertyMock
|
|
|
|
import blebox_uniapi
|
|
import pytest
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import entity_registry as er
|
|
|
|
from .conftest import async_setup_entity, mock_feature
|
|
|
|
query_translation_key_matching = [
|
|
("up", "up"),
|
|
("down", "down"),
|
|
("fav", "fav"),
|
|
("open", "open"),
|
|
("close", "close"),
|
|
("unknown_action", None),
|
|
]
|
|
|
|
|
|
@pytest.fixture(name="tvliftbox")
|
|
def tv_lift_box_fixture(caplog: pytest.LogCaptureFixture):
|
|
"""Return simple button entity mock."""
|
|
caplog.set_level(logging.ERROR)
|
|
|
|
feature = mock_feature(
|
|
"buttons",
|
|
blebox_uniapi.button.Button,
|
|
unique_id="BleBox-tvLiftBox-4a3fdaad90aa-open_or_stop",
|
|
full_name="tvLiftBox-open_or_stop",
|
|
control_type=blebox_uniapi.button.ControlType.OPEN,
|
|
)
|
|
|
|
product = feature.product
|
|
type(product).name = PropertyMock(return_value="My tvLiftBox")
|
|
type(product).model = PropertyMock(return_value="tvLiftBox")
|
|
type(product)._query_string = PropertyMock(return_value="open_or_stop")
|
|
|
|
return (feature, "button.my_tvliftbox")
|
|
|
|
|
|
async def test_tvliftbox_init(
|
|
tvliftbox, hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
|
) -> None:
|
|
"""Test tvLiftBox initialisation."""
|
|
caplog.set_level(logging.ERROR)
|
|
|
|
_, entity_id = tvliftbox
|
|
entry = await async_setup_entity(hass, entity_id)
|
|
state = hass.states.get(entity_id)
|
|
|
|
assert entry.unique_id == "BleBox-tvLiftBox-4a3fdaad90aa-open_or_stop"
|
|
|
|
assert state.name == "My tvLiftBox"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("query_string", "expected_translation_key"),
|
|
query_translation_key_matching,
|
|
ids=[q[0] for q in query_translation_key_matching],
|
|
)
|
|
async def test_button_translation_key(
|
|
query_string: str,
|
|
expected_translation_key: str | None,
|
|
tvliftbox: tuple[blebox_uniapi.button.Button, str],
|
|
hass: HomeAssistant,
|
|
caplog: pytest.LogCaptureFixture,
|
|
) -> None:
|
|
"""Test that the correct translation_key is assigned based on query_string."""
|
|
caplog.set_level(logging.ERROR)
|
|
|
|
feature_mock, entity_id = tvliftbox
|
|
feature_mock.query_string = query_string
|
|
await async_setup_entity(hass, entity_id)
|
|
|
|
state = hass.states.get(entity_id)
|
|
assert state is not None
|
|
|
|
entity = er.async_get(hass).async_get(entity_id)
|
|
assert entity is not None
|
|
assert entity.translation_key == expected_translation_key
|