mirror of
https://github.com/home-assistant/core.git
synced 2026-03-12 14:02:03 +01:00
Compare commits
1 Commits
windows-98
...
add_select
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f532d5aec |
@@ -155,6 +155,7 @@ _EXPERIMENTAL_TRIGGER_PLATFORMS = {
|
||||
"remote",
|
||||
"scene",
|
||||
"schedule",
|
||||
"select",
|
||||
"siren",
|
||||
"switch",
|
||||
"text",
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
],
|
||||
"documentation": "https://www.home-assistant.io/integrations/frontend",
|
||||
"integration_type": "system",
|
||||
"preview_features": { "windows_98": {}, "winter_mode": {} },
|
||||
"preview_features": { "winter_mode": {} },
|
||||
"quality_scale": "internal",
|
||||
"requirements": ["home-assistant-frontend==20260304.0"]
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
{
|
||||
"preview_features": {
|
||||
"windows_98": {
|
||||
"description": "Transforms your dashboard with a nostalgic Windows 98 look.",
|
||||
"disable_confirmation": "Your dashboard will return to its normal look. You can re-enable this at any time in Labs settings.",
|
||||
"enable_confirmation": "Your dashboard will be transformed with a Windows 98 theme. You can turn this off at any time in Labs settings.",
|
||||
"name": "Windows 98"
|
||||
},
|
||||
"winter_mode": {
|
||||
"description": "Adds falling snowflakes on your screen. Get your home ready for winter! ❄️\n\nIf you have animations disabled in your device accessibility settings, this feature will not work.",
|
||||
"disable_confirmation": "Snowflakes will no longer fall on your screen. You can re-enable this at any time in Labs settings.",
|
||||
|
||||
@@ -20,5 +20,10 @@
|
||||
"select_previous": {
|
||||
"service": "mdi:format-list-bulleted"
|
||||
}
|
||||
},
|
||||
"triggers": {
|
||||
"selection_changed": {
|
||||
"trigger": "mdi:format-list-bulleted"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,5 +76,11 @@
|
||||
"name": "Previous"
|
||||
}
|
||||
},
|
||||
"title": "Select"
|
||||
"title": "Select",
|
||||
"triggers": {
|
||||
"selection_changed": {
|
||||
"description": "Triggers after one or more selections change.",
|
||||
"name": "Selection changed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
homeassistant/components/select/trigger.py
Normal file
32
homeassistant/components/select/trigger.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""Provides triggers for selects."""
|
||||
|
||||
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers.trigger import (
|
||||
ENTITY_STATE_TRIGGER_SCHEMA,
|
||||
EntityTriggerBase,
|
||||
Trigger,
|
||||
)
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
class SelectionChangedTrigger(EntityTriggerBase):
|
||||
"""Trigger for select entity when its selection changes."""
|
||||
|
||||
_domains = {DOMAIN}
|
||||
_schema = ENTITY_STATE_TRIGGER_SCHEMA
|
||||
|
||||
def is_valid_state(self, state: State) -> bool:
|
||||
"""Check if the new state is not invalid."""
|
||||
return state.state not in (STATE_UNAVAILABLE, STATE_UNKNOWN)
|
||||
|
||||
|
||||
TRIGGERS: dict[str, type[Trigger]] = {
|
||||
"selection_changed": SelectionChangedTrigger,
|
||||
}
|
||||
|
||||
|
||||
async def async_get_triggers(hass: HomeAssistant) -> dict[str, type[Trigger]]:
|
||||
"""Return the triggers for selects."""
|
||||
return TRIGGERS
|
||||
4
homeassistant/components/select/triggers.yaml
Normal file
4
homeassistant/components/select/triggers.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
selection_changed:
|
||||
target:
|
||||
entity:
|
||||
domain: select
|
||||
@@ -790,6 +790,7 @@ edit_message:
|
||||
filter:
|
||||
domain: notify
|
||||
integration: telegram_bot
|
||||
reorder: true
|
||||
message_id:
|
||||
required: true
|
||||
example: "{{ trigger.event.data.message.message_id }}"
|
||||
@@ -842,6 +843,7 @@ edit_message_media:
|
||||
filter:
|
||||
domain: notify
|
||||
integration: telegram_bot
|
||||
reorder: true
|
||||
message_id:
|
||||
required: true
|
||||
example: "{{ trigger.event.data.message.message_id }}"
|
||||
@@ -920,6 +922,7 @@ edit_caption:
|
||||
filter:
|
||||
domain: notify
|
||||
integration: telegram_bot
|
||||
reorder: true
|
||||
message_id:
|
||||
required: true
|
||||
example: "{{ trigger.event.data.message.message_id }}"
|
||||
@@ -957,6 +960,7 @@ edit_replymarkup:
|
||||
filter:
|
||||
domain: notify
|
||||
integration: telegram_bot
|
||||
reorder: true
|
||||
message_id:
|
||||
required: true
|
||||
example: "{{ trigger.event.data.message.message_id }}"
|
||||
@@ -1011,6 +1015,7 @@ delete_message:
|
||||
filter:
|
||||
domain: notify
|
||||
integration: telegram_bot
|
||||
reorder: true
|
||||
message_id:
|
||||
required: true
|
||||
example: "{{ trigger.event.data.message.message_id }}"
|
||||
@@ -1037,6 +1042,7 @@ leave_chat:
|
||||
filter:
|
||||
domain: notify
|
||||
integration: telegram_bot
|
||||
reorder: true
|
||||
advanced:
|
||||
collapsed: true
|
||||
fields:
|
||||
@@ -1058,6 +1064,7 @@ set_message_reaction:
|
||||
filter:
|
||||
domain: notify
|
||||
integration: telegram_bot
|
||||
reorder: true
|
||||
message_id:
|
||||
required: true
|
||||
example: 54321
|
||||
|
||||
@@ -32,7 +32,7 @@ from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import CONF_HAS_AMBIENT, CONF_PROBE_COUNT, DOMAIN
|
||||
from .const import CONF_PROBE_COUNT, DOMAIN
|
||||
|
||||
type ToGrillConfigEntry = ConfigEntry[ToGrillCoordinator]
|
||||
|
||||
@@ -213,8 +213,6 @@ class ToGrillCoordinator(DataUpdateCoordinator[dict[tuple[int, int | None], Pack
|
||||
await client.request(PacketA1Notify)
|
||||
for probe in range(1, self.config_entry.data[CONF_PROBE_COUNT] + 1):
|
||||
await client.write(PacketA8Write(probe=probe))
|
||||
if self.config_entry.data.get(CONF_HAS_AMBIENT):
|
||||
await client.write(PacketA8Write(probe=0))
|
||||
except BleakError as exc:
|
||||
raise DeviceFailed(f"Device failed {exc}") from exc
|
||||
return self.data
|
||||
|
||||
@@ -27,7 +27,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import ToGrillConfigEntry
|
||||
from .const import CONF_HAS_AMBIENT, CONF_PROBE_COUNT, MAX_PROBE_COUNT
|
||||
from .const import CONF_PROBE_COUNT, MAX_PROBE_COUNT
|
||||
from .coordinator import ToGrillCoordinator
|
||||
from .entity import ToGrillEntity
|
||||
|
||||
@@ -123,64 +123,12 @@ def _get_temperature_descriptions(
|
||||
)
|
||||
|
||||
|
||||
def _get_ambient_temperatures(
|
||||
coordinator: ToGrillCoordinator, alarm_type: AlarmType
|
||||
) -> tuple[float | None, float | None]:
|
||||
if not (packet := coordinator.get_packet(PacketA8Notify, 0)):
|
||||
return None, None
|
||||
if packet.alarm_type != alarm_type:
|
||||
return None, None
|
||||
return packet.temperature_1, packet.temperature_2
|
||||
|
||||
|
||||
ENTITY_DESCRIPTIONS = (
|
||||
*[
|
||||
description
|
||||
for probe_number in range(1, MAX_PROBE_COUNT + 1)
|
||||
for description in _get_temperature_descriptions(probe_number)
|
||||
],
|
||||
ToGrillNumberEntityDescription(
|
||||
key="ambient_temperature_minimum",
|
||||
translation_key="ambient_temperature_minimum",
|
||||
device_class=NumberDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
native_min_value=0,
|
||||
native_max_value=400,
|
||||
mode=NumberMode.BOX,
|
||||
icon="mdi:thermometer-chevron-down",
|
||||
set_packet=lambda coordinator, value: PacketA300Write(
|
||||
probe=0,
|
||||
minimum=None if value == 0.0 else value,
|
||||
maximum=_get_ambient_temperatures(coordinator, AlarmType.TEMPERATURE_RANGE)[
|
||||
1
|
||||
],
|
||||
),
|
||||
get_value=lambda x: _get_ambient_temperatures(x, AlarmType.TEMPERATURE_RANGE)[
|
||||
0
|
||||
],
|
||||
entity_supported=lambda x: x.get(CONF_HAS_AMBIENT, False),
|
||||
),
|
||||
ToGrillNumberEntityDescription(
|
||||
key="ambient_temperature_maximum",
|
||||
translation_key="ambient_temperature_maximum",
|
||||
device_class=NumberDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
native_min_value=0,
|
||||
native_max_value=400,
|
||||
mode=NumberMode.BOX,
|
||||
icon="mdi:thermometer-chevron-up",
|
||||
set_packet=lambda coordinator, value: PacketA300Write(
|
||||
probe=0,
|
||||
minimum=_get_ambient_temperatures(coordinator, AlarmType.TEMPERATURE_RANGE)[
|
||||
0
|
||||
],
|
||||
maximum=None if value == 0.0 else value,
|
||||
),
|
||||
get_value=lambda x: _get_ambient_temperatures(x, AlarmType.TEMPERATURE_RANGE)[
|
||||
1
|
||||
],
|
||||
entity_supported=lambda x: x.get(CONF_HAS_AMBIENT, False),
|
||||
),
|
||||
ToGrillNumberEntityDescription(
|
||||
key="alarm_interval",
|
||||
translation_key="alarm_interval",
|
||||
|
||||
@@ -55,12 +55,6 @@
|
||||
"alarm_interval": {
|
||||
"name": "Alarm interval"
|
||||
},
|
||||
"ambient_temperature_maximum": {
|
||||
"name": "Ambient maximum temperature"
|
||||
},
|
||||
"ambient_temperature_minimum": {
|
||||
"name": "Ambient minimum temperature"
|
||||
},
|
||||
"temperature_maximum": {
|
||||
"name": "Maximum temperature"
|
||||
},
|
||||
|
||||
5
homeassistant/generated/labs.py
generated
5
homeassistant/generated/labs.py
generated
@@ -19,11 +19,6 @@ LABS_PREVIEW_FEATURES = {
|
||||
},
|
||||
},
|
||||
"frontend": {
|
||||
"windows_98": {
|
||||
"feedback_url": "",
|
||||
"learn_more_url": "",
|
||||
"report_issue_url": "",
|
||||
},
|
||||
"winter_mode": {
|
||||
"feedback_url": "",
|
||||
"learn_more_url": "",
|
||||
|
||||
@@ -119,13 +119,6 @@ def _validate_supported_features(supported_features: list[str]) -> int:
|
||||
return feature_mask
|
||||
|
||||
|
||||
def _validate_selector_reorder_config(config: Any) -> Any:
|
||||
"""Validate selectors with reorder option."""
|
||||
if config.get("reorder") and not config.get("multiple"):
|
||||
raise vol.Invalid("reorder can only be used when multiple is true")
|
||||
return config
|
||||
|
||||
|
||||
def make_selector_config_schema(schema_dict: dict | None = None) -> vol.Schema:
|
||||
"""Make selector config schema."""
|
||||
if schema_dict is None:
|
||||
@@ -317,22 +310,19 @@ class AreaSelector(Selector[AreaSelectorConfig]):
|
||||
|
||||
selector_type = "area"
|
||||
|
||||
CONFIG_SCHEMA = vol.All(
|
||||
make_selector_config_schema(
|
||||
{
|
||||
vol.Optional("entity"): vol.All(
|
||||
cv.ensure_list,
|
||||
[ENTITY_FILTER_SELECTOR_CONFIG_SCHEMA],
|
||||
),
|
||||
vol.Optional("device"): vol.All(
|
||||
cv.ensure_list,
|
||||
[DEVICE_FILTER_SELECTOR_CONFIG_SCHEMA],
|
||||
),
|
||||
vol.Optional("multiple", default=False): cv.boolean,
|
||||
vol.Optional("reorder", default=False): cv.boolean,
|
||||
}
|
||||
),
|
||||
_validate_selector_reorder_config,
|
||||
CONFIG_SCHEMA = make_selector_config_schema(
|
||||
{
|
||||
vol.Optional("entity"): vol.All(
|
||||
cv.ensure_list,
|
||||
[ENTITY_FILTER_SELECTOR_CONFIG_SCHEMA],
|
||||
),
|
||||
vol.Optional("device"): vol.All(
|
||||
cv.ensure_list,
|
||||
[DEVICE_FILTER_SELECTOR_CONFIG_SCHEMA],
|
||||
),
|
||||
vol.Optional("multiple", default=False): cv.boolean,
|
||||
vol.Optional("reorder", default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(self, config: AreaSelectorConfig | None = None) -> None:
|
||||
@@ -904,21 +894,18 @@ class EntitySelector(Selector[EntitySelectorConfig]):
|
||||
|
||||
selector_type = "entity"
|
||||
|
||||
CONFIG_SCHEMA = vol.All(
|
||||
make_selector_config_schema(
|
||||
{
|
||||
**_LEGACY_ENTITY_SELECTOR_CONFIG_SCHEMA_DICT,
|
||||
vol.Optional("exclude_entities"): [str],
|
||||
vol.Optional("include_entities"): [str],
|
||||
vol.Optional("multiple", default=False): cv.boolean,
|
||||
vol.Optional("reorder", default=False): cv.boolean,
|
||||
vol.Optional("filter"): vol.All(
|
||||
cv.ensure_list,
|
||||
[ENTITY_FILTER_SELECTOR_CONFIG_SCHEMA],
|
||||
),
|
||||
}
|
||||
),
|
||||
_validate_selector_reorder_config,
|
||||
CONFIG_SCHEMA = make_selector_config_schema(
|
||||
{
|
||||
**_LEGACY_ENTITY_SELECTOR_CONFIG_SCHEMA_DICT,
|
||||
vol.Optional("exclude_entities"): [str],
|
||||
vol.Optional("include_entities"): [str],
|
||||
vol.Optional("multiple", default=False): cv.boolean,
|
||||
vol.Optional("reorder", default=False): cv.boolean,
|
||||
vol.Optional("filter"): vol.All(
|
||||
cv.ensure_list,
|
||||
[ENTITY_FILTER_SELECTOR_CONFIG_SCHEMA],
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(self, config: EntitySelectorConfig | None = None) -> None:
|
||||
|
||||
126
tests/components/select/test_trigger.py
Normal file
126
tests/components/select/test_trigger.py
Normal file
@@ -0,0 +1,126 @@
|
||||
"""Test select trigger."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_LABEL_ID,
|
||||
CONF_ENTITY_ID,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
|
||||
from tests.components import (
|
||||
TriggerStateDescription,
|
||||
arm_trigger,
|
||||
parametrize_target_entities,
|
||||
set_or_remove_state,
|
||||
target_entities,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def target_selects(hass: HomeAssistant) -> list[str]:
|
||||
"""Create multiple select entities associated with different targets."""
|
||||
return (await target_entities(hass, "select"))["included"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("trigger_key", ["select.selection_changed"])
|
||||
async def test_select_triggers_gated_by_labs_flag(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, trigger_key: str
|
||||
) -> None:
|
||||
"""Test the select triggers are gated by the labs flag."""
|
||||
await arm_trigger(hass, trigger_key, None, {ATTR_LABEL_ID: "test_label"})
|
||||
assert (
|
||||
"Unnamed automation failed to setup triggers and has been disabled: Trigger "
|
||||
f"'{trigger_key}' requires the experimental 'New triggers and conditions' "
|
||||
"feature to be enabled in Home Assistant Labs settings (feature flag: "
|
||||
"'new_triggers_conditions')"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_target_config", "entity_id", "entities_in_target"),
|
||||
parametrize_target_entities("select"),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("trigger", "states"),
|
||||
[
|
||||
(
|
||||
"select.selection_changed",
|
||||
[
|
||||
{"included": {"state": None, "attributes": {}}, "count": 0},
|
||||
{"included": {"state": "option_a", "attributes": {}}, "count": 0},
|
||||
{"included": {"state": "option_b", "attributes": {}}, "count": 1},
|
||||
],
|
||||
),
|
||||
(
|
||||
"select.selection_changed",
|
||||
[
|
||||
{"included": {"state": "option_a", "attributes": {}}, "count": 0},
|
||||
{"included": {"state": "option_b", "attributes": {}}, "count": 1},
|
||||
{"included": {"state": "option_c", "attributes": {}}, "count": 1},
|
||||
],
|
||||
),
|
||||
(
|
||||
"select.selection_changed",
|
||||
[
|
||||
{
|
||||
"included": {"state": STATE_UNAVAILABLE, "attributes": {}},
|
||||
"count": 0,
|
||||
},
|
||||
{"included": {"state": "option_a", "attributes": {}}, "count": 0},
|
||||
{"included": {"state": "option_b", "attributes": {}}, "count": 1},
|
||||
{
|
||||
"included": {"state": STATE_UNAVAILABLE, "attributes": {}},
|
||||
"count": 0,
|
||||
},
|
||||
],
|
||||
),
|
||||
(
|
||||
"select.selection_changed",
|
||||
[
|
||||
{"included": {"state": STATE_UNKNOWN, "attributes": {}}, "count": 0},
|
||||
{"included": {"state": "option_a", "attributes": {}}, "count": 0},
|
||||
{"included": {"state": "option_b", "attributes": {}}, "count": 1},
|
||||
{"included": {"state": STATE_UNKNOWN, "attributes": {}}, "count": 0},
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_select_state_trigger_behavior_any(
|
||||
hass: HomeAssistant,
|
||||
service_calls: list[ServiceCall],
|
||||
target_selects: list[str],
|
||||
trigger_target_config: dict,
|
||||
entity_id: str,
|
||||
entities_in_target: int,
|
||||
trigger: str,
|
||||
states: list[TriggerStateDescription],
|
||||
) -> None:
|
||||
"""Test that the select trigger fires when any select state changes."""
|
||||
other_entity_ids = set(target_selects) - {entity_id}
|
||||
|
||||
# Set all selects, including the tested select, to the initial state
|
||||
for eid in target_selects:
|
||||
set_or_remove_state(hass, eid, states[0]["included"])
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await arm_trigger(hass, trigger, None, trigger_target_config)
|
||||
|
||||
for state in states[1:]:
|
||||
included_state = state["included"]
|
||||
set_or_remove_state(hass, entity_id, included_state)
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == state["count"]
|
||||
for service_call in service_calls:
|
||||
assert service_call.data[CONF_ENTITY_ID] == entity_id
|
||||
service_calls.clear()
|
||||
|
||||
# Check if changing other selects also triggers
|
||||
for other_entity_id in other_entity_ids:
|
||||
set_or_remove_state(hass, other_entity_id, included_state)
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == (entities_in_target - 1) * state["count"]
|
||||
service_calls.clear()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -77,150 +77,6 @@ async def test_setup(
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"packets",
|
||||
[
|
||||
pytest.param([], id="no_data"),
|
||||
pytest.param(
|
||||
[
|
||||
PacketA8Notify(
|
||||
probe=0,
|
||||
alarm_type=PacketA8Notify.AlarmType.TEMPERATURE_RANGE,
|
||||
temperature_1=5.0,
|
||||
temperature_2=300.0,
|
||||
),
|
||||
],
|
||||
id="ambient_with_range",
|
||||
),
|
||||
pytest.param(
|
||||
[
|
||||
PacketA8Notify(
|
||||
probe=0,
|
||||
alarm_type=None,
|
||||
temperature_1=5.0,
|
||||
temperature_2=300.0,
|
||||
),
|
||||
],
|
||||
id="ambient_wrong_alarm_type",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_setup_with_ambient(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_entry_with_ambient: MockConfigEntry,
|
||||
mock_client: Mock,
|
||||
packets,
|
||||
) -> None:
|
||||
"""Test the numbers with ambient sensor enabled."""
|
||||
|
||||
inject_bluetooth_service_info(hass, TOGRILL_SERVICE_INFO)
|
||||
|
||||
await setup_entry(hass, mock_entry_with_ambient, [Platform.NUMBER])
|
||||
|
||||
for packet in packets:
|
||||
mock_client.mocked_notify(packet)
|
||||
|
||||
await snapshot_platform(
|
||||
hass, entity_registry, snapshot, mock_entry_with_ambient.entry_id
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("packets", "entity_id", "value", "write_packet"),
|
||||
[
|
||||
pytest.param(
|
||||
[
|
||||
PacketA8Notify(
|
||||
probe=0,
|
||||
alarm_type=PacketA8Notify.AlarmType.TEMPERATURE_RANGE,
|
||||
temperature_1=5.0,
|
||||
temperature_2=300.0,
|
||||
),
|
||||
],
|
||||
"number.pro_05_ambient_minimum_temperature",
|
||||
10.0,
|
||||
PacketA300Write(probe=0, minimum=10.0, maximum=300.0),
|
||||
id="ambient_minimum",
|
||||
),
|
||||
pytest.param(
|
||||
[
|
||||
PacketA8Notify(
|
||||
probe=0,
|
||||
alarm_type=PacketA8Notify.AlarmType.TEMPERATURE_RANGE,
|
||||
temperature_1=5.0,
|
||||
temperature_2=300.0,
|
||||
),
|
||||
],
|
||||
"number.pro_05_ambient_minimum_temperature",
|
||||
0.0,
|
||||
PacketA300Write(probe=0, minimum=None, maximum=300.0),
|
||||
id="ambient_minimum_clear",
|
||||
),
|
||||
pytest.param(
|
||||
[
|
||||
PacketA8Notify(
|
||||
probe=0,
|
||||
alarm_type=PacketA8Notify.AlarmType.TEMPERATURE_RANGE,
|
||||
temperature_1=5.0,
|
||||
temperature_2=300.0,
|
||||
),
|
||||
],
|
||||
"number.pro_05_ambient_maximum_temperature",
|
||||
350.0,
|
||||
PacketA300Write(probe=0, minimum=5.0, maximum=350.0),
|
||||
id="ambient_maximum",
|
||||
),
|
||||
pytest.param(
|
||||
[
|
||||
PacketA8Notify(
|
||||
probe=0,
|
||||
alarm_type=PacketA8Notify.AlarmType.TEMPERATURE_RANGE,
|
||||
temperature_1=5.0,
|
||||
temperature_2=300.0,
|
||||
),
|
||||
],
|
||||
"number.pro_05_ambient_maximum_temperature",
|
||||
0.0,
|
||||
PacketA300Write(probe=0, minimum=5.0, maximum=None),
|
||||
id="ambient_maximum_clear",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_set_ambient_number(
|
||||
hass: HomeAssistant,
|
||||
mock_entry_with_ambient: MockConfigEntry,
|
||||
mock_client: Mock,
|
||||
packets,
|
||||
entity_id,
|
||||
value,
|
||||
write_packet,
|
||||
) -> None:
|
||||
"""Test setting ambient temperature numbers."""
|
||||
|
||||
inject_bluetooth_service_info(hass, TOGRILL_SERVICE_INFO)
|
||||
|
||||
await setup_entry(hass, mock_entry_with_ambient, [Platform.NUMBER])
|
||||
|
||||
for packet in packets:
|
||||
mock_client.mocked_notify(packet)
|
||||
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
service_data={
|
||||
ATTR_VALUE: value,
|
||||
},
|
||||
target={
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mock_client.write.assert_any_call(write_packet)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("packets", "entity_id", "value", "write_packet"),
|
||||
[
|
||||
|
||||
@@ -319,9 +319,6 @@ def test_entity_selector_schema(schema, valid_selections, invalid_selections) ->
|
||||
{"filter": [{"supported_features": ["light.LightEntityFeature.blah"]}]},
|
||||
# supported_features should be used under the filter key
|
||||
{"supported_features": ["light.LightEntityFeature.EFFECT"]},
|
||||
# reorder can only be used when multiple is true
|
||||
{"reorder": True},
|
||||
{"reorder": True, "multiple": False},
|
||||
],
|
||||
)
|
||||
def test_entity_selector_schema_error(schema) -> None:
|
||||
@@ -397,20 +394,6 @@ def test_area_selector_schema(schema, valid_selections, invalid_selections) -> N
|
||||
_test_selector("area", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"schema",
|
||||
[
|
||||
# reorder can only be used when multiple is true
|
||||
{"reorder": True},
|
||||
{"reorder": True, "multiple": False},
|
||||
],
|
||||
)
|
||||
def test_area_selector_schema_error(schema) -> None:
|
||||
"""Test area selector."""
|
||||
with pytest.raises(vol.Invalid):
|
||||
selector.validate_selector({"area": schema})
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("schema", "valid_selections", "invalid_selections"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user