Compare commits

..

3 Commits

Author SHA1 Message Date
mib1185
ee0230f3b1 use renamed helpers 2025-12-17 20:06:03 +00:00
mib1185
851fd467fe Merge branch 'dev' into input_boolean/add-domain-driven-triggers 2025-12-17 20:05:20 +00:00
mib1185
d10148a175 add turned_off and turned_on triggers 2025-12-12 20:53:03 +00:00
50 changed files with 461 additions and 249 deletions

View File

@@ -51,9 +51,6 @@ rules:
- **Missing imports** - We use static analysis tooling to catch that - **Missing imports** - We use static analysis tooling to catch that
- **Code formatting** - We have ruff as a formatting tool that will catch those if needed (unless specifically instructed otherwise in these instructions) - **Code formatting** - We have ruff as a formatting tool that will catch those if needed (unless specifically instructed otherwise in these instructions)
**Git commit practices during review:**
- **Do NOT amend, squash, or rebase commits after review has started** - Reviewers need to see what changed since their last review
## Python Requirements ## Python Requirements
- **Compatibility**: Python 3.13+ - **Compatibility**: Python 3.13+

View File

@@ -130,6 +130,7 @@ _EXPERIMENTAL_TRIGGER_PLATFORMS = {
"cover", "cover",
"device_tracker", "device_tracker",
"fan", "fan",
"input_boolean",
"lawn_mower", "lawn_mower",
"light", "light",
"media_player", "media_player",

View File

@@ -2,7 +2,6 @@
"domain": "blackbird", "domain": "blackbird",
"name": "Monoprice Blackbird Matrix Switch", "name": "Monoprice Blackbird Matrix Switch",
"codeowners": [], "codeowners": [],
"disabled": "This integration is disabled because it references pyserial-asyncio, which does blocking I/O in the asyncio loop and is not maintained.",
"documentation": "https://www.home-assistant.io/integrations/blackbird", "documentation": "https://www.home-assistant.io/integrations/blackbird",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["pyblackbird"], "loggers": ["pyblackbird"],

View File

@@ -17,7 +17,7 @@
"mqtt": ["esphome/discover/#"], "mqtt": ["esphome/discover/#"],
"quality_scale": "platinum", "quality_scale": "platinum",
"requirements": [ "requirements": [
"aioesphomeapi==43.3.0", "aioesphomeapi==43.0.0",
"esphome-dashboard-api==1.3.0", "esphome-dashboard-api==1.3.0",
"bleak-esphome==3.4.0" "bleak-esphome==3.4.0"
], ],

View File

@@ -20,5 +20,13 @@
"turn_on": { "turn_on": {
"service": "mdi:toggle-switch" "service": "mdi:toggle-switch"
} }
},
"triggers": {
"turned_off": {
"trigger": "mdi:toggle-switch-off"
},
"turned_on": {
"trigger": "mdi:toggle-switch"
}
} }
} }

View File

@@ -1,4 +1,8 @@
{ {
"common": {
"trigger_behavior_description": "The behavior of the targeted input booleans to trigger on.",
"trigger_behavior_name": "Behavior"
},
"entity_component": { "entity_component": {
"_": { "_": {
"name": "[%key:component::input_boolean::title%]", "name": "[%key:component::input_boolean::title%]",
@@ -17,6 +21,15 @@
} }
} }
}, },
"selector": {
"trigger_behavior": {
"options": {
"any": "Any",
"first": "First",
"last": "Last"
}
}
},
"services": { "services": {
"reload": { "reload": {
"description": "Reloads helpers from the YAML-configuration.", "description": "Reloads helpers from the YAML-configuration.",
@@ -35,5 +48,27 @@
"name": "[%key:common::action::turn_on%]" "name": "[%key:common::action::turn_on%]"
} }
}, },
"title": "Input boolean" "title": "Input boolean",
"triggers": {
"turned_off": {
"description": "Triggers after one or more input booleans turn off.",
"fields": {
"behavior": {
"description": "[%key:component::input_boolean::common::trigger_behavior_description%]",
"name": "[%key:component::input_boolean::common::trigger_behavior_name%]"
}
},
"name": "Input boolean turned off"
},
"turned_on": {
"description": "Triggers after one or more input booleans turn on.",
"fields": {
"behavior": {
"description": "[%key:component::input_boolean::common::trigger_behavior_description%]",
"name": "[%key:component::input_boolean::common::trigger_behavior_name%]"
}
},
"name": "Input boolean turned on"
}
}
} }

View File

@@ -0,0 +1,17 @@
"""Provides triggers for input booleans."""
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.helpers.trigger import Trigger, make_entity_target_state_trigger
from . import DOMAIN
TRIGGERS: dict[str, type[Trigger]] = {
"turned_on": make_entity_target_state_trigger(DOMAIN, STATE_ON),
"turned_off": make_entity_target_state_trigger(DOMAIN, STATE_OFF),
}
async def async_get_triggers(hass: HomeAssistant) -> dict[str, type[Trigger]]:
"""Return the triggers for input booleans."""
return TRIGGERS

View File

@@ -0,0 +1,18 @@
.trigger_common: &trigger_common
target:
entity:
domain: input_boolean
fields:
behavior:
required: true
default: any
selector:
select:
options:
- first
- last
- any
translation_key: trigger_behavior
turned_off: *trigger_common
turned_on: *trigger_common

View File

