mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 00:20:30 +01:00
Remove number entity support from power triggers and conditions (#166597)
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN, NumberDeviceClass
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
|
||||
from homeassistant.const import UnitOfPower
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -14,7 +13,6 @@ from homeassistant.helpers.condition import (
|
||||
from homeassistant.util.unit_conversion import PowerConverter
|
||||
|
||||
POWER_DOMAIN_SPECS = {
|
||||
NUMBER_DOMAIN: DomainSpec(device_class=NumberDeviceClass.POWER),
|
||||
SENSOR_DOMAIN: DomainSpec(device_class=SensorDeviceClass.POWER),
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
is_value:
|
||||
target:
|
||||
entity:
|
||||
- domain: number
|
||||
device_class: power
|
||||
- domain: sensor
|
||||
device_class: power
|
||||
fields:
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN, NumberDeviceClass
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
|
||||
from homeassistant.const import UnitOfPower
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -15,7 +14,6 @@ from homeassistant.helpers.trigger import (
|
||||
from homeassistant.util.unit_conversion import PowerConverter
|
||||
|
||||
POWER_DOMAIN_SPECS: dict[str, DomainSpec] = {
|
||||
NUMBER_DOMAIN: DomainSpec(device_class=NumberDeviceClass.POWER),
|
||||
SENSOR_DOMAIN: DomainSpec(device_class=SensorDeviceClass.POWER),
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
.trigger_target: &trigger_target
|
||||
entity:
|
||||
- domain: number
|
||||
device_class: power
|
||||
- domain: sensor
|
||||
device_class: power
|
||||
|
||||
|
||||
@@ -26,12 +26,6 @@ async def target_sensors(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
return await target_entities(hass, "sensor")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def target_numbers(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
"""Create multiple number entities associated with different targets."""
|
||||
return await target_entities(hass, "number")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"condition",
|
||||
["power.is_value"],
|
||||
@@ -117,80 +111,6 @@ async def test_power_sensor_condition_behavior_all(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_target_config", "entity_id", "entities_in_target"),
|
||||
parametrize_target_entities("number"),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("condition", "condition_options", "states"),
|
||||
parametrize_numerical_condition_above_below_any(
|
||||
"power.is_value",
|
||||
device_class="power",
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.WATT},
|
||||
),
|
||||
)
|
||||
async def test_power_number_condition_behavior_any(
|
||||
hass: HomeAssistant,
|
||||
target_numbers: dict[str, list[str]],
|
||||
condition_target_config: dict,
|
||||
entity_id: str,
|
||||
entities_in_target: int,
|
||||
condition: str,
|
||||
condition_options: dict[str, Any],
|
||||
states: list[ConditionStateDescription],
|
||||
) -> None:
|
||||
"""Test the power number condition with 'any' behavior."""
|
||||
await assert_condition_behavior_any(
|
||||
hass,
|
||||
target_entities=target_numbers,
|
||||
condition_target_config=condition_target_config,
|
||||
entity_id=entity_id,
|
||||
entities_in_target=entities_in_target,
|
||||
condition=condition,
|
||||
condition_options=condition_options,
|
||||
states=states,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_target_config", "entity_id", "entities_in_target"),
|
||||
parametrize_target_entities("number"),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("condition", "condition_options", "states"),
|
||||
parametrize_numerical_condition_above_below_all(
|
||||
"power.is_value",
|
||||
device_class="power",
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.WATT},
|
||||
),
|
||||
)
|
||||
async def test_power_number_condition_behavior_all(
|
||||
hass: HomeAssistant,
|
||||
target_numbers: dict[str, list[str]],
|
||||
condition_target_config: dict,
|
||||
entity_id: str,
|
||||
entities_in_target: int,
|
||||
condition: str,
|
||||
condition_options: dict[str, Any],
|
||||
states: list[ConditionStateDescription],
|
||||
) -> None:
|
||||
"""Test the power number condition with 'all' behavior."""
|
||||
await assert_condition_behavior_all(
|
||||
hass,
|
||||
target_entities=target_numbers,
|
||||
condition_target_config=condition_target_config,
|
||||
entity_id=entity_id,
|
||||
entities_in_target=entities_in_target,
|
||||
condition=condition,
|
||||
condition_options=condition_options,
|
||||
states=states,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
async def test_power_condition_unit_conversion_sensor(
|
||||
hass: HomeAssistant,
|
||||
|
||||
@@ -4,7 +4,6 @@ from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.number import NumberDeviceClass
|
||||
from homeassistant.components.sensor import SensorDeviceClass
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfPower
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -24,12 +23,6 @@ from tests.components.common import (
|
||||
_POWER_UNIT_ATTRIBUTES = {ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.WATT}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def target_numbers(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
"""Create multiple number entities associated with different targets."""
|
||||
return await target_entities(hass, "number")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def target_sensors(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
"""Create multiple sensor entities associated with different targets."""
|
||||
@@ -171,129 +164,3 @@ async def test_power_trigger_sensor_crossed_threshold_behavior_last(
|
||||
trigger_options=trigger_options,
|
||||
states=states,
|
||||
)
|
||||
|
||||
|
||||
# --- Number entity tests ---
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_target_config", "entity_id", "entities_in_target"),
|
||||
parametrize_target_entities("number"),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("trigger", "trigger_options", "states"),
|
||||
[
|
||||
*parametrize_numerical_state_value_changed_trigger_states(
|
||||
"power.changed",
|
||||
device_class=NumberDeviceClass.POWER,
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes=_POWER_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_state_value_crossed_threshold_trigger_states(
|
||||
"power.crossed_threshold",
|
||||
device_class=NumberDeviceClass.POWER,
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes=_POWER_UNIT_ATTRIBUTES,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_power_trigger_number_behavior_any(
|
||||
hass: HomeAssistant,
|
||||
target_numbers: dict[str, list[str]],
|
||||
trigger_target_config: dict,
|
||||
entity_id: str,
|
||||
entities_in_target: int,
|
||||
trigger: str,
|
||||
trigger_options: dict[str, Any],
|
||||
states: list[TriggerStateDescription],
|
||||
) -> None:
|
||||
"""Test power trigger fires for number entities with device_class power."""
|
||||
await assert_trigger_behavior_any(
|
||||
hass,
|
||||
target_entities=target_numbers,
|
||||
trigger_target_config=trigger_target_config,
|
||||
entity_id=entity_id,
|
||||
entities_in_target=entities_in_target,
|
||||
trigger=trigger,
|
||||
trigger_options=trigger_options,
|
||||
states=states,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_target_config", "entity_id", "entities_in_target"),
|
||||
parametrize_target_entities("number"),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("trigger", "trigger_options", "states"),
|
||||
[
|
||||
*parametrize_numerical_state_value_crossed_threshold_trigger_states(
|
||||
"power.crossed_threshold",
|
||||
device_class=NumberDeviceClass.POWER,
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes=_POWER_UNIT_ATTRIBUTES,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_power_trigger_number_crossed_threshold_behavior_first(
|
||||
hass: HomeAssistant,
|
||||
target_numbers: dict[str, list[str]],
|
||||
trigger_target_config: dict,
|
||||
entity_id: str,
|
||||
entities_in_target: int,
|
||||
trigger: str,
|
||||
trigger_options: dict[str, Any],
|
||||
states: list[TriggerStateDescription],
|
||||
) -> None:
|
||||
"""Test power crossed_threshold trigger fires on the first number state change."""
|
||||
await assert_trigger_behavior_first(
|
||||
hass,
|
||||
target_entities=target_numbers,
|
||||
trigger_target_config=trigger_target_config,
|
||||
entity_id=entity_id,
|
||||
entities_in_target=entities_in_target,
|
||||
trigger=trigger,
|
||||
trigger_options=trigger_options,
|
||||
states=states,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_target_config", "entity_id", "entities_in_target"),
|
||||
parametrize_target_entities("number"),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("trigger", "trigger_options", "states"),
|
||||
[
|
||||
*parametrize_numerical_state_value_crossed_threshold_trigger_states(
|
||||
"power.crossed_threshold",
|
||||
device_class=NumberDeviceClass.POWER,
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes=_POWER_UNIT_ATTRIBUTES,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_power_trigger_number_crossed_threshold_behavior_last(
|
||||
hass: HomeAssistant,
|
||||
target_numbers: dict[str, list[str]],
|
||||
trigger_target_config: dict,
|
||||
entity_id: str,
|
||||
entities_in_target: int,
|
||||
trigger: str,
|
||||
trigger_options: dict[str, Any],
|
||||
states: list[TriggerStateDescription],
|
||||
) -> None:
|
||||
"""Test power crossed_threshold trigger fires when the last number changes state."""
|
||||
await assert_trigger_behavior_last(
|
||||
hass,
|
||||
target_entities=target_numbers,
|
||||
trigger_target_config=trigger_target_config,
|
||||
entity_id=entity_id,
|
||||
entities_in_target=entities_in_target,
|
||||
trigger=trigger,
|
||||
trigger_options=trigger_options,
|
||||
states=states,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user