mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Remove device from device action schema (#26536)
This commit is contained in:
parent
b14b14c3c9
commit
02ded7a4a8
@ -12,7 +12,6 @@ from homeassistant.components.device_automation.const import (
|
|||||||
from homeassistant.core import split_entity_id
|
from homeassistant.core import split_entity_id
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_CONDITION,
|
CONF_CONDITION,
|
||||||
CONF_DEVICE,
|
|
||||||
CONF_DEVICE_ID,
|
CONF_DEVICE_ID,
|
||||||
CONF_DOMAIN,
|
CONF_DOMAIN,
|
||||||
CONF_ENTITY_ID,
|
CONF_ENTITY_ID,
|
||||||
@ -25,18 +24,15 @@ from homeassistant.helpers import condition, config_validation as cv, service
|
|||||||
ENTITY_ACTIONS = [
|
ENTITY_ACTIONS = [
|
||||||
{
|
{
|
||||||
# Turn entity off
|
# Turn entity off
|
||||||
CONF_DEVICE: None,
|
CONF_TYPE: CONF_TURN_OFF
|
||||||
CONF_TYPE: CONF_TURN_OFF,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
# Turn entity on
|
# Turn entity on
|
||||||
CONF_DEVICE: None,
|
CONF_TYPE: CONF_TURN_ON
|
||||||
CONF_TYPE: CONF_TURN_ON,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
# Toggle entity
|
# Toggle entity
|
||||||
CONF_DEVICE: None,
|
CONF_TYPE: CONF_TOGGLE
|
||||||
CONF_TYPE: CONF_TOGGLE,
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -68,8 +64,7 @@ ENTITY_TRIGGERS = [
|
|||||||
|
|
||||||
ACTION_SCHEMA = vol.Schema(
|
ACTION_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_DEVICE): None,
|
vol.Required(CONF_DEVICE_ID): str,
|
||||||
vol.Optional(CONF_DEVICE_ID): str,
|
|
||||||
vol.Required(CONF_DOMAIN): str,
|
vol.Required(CONF_DOMAIN): str,
|
||||||
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
||||||
vol.Required(CONF_TYPE): vol.In([CONF_TOGGLE, CONF_TURN_OFF, CONF_TURN_ON]),
|
vol.Required(CONF_TYPE): vol.In([CONF_TOGGLE, CONF_TURN_OFF, CONF_TURN_ON]),
|
||||||
@ -79,7 +74,7 @@ ACTION_SCHEMA = vol.Schema(
|
|||||||
CONDITION_SCHEMA = vol.Schema(
|
CONDITION_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_CONDITION): "device",
|
vol.Required(CONF_CONDITION): "device",
|
||||||
vol.Optional(CONF_DEVICE_ID): str,
|
vol.Required(CONF_DEVICE_ID): str,
|
||||||
vol.Required(CONF_DOMAIN): str,
|
vol.Required(CONF_DOMAIN): str,
|
||||||
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
||||||
vol.Required(CONF_TYPE): vol.In([CONF_IS_OFF, CONF_IS_ON]),
|
vol.Required(CONF_TYPE): vol.In([CONF_IS_OFF, CONF_IS_ON]),
|
||||||
@ -89,7 +84,7 @@ CONDITION_SCHEMA = vol.Schema(
|
|||||||
TRIGGER_SCHEMA = vol.Schema(
|
TRIGGER_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_PLATFORM): "device",
|
vol.Required(CONF_PLATFORM): "device",
|
||||||
vol.Optional(CONF_DEVICE_ID): str,
|
vol.Required(CONF_DEVICE_ID): str,
|
||||||
vol.Required(CONF_DOMAIN): str,
|
vol.Required(CONF_DOMAIN): str,
|
||||||
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
||||||
vol.Required(CONF_TYPE): vol.In([CONF_TURN_OFF, CONF_TURN_ON]),
|
vol.Required(CONF_TYPE): vol.In([CONF_TURN_OFF, CONF_TURN_ON]),
|
||||||
|
@ -24,7 +24,7 @@ from homeassistant.const import (
|
|||||||
CONF_ALIAS,
|
CONF_ALIAS,
|
||||||
CONF_BELOW,
|
CONF_BELOW,
|
||||||
CONF_CONDITION,
|
CONF_CONDITION,
|
||||||
CONF_DEVICE,
|
CONF_DEVICE_ID,
|
||||||
CONF_DOMAIN,
|
CONF_DOMAIN,
|
||||||
CONF_ENTITY_ID,
|
CONF_ENTITY_ID,
|
||||||
CONF_ENTITY_NAMESPACE,
|
CONF_ENTITY_NAMESPACE,
|
||||||
@ -863,7 +863,7 @@ _SCRIPT_WAIT_TEMPLATE_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
DEVICE_ACTION_SCHEMA = vol.Schema(
|
DEVICE_ACTION_SCHEMA = vol.Schema(
|
||||||
{vol.Required(CONF_DEVICE): None, vol.Required(CONF_DOMAIN): str},
|
{vol.Required(CONF_DEVICE_ID): string, vol.Required(CONF_DOMAIN): str},
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,7 +9,12 @@ from typing import Optional, Sequence, Callable, Dict, List, Set, Tuple
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant, Context, callback, CALLBACK_TYPE
|
from homeassistant.core import HomeAssistant, Context, callback, CALLBACK_TYPE
|
||||||
from homeassistant.const import CONF_CONDITION, CONF_DEVICE, CONF_DOMAIN, CONF_TIMEOUT
|
from homeassistant.const import (
|
||||||
|
CONF_CONDITION,
|
||||||
|
CONF_DEVICE_ID,
|
||||||
|
CONF_DOMAIN,
|
||||||
|
CONF_TIMEOUT,
|
||||||
|
)
|
||||||
from homeassistant import exceptions
|
from homeassistant import exceptions
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
service,
|
service,
|
||||||
@ -66,7 +71,7 @@ def _determine_action(action):
|
|||||||
if CONF_EVENT in action:
|
if CONF_EVENT in action:
|
||||||
return ACTION_FIRE_EVENT
|
return ACTION_FIRE_EVENT
|
||||||
|
|
||||||
if CONF_DEVICE in action:
|
if CONF_DEVICE_ID in action:
|
||||||
return ACTION_DEVICE_AUTOMATION
|
return ACTION_DEVICE_AUTOMATION
|
||||||
|
|
||||||
return ACTION_CALL_SERVICE
|
return ACTION_CALL_SERVICE
|
||||||
|
@ -43,21 +43,18 @@ async def test_websocket_get_actions(hass, hass_ws_client, device_reg, entity_re
|
|||||||
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
|
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
|
||||||
expected_actions = [
|
expected_actions = [
|
||||||
{
|
{
|
||||||
"device": None,
|
|
||||||
"domain": "light",
|
"domain": "light",
|
||||||
"type": "turn_off",
|
"type": "turn_off",
|
||||||
"device_id": device_entry.id,
|
"device_id": device_entry.id,
|
||||||
"entity_id": "light.test_5678",
|
"entity_id": "light.test_5678",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"device": None,
|
|
||||||
"domain": "light",
|
"domain": "light",
|
||||||
"type": "turn_on",
|
"type": "turn_on",
|
||||||
"device_id": device_entry.id,
|
"device_id": device_entry.id,
|
||||||
"entity_id": "light.test_5678",
|
"entity_id": "light.test_5678",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"device": None,
|
|
||||||
"domain": "light",
|
"domain": "light",
|
||||||
"type": "toggle",
|
"type": "toggle",
|
||||||
"device_id": device_entry.id,
|
"device_id": device_entry.id,
|
||||||
|
@ -57,21 +57,18 @@ async def test_get_actions(hass, device_reg, entity_reg):
|
|||||||
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
|
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
|
||||||
expected_actions = [
|
expected_actions = [
|
||||||
{
|
{
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
"type": "turn_off",
|
"type": "turn_off",
|
||||||
"device_id": device_entry.id,
|
"device_id": device_entry.id,
|
||||||
"entity_id": f"{DOMAIN}.test_5678",
|
"entity_id": f"{DOMAIN}.test_5678",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
"type": "turn_on",
|
"type": "turn_on",
|
||||||
"device_id": device_entry.id,
|
"device_id": device_entry.id,
|
||||||
"entity_id": f"{DOMAIN}.test_5678",
|
"entity_id": f"{DOMAIN}.test_5678",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
"type": "toggle",
|
"type": "toggle",
|
||||||
"device_id": device_entry.id,
|
"device_id": device_entry.id,
|
||||||
@ -164,6 +161,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
|||||||
"trigger": {
|
"trigger": {
|
||||||
"platform": "device",
|
"platform": "device",
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "turn_on",
|
"type": "turn_on",
|
||||||
},
|
},
|
||||||
@ -187,6 +185,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
|||||||
"trigger": {
|
"trigger": {
|
||||||
"platform": "device",
|
"platform": "device",
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "turn_off",
|
"type": "turn_off",
|
||||||
},
|
},
|
||||||
@ -248,6 +247,7 @@ async def test_if_state(hass, calls):
|
|||||||
{
|
{
|
||||||
"condition": "device",
|
"condition": "device",
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "is_on",
|
"type": "is_on",
|
||||||
}
|
}
|
||||||
@ -266,6 +266,7 @@ async def test_if_state(hass, calls):
|
|||||||
{
|
{
|
||||||
"condition": "device",
|
"condition": "device",
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "is_off",
|
"type": "is_off",
|
||||||
}
|
}
|
||||||
@ -316,8 +317,8 @@ async def test_action(hass, calls):
|
|||||||
{
|
{
|
||||||
"trigger": {"platform": "event", "event_type": "test_event1"},
|
"trigger": {"platform": "event", "event_type": "test_event1"},
|
||||||
"action": {
|
"action": {
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "turn_off",
|
"type": "turn_off",
|
||||||
},
|
},
|
||||||
@ -325,8 +326,8 @@ async def test_action(hass, calls):
|
|||||||
{
|
{
|
||||||
"trigger": {"platform": "event", "event_type": "test_event2"},
|
"trigger": {"platform": "event", "event_type": "test_event2"},
|
||||||
"action": {
|
"action": {
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "turn_on",
|
"type": "turn_on",
|
||||||
},
|
},
|
||||||
@ -334,8 +335,8 @@ async def test_action(hass, calls):
|
|||||||
{
|
{
|
||||||
"trigger": {"platform": "event", "event_type": "test_event3"},
|
"trigger": {"platform": "event", "event_type": "test_event3"},
|
||||||
"action": {
|
"action": {
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "toggle",
|
"type": "toggle",
|
||||||
},
|
},
|
||||||
|
@ -57,21 +57,18 @@ async def test_get_actions(hass, device_reg, entity_reg):
|
|||||||
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
|
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
|
||||||
expected_actions = [
|
expected_actions = [
|
||||||
{
|
{
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
"type": "turn_off",
|
"type": "turn_off",
|
||||||
"device_id": device_entry.id,
|
"device_id": device_entry.id,
|
||||||
"entity_id": f"{DOMAIN}.test_5678",
|
"entity_id": f"{DOMAIN}.test_5678",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
"type": "turn_on",
|
"type": "turn_on",
|
||||||
"device_id": device_entry.id,
|
"device_id": device_entry.id,
|
||||||
"entity_id": f"{DOMAIN}.test_5678",
|
"entity_id": f"{DOMAIN}.test_5678",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
"type": "toggle",
|
"type": "toggle",
|
||||||
"device_id": device_entry.id,
|
"device_id": device_entry.id,
|
||||||
@ -164,6 +161,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
|||||||
"trigger": {
|
"trigger": {
|
||||||
"platform": "device",
|
"platform": "device",
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "turn_on",
|
"type": "turn_on",
|
||||||
},
|
},
|
||||||
@ -187,6 +185,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
|||||||
"trigger": {
|
"trigger": {
|
||||||
"platform": "device",
|
"platform": "device",
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "turn_off",
|
"type": "turn_off",
|
||||||
},
|
},
|
||||||
@ -248,6 +247,7 @@ async def test_if_state(hass, calls):
|
|||||||
{
|
{
|
||||||
"condition": "device",
|
"condition": "device",
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "is_on",
|
"type": "is_on",
|
||||||
}
|
}
|
||||||
@ -266,6 +266,7 @@ async def test_if_state(hass, calls):
|
|||||||
{
|
{
|
||||||
"condition": "device",
|
"condition": "device",
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "is_off",
|
"type": "is_off",
|
||||||
}
|
}
|
||||||
@ -316,8 +317,8 @@ async def test_action(hass, calls):
|
|||||||
{
|
{
|
||||||
"trigger": {"platform": "event", "event_type": "test_event1"},
|
"trigger": {"platform": "event", "event_type": "test_event1"},
|
||||||
"action": {
|
"action": {
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "turn_off",
|
"type": "turn_off",
|
||||||
},
|
},
|
||||||
@ -325,8 +326,8 @@ async def test_action(hass, calls):
|
|||||||
{
|
{
|
||||||
"trigger": {"platform": "event", "event_type": "test_event2"},
|
"trigger": {"platform": "event", "event_type": "test_event2"},
|
||||||
"action": {
|
"action": {
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "turn_on",
|
"type": "turn_on",
|
||||||
},
|
},
|
||||||
@ -334,8 +335,8 @@ async def test_action(hass, calls):
|
|||||||
{
|
{
|
||||||
"trigger": {"platform": "event", "event_type": "test_event3"},
|
"trigger": {"platform": "event", "event_type": "test_event3"},
|
||||||
"action": {
|
"action": {
|
||||||
"device": None,
|
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
|
"device_id": "",
|
||||||
"entity_id": dev1.entity_id,
|
"entity_id": dev1.entity_id,
|
||||||
"type": "toggle",
|
"type": "toggle",
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user