@@ -4,7 +4,6 @@
"codeowners": ["@dgomes"], "codeowners": ["@dgomes"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/kmtronic", "documentation": "https://www.home-assistant.io/integrations/kmtronic",
"integration_type": "device",
"iot_class": "local_push", "iot_class": "local_push",
"loggers": ["pykmtronic"], "loggers": ["pykmtronic"],
"requirements": ["pykmtronic==0.3.0"] "requirements": ["pykmtronic==0.3.0"]

View File

@@ -5,7 +5,6 @@
"codeowners": ["@OnFreund"], "codeowners": ["@OnFreund"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/kodi", "documentation": "https://www.home-assistant.io/integrations/kodi",
"integration_type": "service",
"iot_class": "local_push", "iot_class": "local_push",
"loggers": ["jsonrpc_async", "jsonrpc_base", "jsonrpc_websocket", "pykodi"], "loggers": ["jsonrpc_async", "jsonrpc_base", "jsonrpc_websocket", "pykodi"],
"requirements": ["pykodi==0.2.7"], "requirements": ["pykodi==0.2.7"],

View File

@@ -4,7 +4,6 @@
"codeowners": ["@stegm"], "codeowners": ["@stegm"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/kostal_plenticore", "documentation": "https://www.home-assistant.io/integrations/kostal_plenticore",
"integration_type": "device",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["kostal"], "loggers": ["kostal"],
"requirements": ["pykoplenti==1.3.0"] "requirements": ["pykoplenti==1.3.0"]

View File

@@ -4,7 +4,6 @@
"codeowners": ["@eifinger"], "codeowners": ["@eifinger"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/kraken", "documentation": "https://www.home-assistant.io/integrations/kraken",
"integration_type": "service",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"loggers": ["krakenex", "pykrakenapi"], "loggers": ["krakenex", "pykrakenapi"],
"requirements": ["krakenex==2.2.2", "pykrakenapi==0.1.8"] "requirements": ["krakenex==2.2.2", "pykrakenapi==0.1.8"]

View File

@@ -10,7 +10,6 @@
"config_flow": true, "config_flow": true,
"dependencies": ["bluetooth_adapters"], "dependencies": ["bluetooth_adapters"],
"documentation": "https://www.home-assistant.io/integrations/kulersky", "documentation": "https://www.home-assistant.io/integrations/kulersky",
"integration_type": "device",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["bleak", "pykulersky"], "loggers": ["bleak", "pykulersky"],
"requirements": ["pykulersky==0.5.8"] "requirements": ["pykulersky==0.5.8"]

View File

@@ -4,7 +4,6 @@
"codeowners": ["@IceBotYT"], "codeowners": ["@IceBotYT"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/lacrosse_view", "documentation": "https://www.home-assistant.io/integrations/lacrosse_view",
"integration_type": "hub",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"loggers": ["lacrosse_view"], "loggers": ["lacrosse_view"],
"requirements": ["lacrosse-view==1.1.1"] "requirements": ["lacrosse-view==1.1.1"]

View File

@@ -5,7 +5,6 @@
"config_flow": true, "config_flow": true,
"dependencies": ["usb"], "dependencies": ["usb"],
"documentation": "https://www.home-assistant.io/integrations/landisgyr_heat_meter", "documentation": "https://www.home-assistant.io/integrations/landisgyr_heat_meter",
"integration_type": "device",
"iot_class": "local_polling", "iot_class": "local_polling",
"requirements": ["ultraheat-api==0.5.7"] "requirements": ["ultraheat-api==0.5.7"]
} }

View File

@@ -4,7 +4,6 @@
"codeowners": ["@joostlek"], "codeowners": ["@joostlek"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/lastfm", "documentation": "https://www.home-assistant.io/integrations/lastfm",
"integration_type": "service",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"loggers": ["pylast"], "loggers": ["pylast"],
"requirements": ["pylast==5.1.0"] "requirements": ["pylast==5.1.0"]

View File

@@ -4,7 +4,6 @@
"codeowners": ["@xLarry"], "codeowners": ["@xLarry"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/laundrify", "documentation": "https://www.home-assistant.io/integrations/laundrify",
"integration_type": "hub",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"requirements": ["laundrify-aio==1.2.2"] "requirements": ["laundrify-aio==1.2.2"]
} }

View File

@@ -19,8 +19,8 @@ from .const import CONF_DOMAIN_DATA
from .entity import LcnEntity from .entity import LcnEntity
from .helpers import InputType, LcnConfigEntry from .helpers import InputType, LcnConfigEntry
PARALLEL_UPDATES = 2 PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(minutes=10) SCAN_INTERVAL = timedelta(minutes=1)
def add_lcn_entities( def add_lcn_entities(

View File

@@ -36,7 +36,7 @@ from .const import (
from .entity import LcnEntity from .entity import LcnEntity
from .helpers import InputType, LcnConfigEntry from .helpers import InputType, LcnConfigEntry
PARALLEL_UPDATES = 2 PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(minutes=1) SCAN_INTERVAL = timedelta(minutes=1)

View File

@@ -27,7 +27,7 @@ from .const import (
from .entity import LcnEntity from .entity import LcnEntity
from .helpers import InputType, LcnConfigEntry from .helpers import InputType, LcnConfigEntry
PARALLEL_UPDATES = 2 PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(minutes=1) SCAN_INTERVAL = timedelta(minutes=1)

View File

@@ -33,8 +33,8 @@ from .helpers import InputType, LcnConfigEntry
BRIGHTNESS_SCALE = (1, 100) BRIGHTNESS_SCALE = (1, 100)
PARALLEL_UPDATES = 2 PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(minutes=10) SCAN_INTERVAL = timedelta(minutes=1)
def add_lcn_entities( def add_lcn_entities(

View File

@@ -6,9 +6,8 @@
"config_flow": true, "config_flow": true,
"dependencies": ["http", "websocket_api"], "dependencies": ["http", "websocket_api"],
"documentation": "https://www.home-assistant.io/integrations/lcn", "documentation": "https://www.home-assistant.io/integrations/lcn",
"integration_type": "hub",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["pypck"], "loggers": ["pypck"],
"quality_scale": "silver", "quality_scale": "silver",
"requirements": ["pypck==0.9.8", "lcn-frontend==0.2.7"] "requirements": ["pypck==0.9.7", "lcn-frontend==0.2.7"]
} }

View File

@@ -22,7 +22,7 @@ from .const import (
from .entity import LcnEntity from .entity import LcnEntity
from .helpers import LcnConfigEntry from .helpers import LcnConfigEntry
PARALLEL_UPDATES = 2 PARALLEL_UPDATES = 0
def add_lcn_entities( def add_lcn_entities(

View File

@@ -40,7 +40,7 @@ from .const import (
from .entity import LcnEntity from .entity import LcnEntity
from .helpers import InputType, LcnConfigEntry from .helpers import InputType, LcnConfigEntry
PARALLEL_UPDATES = 2 PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(minutes=1) SCAN_INTERVAL = timedelta(minutes=1)

View File

@@ -17,8 +17,8 @@ from .const import CONF_DOMAIN_DATA, CONF_OUTPUT, OUTPUT_PORTS, RELAY_PORTS, SET
from .entity import LcnEntity from .entity import LcnEntity
from .helpers import InputType, LcnConfigEntry from .helpers import InputType, LcnConfigEntry
PARALLEL_UPDATES = 2 PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(minutes=10) SCAN_INTERVAL = timedelta(minutes=1)
def add_lcn_switch_entities( def add_lcn_switch_entities(

View File

@@ -5,7 +5,6 @@
"config_flow": true, "config_flow": true,
"dependencies": ["bluetooth_adapters"], "dependencies": ["bluetooth_adapters"],
"documentation": "https://www.home-assistant.io/integrations/leaone", "documentation": "https://www.home-assistant.io/integrations/leaone",
"integration_type": "device",
"iot_class": "local_push", "iot_class": "local_push",
"requirements": ["leaone-ble==0.3.0"] "requirements": ["leaone-ble==0.3.0"]
} }

View File

@@ -34,7 +34,6 @@
"config_flow": true, "config_flow": true,
"dependencies": ["bluetooth_adapters"], "dependencies": ["bluetooth_adapters"],
"documentation": "https://www.home-assistant.io/integrations/led_ble", "documentation": "https://www.home-assistant.io/integrations/led_ble",
"integration_type": "device",
"iot_class": "local_polling", "iot_class": "local_polling",
"requirements": ["bluetooth-data-tools==1.28.4", "led-ble==1.1.7"] "requirements": ["bluetooth-data-tools==1.28.4", "led-ble==1.1.7"]
} }

View File

@@ -4,7 +4,6 @@
"codeowners": [], "codeowners": [],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/lg_soundbar", "documentation": "https://www.home-assistant.io/integrations/lg_soundbar",
"integration_type": "device",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["temescal"], "loggers": ["temescal"],
"requirements": ["temescal==0.5"] "requirements": ["temescal==0.5"]

View File

@@ -3,13 +3,8 @@
"name": "LG ThinQ", "name": "LG ThinQ",
"codeowners": ["@LG-ThinQ-Integration"], "codeowners": ["@LG-ThinQ-Integration"],
"config_flow": true, "config_flow": true,
"dhcp": [ "dhcp": [{ "macaddress": "34E6E6*" }],
{
"macaddress": "34E6E6*"
}
],
"documentation": "https://www.home-assistant.io/integrations/lg_thinq", "documentation": "https://www.home-assistant.io/integrations/lg_thinq",
"integration_type": "hub",
"iot_class": "cloud_push", "iot_class": "cloud_push",
"loggers": ["thinqconnect"], "loggers": ["thinqconnect"],
"requirements": ["thinqconnect==1.0.9"] "requirements": ["thinqconnect==1.0.9"]

View File

@@ -49,7 +49,6 @@
"LIFX Z" "LIFX Z"
] ]
}, },
"integration_type": "device",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["aiolifx", "aiolifx_effects", "bitstring"], "loggers": ["aiolifx", "aiolifx_effects", "bitstring"],
"requirements": [ "requirements": [

View File

@@ -4,7 +4,6 @@
"codeowners": ["@StefanIacobLivisi", "@planbnet"], "codeowners": ["@StefanIacobLivisi", "@planbnet"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/livisi", "documentation": "https://www.home-assistant.io/integrations/livisi",
"integration_type": "hub",
"iot_class": "local_polling", "iot_class": "local_polling",
"requirements": ["livisi==0.0.25"] "requirements": ["livisi==0.0.25"]
} }

View File

@@ -6,7 +6,6 @@
"config_flow": true, "config_flow": true,
"dependencies": ["webhook"], "dependencies": ["webhook"],
"documentation": "https://www.home-assistant.io/integrations/loqed", "documentation": "https://www.home-assistant.io/integrations/loqed",
"integration_type": "device",
"iot_class": "local_push", "iot_class": "local_push",
"requirements": ["loqedAPI==2.1.10"], "requirements": ["loqedAPI==2.1.10"],
"zeroconf": [ "zeroconf": [

View File

@@ -4,7 +4,6 @@
"codeowners": ["@majuss", "@suaveolent"], "codeowners": ["@majuss", "@suaveolent"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/lupusec", "documentation": "https://www.home-assistant.io/integrations/lupusec",
"integration_type": "hub",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["lupupy"], "loggers": ["lupupy"],
"requirements": ["lupupy==0.3.2"] "requirements": ["lupupy==0.3.2"]

View File

@@ -4,7 +4,6 @@
"codeowners": ["@cdheiser", "@wilburCForce"], "codeowners": ["@cdheiser", "@wilburCForce"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/lutron", "documentation": "https://www.home-assistant.io/integrations/lutron",
"integration_type": "hub",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["pylutron"], "loggers": ["pylutron"],
"requirements": ["pylutron==0.2.18"], "requirements": ["pylutron==0.2.18"],

View File

@@ -19,7 +19,6 @@
} }
], ],
"documentation": "https://www.home-assistant.io/integrations/lyric", "documentation": "https://www.home-assistant.io/integrations/lyric",
"integration_type": "hub",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"loggers": ["aiolyric"], "loggers": ["aiolyric"],
"requirements": ["aiolyric==2.0.2"] "requirements": ["aiolyric==2.0.2"]

View File

@@ -5,7 +5,6 @@
"config_flow": true, "config_flow": true,
"dependencies": ["webhook"], "dependencies": ["webhook"],
"documentation": "https://www.home-assistant.io/integrations/mailgun", "documentation": "https://www.home-assistant.io/integrations/mailgun",
"integration_type": "service",
"iot_class": "cloud_push", "iot_class": "cloud_push",
"loggers": ["pymailgunner"], "loggers": ["pymailgunner"],
"requirements": ["pymailgunner==1.4"] "requirements": ["pymailgunner==1.4"]

View File

@@ -4,7 +4,6 @@
"codeowners": ["@Sotolotl", "@emontnemery"], "codeowners": ["@Sotolotl", "@emontnemery"],
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/meater", "documentation": "https://www.home-assistant.io/integrations/meater",
"integration_type": "hub",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"requirements": ["meater-python==0.0.8"] "requirements": ["meater-python==0.0.8"]
} }

View File

@@ -10,7 +10,6 @@
"config_flow": true, "config_flow": true,
"dependencies": ["bluetooth_adapters"], "dependencies": ["bluetooth_adapters"],
"documentation": "https://www.home-assistant.io/integrations/medcom_ble", "documentation": "https://www.home-assistant.io/integrations/medcom_ble",
"integration_type": "device",
"iot_class": "local_polling", "iot_class": "local_polling",
"requirements": ["medcom-ble==0.1.1"] "requirements": ["medcom-ble==0.1.1"]
} }

View File

@@ -11,7 +11,6 @@
"config_flow": true, "config_flow": true,
"dependencies": ["bluetooth_adapters"], "dependencies": ["bluetooth_adapters"],
"documentation": "https://www.home-assistant.io/integrations/melnor", "documentation": "https://www.home-assistant.io/integrations/melnor",
"integration_type": "device",
"iot_class": "local_polling", "iot_class": "local_polling",
"requirements": ["melnor-bluetooth==0.0.25"] "requirements": ["melnor-bluetooth==0.0.25"]
} }

