Files
ha-ninlight/tests/test_number.py
T

50 lines
1.6 KiB
Python

"""Fade and transition settings."""
from __future__ import annotations
from unittest.mock import MagicMock
from homeassistant.components.number import ATTR_VALUE, SERVICE_SET_VALUE
from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, ATTR_UNIT_OF_MEASUREMENT, UnitOfTime
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity import EntityCategory
import pytest
from tests.helpers import entity_id_for
@pytest.mark.parametrize(
("key", "initial", "new", "maximum"),
[
("fade_in", "450", 1300, 10000),
("fade_out", "1250", 3350, 10000),
("transition_default", "700", 42050, 60000),
],
)
async def test_number_reads_and_writes_its_field(
hass: HomeAssistant,
init_integration,
mock_client: MagicMock,
key: str,
initial: str,
new: int,
maximum: int,
) -> None:
entity_id = entity_id_for(hass, "number", key)
state = hass.states.get(entity_id)
assert state.state == initial
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTime.MILLISECONDS
assert state.attributes["max"] == maximum
assert er.async_get(hass).async_get(entity_id).entity_category is EntityCategory.CONFIG
await hass.services.async_call(
NUMBER_DOMAIN,
SERVICE_SET_VALUE,
{ATTR_ENTITY_ID: entity_id, ATTR_VALUE: new},
blocking=True,
)
mock_client.set_state.assert_awaited_once_with(**{key: new})
assert hass.states.get(entity_id).state == str(new)