1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-02 04:06:41 +01:00
Files
core/tests/components/ohme/test_number.py
T
2026-05-02 00:11:41 +02:00

98 lines
2.6 KiB
Python

"""Tests for numbers."""
from unittest.mock import MagicMock, patch
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.number import (
ATTR_VALUE,
DOMAIN as NUMBER_DOMAIN,
SERVICE_SET_VALUE,
)
from homeassistant.const import ATTR_ENTITY_ID, 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_numbers(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
mock_config_entry: MockConfigEntry,
mock_client: MagicMock,
) -> None:
"""Test the Ohme numbers."""
with patch("homeassistant.components.ohme.PLATFORMS", [Platform.NUMBER]):
await setup_integration(hass, mock_config_entry)
entity_registry.async_update_entity(
"number.ohme_home_pro_state_of_charge_input",
disabled_by=None,
)
with patch("homeassistant.components.ohme.PLATFORMS", [Platform.NUMBER]):
await hass.config_entries.async_reload(mock_config_entry.entry_id)
await hass.async_block_till_done()
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
async def test_set_target_percentage(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_client: MagicMock,
) -> None:
"""Test the number set."""
await setup_integration(hass, mock_config_entry)
await hass.services.async_call(
NUMBER_DOMAIN,
SERVICE_SET_VALUE,
service_data={
ATTR_VALUE: 100,
},
target={
ATTR_ENTITY_ID: "number.ohme_home_pro_target_percentage",
},
blocking=True,
)
assert len(mock_client.async_set_target.mock_calls) == 1
async def test_set_state_of_charge_input(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
mock_client: MagicMock,
) -> None:
"""Test the number set."""
await setup_integration(hass, mock_config_entry)
entity_registry.async_update_entity(
"number.ohme_home_pro_state_of_charge_input",
disabled_by=None,
)
await hass.config_entries.async_reload(mock_config_entry.entry_id)
await hass.async_block_till_done()
await hass.services.async_call(
NUMBER_DOMAIN,
SERVICE_SET_VALUE,
service_data={
ATTR_VALUE: 100,
},
target={
ATTR_ENTITY_ID: "number.ohme_home_pro_state_of_charge_input",
},
blocking=True,
)
assert len(mock_client.async_set_state_of_charge.mock_calls) == 1