View File

@@ -537,12 +537,6 @@
"voltmeter_value": { "voltmeter_value": {
"name": "Voltmeter value" "name": "Voltmeter value"
}, },
"voltmeter_value_with_channel_name": {
"name": "Voltmeter value {channel_name}"
},
"voltmeter_with_channel_name": {
"name": "Voltmeter {channel_name}"
},
"water_consumption": { "water_consumption": {
"name": "Water consumption" "name": "Water consumption"
}, },

View File

@@ -31,12 +31,10 @@ from .models import (
class _DPCodeEventWrapper(DPCodeTypeInformationWrapper): class _DPCodeEventWrapper(DPCodeTypeInformationWrapper):
"""Base class for Tuya event wrappers.""" """Base class for Tuya event wrappers."""
options: list[str] @property
def event_types(self) -> list[str]:
def __init__(self, dpcode: str, type_information: Any) -> None: """Return the event types for the DP code."""
"""Init _DPCodeEventWrapper.""" return ["triggered"]
super().__init__(dpcode, type_information)
self.options = ["triggered"]
def get_event_type( def get_event_type(
self, device: CustomerDevice, updated_status_properties: list[str] | None self, device: CustomerDevice, updated_status_properties: list[str] | None
@@ -57,6 +55,11 @@ class _DPCodeEventWrapper(DPCodeTypeInformationWrapper):
class _EventEnumWrapper(DPCodeEnumWrapper, _DPCodeEventWrapper): class _EventEnumWrapper(DPCodeEnumWrapper, _DPCodeEventWrapper):
"""Wrapper for event enum DP codes.""" """Wrapper for event enum DP codes."""
@property
def event_types(self) -> list[str]:
"""Return the event types for the enum."""
return self.options
def get_event_type( def get_event_type(
self, device: CustomerDevice, updated_status_properties: list[str] | None self, device: CustomerDevice, updated_status_properties: list[str] | None
) -> str | None: ) -> str | None:
@@ -229,7 +232,7 @@ class TuyaEventEntity(TuyaEntity, EventEntity):
self.entity_description = description self.entity_description = description
self._attr_unique_id = f"{super().unique_id}{description.key}" self._attr_unique_id = f"{super().unique_id}{description.key}"
self._dpcode_wrapper = dpcode_wrapper self._dpcode_wrapper = dpcode_wrapper
self._attr_event_types = dpcode_wrapper.options self._attr_event_types = dpcode_wrapper.event_types
async def _handle_state_update( async def _handle_state_update(
self, self,

View File

@@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
from typing import Any, Self from typing import Any
from tuya_sharing import CustomerDevice, Manager from tuya_sharing import CustomerDevice, Manager
@@ -18,13 +18,10 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import TuyaConfigEntry from . import TuyaConfigEntry
from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode
from .entity import TuyaEntity from .entity import TuyaEntity
from .models import DeviceWrapper, DPCodeBooleanWrapper, DPCodeEnumWrapper from .models import DPCodeBooleanWrapper, DPCodeEnumWrapper
TUYA_MODE_RETURN_HOME = "chargego"
class _VacuumActivityWrapper(DeviceWrapper): TUYA_STATUS_TO_HA = {
"""Wrapper for the state of a device."""
_TUYA_STATUS_TO_HA = {
"charge_done": VacuumActivity.DOCKED, "charge_done": VacuumActivity.DOCKED,
"chargecompleted": VacuumActivity.DOCKED, "chargecompleted": VacuumActivity.DOCKED,
"chargego": VacuumActivity.DOCKED, "chargego": VacuumActivity.DOCKED,
@@ -48,110 +45,7 @@ class _VacuumActivityWrapper(DeviceWrapper):
"wall_clean": VacuumActivity.CLEANING, "wall_clean": VacuumActivity.CLEANING,
"wall_follow": VacuumActivity.CLEANING, "wall_follow": VacuumActivity.CLEANING,
"zone_clean": VacuumActivity.CLEANING, "zone_clean": VacuumActivity.CLEANING,
} }
def __init__(
self,
pause_wrapper: DPCodeBooleanWrapper | None = None,
status_wrapper: DPCodeEnumWrapper | None = None,
) -> None:
"""Init _VacuumActivityWrapper."""
self._pause_wrapper = pause_wrapper
self._status_wrapper = status_wrapper
@classmethod
def find_dpcode(cls, device: CustomerDevice) -> Self | None:
"""Find and return a _VacuumActivityWrapper for the given DP codes."""
pause_wrapper = DPCodeBooleanWrapper.find_dpcode(device, DPCode.PAUSE)
status_wrapper = DPCodeEnumWrapper.find_dpcode(device, DPCode.STATUS)
if pause_wrapper or status_wrapper:
return cls(pause_wrapper=pause_wrapper, status_wrapper=status_wrapper)
return None
def read_device_status(self, device: CustomerDevice) -> VacuumActivity | None:
"""Read the device status."""
if (
self._status_wrapper
and (status := self._status_wrapper.read_device_status(device)) is not None
):
return self._TUYA_STATUS_TO_HA.get(status)
if self._pause_wrapper and self._pause_wrapper.read_device_status(device):
return VacuumActivity.PAUSED
return None
class _VacuumActionWrapper(DeviceWrapper):
"""Wrapper for sending actions to a vacuum."""
_TUYA_MODE_RETURN_HOME = "chargego"
def __init__(
self,
charge_wrapper: DPCodeBooleanWrapper | None,
locate_wrapper: DPCodeBooleanWrapper | None,
pause_wrapper: DPCodeBooleanWrapper | None,
mode_wrapper: DPCodeEnumWrapper | None,
switch_wrapper: DPCodeBooleanWrapper | None,
) -> None:
"""Init _VacuumActionWrapper."""
self._charge_wrapper = charge_wrapper
self._locate_wrapper = locate_wrapper
self._mode_wrapper = mode_wrapper
self._switch_wrapper = switch_wrapper
self.options = []
if charge_wrapper or (
mode_wrapper and self._TUYA_MODE_RETURN_HOME in mode_wrapper.options
):
self.options.append("return_to_base")
if locate_wrapper:
self.options.append("locate")
if pause_wrapper:
self.options.append("pause")
if switch_wrapper:
self.options.append("start")
self.options.append("stop")
@classmethod
def find_dpcode(cls, device: CustomerDevice) -> Self:
"""Find and return a _VacuumActionWrapper for the given DP codes."""
return cls(
charge_wrapper=DPCodeBooleanWrapper.find_dpcode(
device, DPCode.SWITCH_CHARGE, prefer_function=True
),
locate_wrapper=DPCodeBooleanWrapper.find_dpcode(
device, DPCode.SEEK, prefer_function=True
),
mode_wrapper=DPCodeEnumWrapper.find_dpcode(
device, DPCode.MODE, prefer_function=True
),
pause_wrapper=DPCodeBooleanWrapper.find_dpcode(device, DPCode.PAUSE),
switch_wrapper=DPCodeBooleanWrapper.find_dpcode(
device, DPCode.POWER_GO, prefer_function=True
),
)
def get_update_commands(
self, device: CustomerDevice, value: Any
) -> list[dict[str, Any]]:
"""Get the commands for the action wrapper."""
if value == "locate" and self._locate_wrapper:
return self._locate_wrapper.get_update_commands(device, True)
if value == "pause" and self._switch_wrapper:
return self._switch_wrapper.get_update_commands(device, False)
if value == "return_to_base":
if self._charge_wrapper:
return self._charge_wrapper.get_update_commands(device, True)
if self._mode_wrapper:
return self._mode_wrapper.get_update_commands(
device, self._TUYA_MODE_RETURN_HOME
)
if value == "start" and self._switch_wrapper:
return self._switch_wrapper.get_update_commands(device, True)
if value == "stop" and self._switch_wrapper:
return self._switch_wrapper.get_update_commands(device, False)
return []
async def async_setup_entry( async def async_setup_entry(
@@ -173,11 +67,27 @@ async def async_setup_entry(
TuyaVacuumEntity( TuyaVacuumEntity(
device, device,
manager, manager,
action_wrapper=_VacuumActionWrapper.find_dpcode(device), charge_wrapper=DPCodeBooleanWrapper.find_dpcode(
activity_wrapper=_VacuumActivityWrapper.find_dpcode(device), device, DPCode.SWITCH_CHARGE, prefer_function=True
),
fan_speed_wrapper=DPCodeEnumWrapper.find_dpcode( fan_speed_wrapper=DPCodeEnumWrapper.find_dpcode(
device, DPCode.SUCTION, prefer_function=True device, DPCode.SUCTION, prefer_function=True
), ),
locate_wrapper=DPCodeBooleanWrapper.find_dpcode(
device, DPCode.SEEK, prefer_function=True
),
mode_wrapper=DPCodeEnumWrapper.find_dpcode(
device, DPCode.MODE, prefer_function=True
),
pause_wrapper=DPCodeBooleanWrapper.find_dpcode(
device, DPCode.PAUSE
),
status_wrapper=DPCodeEnumWrapper.find_dpcode(
device, DPCode.STATUS
),
switch_wrapper=DPCodeBooleanWrapper.find_dpcode(
device, DPCode.POWER_GO, prefer_function=True
),
) )
) )
async_add_entities(entities) async_add_entities(entities)
@@ -199,33 +109,43 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
device: CustomerDevice, device: CustomerDevice,
device_manager: Manager, device_manager: Manager,
*, *,
action_wrapper: _VacuumActionWrapper | None, charge_wrapper: DPCodeBooleanWrapper | None,
activity_wrapper: _VacuumActivityWrapper | None,
fan_speed_wrapper: DPCodeEnumWrapper | None, fan_speed_wrapper: DPCodeEnumWrapper | None,
locate_wrapper: DPCodeBooleanWrapper | None,
mode_wrapper: DPCodeEnumWrapper | None,
pause_wrapper: DPCodeBooleanWrapper | None,
status_wrapper: DPCodeEnumWrapper | None,
switch_wrapper: DPCodeBooleanWrapper | None,
) -> None: ) -> None:
"""Init Tuya vacuum.""" """Init Tuya vacuum."""
super().__init__(device, device_manager) super().__init__(device, device_manager)
self._action_wrapper = action_wrapper self._charge_wrapper = charge_wrapper
self._activity_wrapper = activity_wrapper
self._fan_speed_wrapper = fan_speed_wrapper self._fan_speed_wrapper = fan_speed_wrapper
self._locate_wrapper = locate_wrapper
self._mode_wrapper = mode_wrapper
self._pause_wrapper = pause_wrapper
self._status_wrapper = status_wrapper
self._switch_wrapper = switch_wrapper
self._attr_fan_speed_list = [] self._attr_fan_speed_list = []
self._attr_supported_features = VacuumEntityFeature.SEND_COMMAND self._attr_supported_features = (
VacuumEntityFeature.SEND_COMMAND | VacuumEntityFeature.STATE
if action_wrapper and action_wrapper.options: )
if "pause" in action_wrapper.options: if pause_wrapper:
self._attr_supported_features |= VacuumEntityFeature.PAUSE self._attr_supported_features |= VacuumEntityFeature.PAUSE
if "return_to_base" in action_wrapper.options:
self._attr_supported_features |= VacuumEntityFeature.RETURN_HOME
if "locate" in action_wrapper.options:
self._attr_supported_features |= VacuumEntityFeature.LOCATE
if "start" in action_wrapper.options:
self._attr_supported_features |= VacuumEntityFeature.START
if "stop" in action_wrapper.options:
self._attr_supported_features |= VacuumEntityFeature.STOP
if activity_wrapper: if charge_wrapper or (
self._attr_supported_features |= VacuumEntityFeature.STATE mode_wrapper and TUYA_MODE_RETURN_HOME in mode_wrapper.options
):
self._attr_supported_features |= VacuumEntityFeature.RETURN_HOME
if locate_wrapper:
self._attr_supported_features |= VacuumEntityFeature.LOCATE
if switch_wrapper:
self._attr_supported_features |= (
VacuumEntityFeature.STOP | VacuumEntityFeature.START
)
if fan_speed_wrapper: if fan_speed_wrapper:
self._attr_fan_speed_list = fan_speed_wrapper.options self._attr_fan_speed_list = fan_speed_wrapper.options
@@ -239,27 +159,37 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
@property @property
def activity(self) -> VacuumActivity | None: def activity(self) -> VacuumActivity | None:
"""Return Tuya vacuum device state.""" """Return Tuya vacuum device state."""
return self._read_wrapper(self._activity_wrapper) if (status := self._read_wrapper(self._status_wrapper)) is not None:
return TUYA_STATUS_TO_HA.get(status)
if self._read_wrapper(self._pause_wrapper):
return VacuumActivity.PAUSED
return None
async def async_start(self, **kwargs: Any) -> None: async def async_start(self, **kwargs: Any) -> None:
"""Start the device.""" """Start the device."""
await self._async_send_wrapper_updates(self._action_wrapper, "start") await self._async_send_wrapper_updates(self._switch_wrapper, True)
async def async_stop(self, **kwargs: Any) -> None: async def async_stop(self, **kwargs: Any) -> None:
"""Stop the device.""" """Stop the device."""
await self._async_send_wrapper_updates(self._action_wrapper, "stop") await self._async_send_wrapper_updates(self._switch_wrapper, False)
async def async_pause(self, **kwargs: Any) -> None: async def async_pause(self, **kwargs: Any) -> None:
"""Pause the device.""" """Pause the device."""
await self._async_send_wrapper_updates(self._action_wrapper, "pause") await self.async_stop(**kwargs)
async def async_return_to_base(self, **kwargs: Any) -> None: async def async_return_to_base(self, **kwargs: Any) -> None:
"""Return device to dock.""" """Return device to dock."""
await self._async_send_wrapper_updates(self._action_wrapper, "return_to_base") if self._charge_wrapper:
await self._async_send_wrapper_updates(self._charge_wrapper, True)
else:
await self._async_send_wrapper_updates(
self._mode_wrapper, TUYA_MODE_RETURN_HOME
)
async def async_locate(self, **kwargs: Any) -> None: async def async_locate(self, **kwargs: Any) -> None:
"""Locate the device.""" """Locate the device."""
await self._async_send_wrapper_updates(self._action_wrapper, "locate") await self._async_send_wrapper_updates(self._locate_wrapper, True)
async def async_set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None: async def async_set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None:
"""Set fan speed.""" """Set fan speed."""

View File

@@ -83,7 +83,7 @@ def _async_device_entities(
_LOGGER.debug( _LOGGER.debug(
"Adding %s entity %s for %s", "Adding %s entity %s for %s",
klass.__name__, klass.__name__,
description.key, description.name,
device.display_name, device.display_name,
) )
continue continue
@@ -111,7 +111,7 @@ def _async_device_entities(
_LOGGER.debug( _LOGGER.debug(
"Adding %s entity %s for %s", "Adding %s entity %s for %s",
klass.__name__, klass.__name__,
description.key, description.name,
device.display_name, device.display_name,
) )
@@ -252,11 +252,16 @@ class BaseProtectEntity(Entity):
if changed: if changed:
if _LOGGER.isEnabledFor(logging.DEBUG): if _LOGGER.isEnabledFor(logging.DEBUG):
device_name = device.name or ""
if hasattr(self, "entity_description") and self.entity_description.name:
device_name += f" {self.entity_description.name}"
_LOGGER.debug( _LOGGER.debug(
"Updating state [%s] %s -> %s", "Updating state [%s (%s)] %s -> %s",
self.entity_id, device_name,
device.mac,
previous_attrs, previous_attrs,
tuple(getter() for getter in self._state_getters), tuple((getattr(self, attr)) for attr in self._state_attrs),
) )
self.async_write_ha_state() self.async_write_ha_state()

View File

@@ -377,7 +377,9 @@ class ProtectSelects(ProtectDeviceEntity, SelectEntity):
entity_description.entity_category is not None entity_description.entity_category is not None
and entity_description.ufp_options_fn is not None and entity_description.ufp_options_fn is not None
): ):
_LOGGER.debug("Updating dynamic select options for %s", self.entity_id) _LOGGER.debug(
"Updating dynamic select options for %s", entity_description.name
)
self._async_set_options(self.data, entity_description) self._async_set_options(self.data, entity_description)
if (unifi_value := entity_description.get_ufp_value(device)) is None: if (unifi_value := entity_description.get_ufp_value(device)) is None:
unifi_value = TYPE_EMPTY_VALUE unifi_value = TYPE_EMPTY_VALUE

View File

@@ -3344,7 +3344,7 @@
}, },
"kmtronic": { "kmtronic": {
"name": "KMtronic", "name": "KMtronic",
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_push" "iot_class": "local_push"
}, },
@@ -3363,7 +3363,7 @@
}, },
"kodi": { "kodi": {
"name": "Kodi", "name": "Kodi",
"integration_type": "service", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_push" "iot_class": "local_push"
}, },
@@ -3386,13 +3386,13 @@
}, },
"kostal_plenticore": { "kostal_plenticore": {
"name": "Kostal Plenticore Solar Inverter", "name": "Kostal Plenticore Solar Inverter",
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_polling" "iot_class": "local_polling"
}, },
"kraken": { "kraken": {
"name": "Kraken", "name": "Kraken",
"integration_type": "service", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "cloud_polling" "iot_class": "cloud_polling"
}, },
@@ -3403,7 +3403,7 @@
}, },
"kulersky": { "kulersky": {
"name": "Kuler Sky", "name": "Kuler Sky",
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_polling" "iot_class": "local_polling"
}, },
@@ -3439,7 +3439,7 @@
}, },
"landisgyr_heat_meter": { "landisgyr_heat_meter": {
"name": "Landis+Gyr Heat Meter", "name": "Landis+Gyr Heat Meter",
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_polling" "iot_class": "local_polling"
}, },
@@ -3451,7 +3451,7 @@
}, },
"lastfm": { "lastfm": {
"name": "Last.fm", "name": "Last.fm",
"integration_type": "service", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "cloud_polling" "iot_class": "cloud_polling"
}, },
@@ -3482,13 +3482,13 @@
}, },
"leaone": { "leaone": {
"name": "LeaOne", "name": "LeaOne",
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_push" "iot_class": "local_push"
}, },
"led_ble": { "led_ble": {
"name": "LED BLE", "name": "LED BLE",
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_polling" "iot_class": "local_polling"
}, },
@@ -3536,7 +3536,7 @@
"name": "LG Netcast" "name": "LG Netcast"
}, },
"lg_soundbar": { "lg_soundbar": {
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_polling", "iot_class": "local_polling",
"name": "LG Soundbars" "name": "LG Soundbars"
@@ -3569,7 +3569,7 @@
}, },
"lifx": { "lifx": {
"name": "LIFX", "name": "LIFX",
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_polling" "iot_class": "local_polling"
}, },
@@ -3727,7 +3727,7 @@
}, },
"loqed": { "loqed": {
"name": "LOQED Touch Smart Lock", "name": "LOQED Touch Smart Lock",
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_push" "iot_class": "local_push"
}, },
@@ -3796,7 +3796,7 @@
}, },
"mailgun": { "mailgun": {
"name": "Mailgun", "name": "Mailgun",
"integration_type": "service", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "cloud_push" "iot_class": "cloud_push"
}, },
@@ -3866,7 +3866,7 @@
}, },
"medcom_ble": { "medcom_ble": {
"name": "Medcom Bluetooth", "name": "Medcom Bluetooth",
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_polling" "iot_class": "local_polling"
}, },
@@ -3899,7 +3899,7 @@
"name": "Melnor", "name": "Melnor",
"integrations": { "integrations": {
"melnor": { "melnor": {
"integration_type": "device", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "local_polling", "iot_class": "local_polling",
"name": "Melnor Bluetooth" "name": "Melnor Bluetooth"

7
requirements_all.txt generated
View File

@@ -252,7 +252,7 @@ aioelectricitymaps==1.1.1
aioemonitor==1.0.5 aioemonitor==1.0.5
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==43.3.0 aioesphomeapi==43.0.0
# homeassistant.components.matrix # homeassistant.components.matrix
# homeassistant.components.slack # homeassistant.components.slack
@@ -1918,6 +1918,9 @@ pybalboa==1.1.3
# homeassistant.components.bbox # homeassistant.components.bbox
pybbox==0.0.5-alpha pybbox==0.0.5-alpha
# homeassistant.components.blackbird
pyblackbird==0.6
# homeassistant.components.bluesound # homeassistant.components.bluesound
pyblu==2.0.5 pyblu==2.0.5
@@ -2297,7 +2300,7 @@ pypaperless==4.1.1
pypca==0.0.7 pypca==0.0.7
# homeassistant.components.lcn # homeassistant.components.lcn
pypck==0.9.8 pypck==0.9.7
# homeassistant.components.pglab # homeassistant.components.pglab
pypglab==0.0.5 pypglab==0.0.5

View File

@@ -243,7 +243,7 @@ aioelectricitymaps==1.1.1
aioemonitor==1.0.5 aioemonitor==1.0.5
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==43.3.0 aioesphomeapi==43.0.0
# homeassistant.components.matrix # homeassistant.components.matrix
# homeassistant.components.slack # homeassistant.components.slack
@@ -1637,6 +1637,9 @@ pyaussiebb==0.1.5
# homeassistant.components.balboa # homeassistant.components.balboa
pybalboa==1.1.3 pybalboa==1.1.3
# homeassistant.components.blackbird
pyblackbird==0.6
# homeassistant.components.bluesound # homeassistant.components.bluesound
pyblu==2.0.5 pyblu==2.0.5
@@ -1938,7 +1941,7 @@ pypalazzetti==0.1.20
pypaperless==4.1.1 pypaperless==4.1.1
# homeassistant.components.lcn # homeassistant.components.lcn
pypck==0.9.8 pypck==0.9.7
# homeassistant.components.pglab # homeassistant.components.pglab
pypglab==0.0.5 pypglab==0.0.5

View File

@@ -1,3 +0,0 @@
"""Fixtures for component."""
collect_ignore_glob = ["test_*.py"]

View File

@@ -0,0 +1,228 @@
"""Test input boolean triggers."""
from collections.abc import Generator
from unittest.mock import patch
import pytest
from homeassistant.components.input_boolean import DOMAIN
from homeassistant.const import ATTR_LABEL_ID, CONF_ENTITY_ID, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant, ServiceCall
from tests.components import (
StateDescription,
arm_trigger,
parametrize_target_entities,
parametrize_trigger_states,
set_or_remove_state,
target_entities,
)
@pytest.fixture(autouse=True, name="stub_blueprint_populate")
def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
"""Stub copying the blueprints to the config folder."""
@pytest.fixture(name="enable_experimental_triggers_conditions")
def enable_experimental_triggers_conditions() -> Generator[None]:
"""Enable experimental triggers and conditions."""
with patch(
"homeassistant.components.labs.async_is_preview_feature_enabled",
return_value=True,
):
yield
@pytest.fixture
async def target_input_booleans(hass: HomeAssistant) -> list[str]:
"""Create multiple input_boolean entities associated with different targets."""
return (await target_entities(hass, DOMAIN))["included"]
@pytest.mark.parametrize(
"trigger_key",
[
"input_boolean.turned_off",
"input_boolean.turned_on",
],
)
async def test_input_boolean_triggers_gated_by_labs_flag(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, trigger_key: str
) -> None:
"""Test the input_boolean 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_experimental_triggers_conditions")
@pytest.mark.parametrize(
("trigger_target_config", "entity_id", "entities_in_target"),
parametrize_target_entities(DOMAIN),
)
@pytest.mark.parametrize(
("trigger", "states"),
[
*parametrize_trigger_states(
trigger="input_boolean.turned_off",
target_states=[STATE_OFF],
other_states=[STATE_ON],
),
*parametrize_trigger_states(
trigger="input_boolean.turned_on",
target_states=[STATE_ON],
other_states=[STATE_OFF],
),
],
)
async def test_input_boolean_state_trigger_behavior_any(
hass: HomeAssistant,
service_calls: list[ServiceCall],
target_input_booleans: list[str],
trigger_target_config: dict,
entity_id: str,
entities_in_target: int,
trigger: str,
states: list[StateDescription],
) -> None:
"""Test that the input_boolean state trigger fires when any input_boolean state changes to a specific state."""
other_entity_ids = set(target_input_booleans) - {entity_id}
# Set all input_booleans, including the tested one, to the initial state
for eid in target_input_booleans:
set_or_remove_state(hass, eid, states[0]["included"])
await hass.async_block_till_done()
await arm_trigger(hass, trigger, {}, 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 input_booleans 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()
@pytest.mark.usefixtures("enable_experimental_triggers_conditions")
@pytest.mark.parametrize(
("trigger_target_config", "entity_id", "entities_in_target"),
parametrize_target_entities(DOMAIN),
)
@pytest.mark.parametrize(
("trigger", "states"),
[
*parametrize_trigger_states(
trigger="input_boolean.turned_off",
target_states=[STATE_OFF],
other_states=[STATE_ON],
),
*parametrize_trigger_states(
trigger="input_boolean.turned_on",
target_states=[STATE_ON],
other_states=[STATE_OFF],
),
],
)
async def test_input_boolean_state_trigger_behavior_first(
hass: HomeAssistant,
service_calls: list[ServiceCall],
target_input_booleans: list[str],
trigger_target_config: dict,
entity_id: str,
entities_in_target: int,
trigger: str,
states: list[StateDescription],
) -> None:
"""Test that the input_boolean state trigger fires when the first input_boolean changes to a specific state."""
other_entity_ids = set(target_input_booleans) - {entity_id}
# Set all input_booleans, including the tested one, to the initial state
for eid in target_input_booleans:
set_or_remove_state(hass, eid, states[0]["included"])
await hass.async_block_till_done()
await arm_trigger(hass, trigger, {"behavior": "first"}, 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()
# Triggering other input_booleans should not cause the trigger to fire again
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) == 0
@pytest.mark.usefixtures("enable_experimental_triggers_conditions")
@pytest.mark.parametrize(
("trigger_target_config", "entity_id", "entities_in_target"),
parametrize_target_entities(DOMAIN),
)
@pytest.mark.parametrize(
("trigger", "states"),
[
*parametrize_trigger_states(
trigger="input_boolean.turned_off",
target_states=[STATE_OFF],
other_states=[STATE_ON],
),
*parametrize_trigger_states(
trigger="input_boolean.turned_on",
target_states=[STATE_ON],
other_states=[STATE_OFF],
),
],
)
async def test_input_boolean_state_trigger_behavior_last(
hass: HomeAssistant,
service_calls: list[ServiceCall],
target_input_booleans: list[str],
trigger_target_config: dict,
entity_id: str,
entities_in_target: int,
trigger: str,
states: list[StateDescription],
) -> None:
"""Test that the input_boolean state trigger fires when the last input_boolean changes to a specific state."""
other_entity_ids = set(target_input_booleans) - {entity_id}
# Set all input_booleans, including the tested one, to the initial state
for eid in target_input_booleans:
set_or_remove_state(hass, eid, states[0]["included"])
await hass.async_block_till_done()
await arm_trigger(hass, trigger, {"behavior": "last"}, trigger_target_config)
for state in states[1:]:
included_state = state["included"]
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) == 0
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()

View File

@@ -28,7 +28,7 @@
'platform': 'tuya', 'platform': 'tuya',
'previous_unique_id': None, 'previous_unique_id': None,
'suggested_object_id': None, 'suggested_object_id': None,
'supported_features': <VacuumEntityFeature: 8984>, 'supported_features': <VacuumEntityFeature: 13080>,
'translation_key': None, 'translation_key': None,
'unique_id': 'tuya.mwsaod7fa3gjyh6ids', 'unique_id': 'tuya.mwsaod7fa3gjyh6ids',
'unit_of_measurement': None, 'unit_of_measurement': None,
@@ -38,7 +38,7 @@
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'friendly_name': 'Hoover', 'friendly_name': 'Hoover',
'supported_features': <VacuumEntityFeature: 8984>, 'supported_features': <VacuumEntityFeature: 13080>,
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'vacuum.hoover', 'entity_id': 'vacuum.hoover',