Validate generated device actions (#27262)
* Validate generated actions * Use hass.services.async_call instead of service.async_call_from_config
This commit is contained in:
parent
1a9d07dbdc
commit
0ba4ee1398
3 changed files with 12 additions and 16 deletions
|
@ -17,6 +17,7 @@ from homeassistant.components.device_automation.const import (
|
|||
CONF_TURNED_ON,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_CONDITION,
|
||||
CONF_ENTITY_ID,
|
||||
CONF_FOR,
|
||||
|
@ -24,7 +25,7 @@ from homeassistant.const import (
|
|||
CONF_TYPE,
|
||||
)
|
||||
from homeassistant.helpers.entity_registry import async_entries_for_device
|
||||
from homeassistant.helpers import condition, config_validation as cv, service
|
||||
from homeassistant.helpers import condition, config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
||||
from . import TRIGGER_BASE_SCHEMA
|
||||
|
||||
|
@ -112,13 +113,10 @@ async def async_call_action_from_config(
|
|||
else:
|
||||
action = "toggle"
|
||||
|
||||
service_action = {
|
||||
service.CONF_SERVICE: "{}.{}".format(domain, action),
|
||||
CONF_ENTITY_ID: config[CONF_ENTITY_ID],
|
||||
}
|
||||
service_data = {ATTR_ENTITY_ID: config[CONF_ENTITY_ID]}
|
||||
|
||||
await service.async_call_from_config(
|
||||
hass, service_action, blocking=True, variables=variables, context=context
|
||||
await hass.services.async_call(
|
||||
domain, action, service_data, blocking=True, context=context
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_TYPE
|
||||
from homeassistant.core import Context, HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
||||
|
||||
from . import DOMAIN
|
||||
|
@ -78,13 +78,10 @@ async def _execute_service_based_action(
|
|||
service_name = SERVICE_NAMES[action_type]
|
||||
zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID])
|
||||
|
||||
service_action = {
|
||||
service.CONF_SERVICE: "{}.{}".format(DOMAIN, service_name),
|
||||
ATTR_DATA: {ATTR_IEEE: str(zha_device.ieee)},
|
||||
}
|
||||
service_data = {ATTR_IEEE: str(zha_device.ieee)}
|
||||
|
||||
await service.async_call_from_config(
|
||||
hass, service_action, blocking=True, variables=variables, context=context
|
||||
await hass.services.async_call(
|
||||
DOMAIN, service_name, service_data, blocking=True, context=context
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ from homeassistant.helpers import device_registry
|
|||
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
assert_lists_same,
|
||||
async_mock_service,
|
||||
mock_device_registry,
|
||||
mock_registry,
|
||||
|
@ -28,7 +29,7 @@ def entity_reg(hass):
|
|||
|
||||
|
||||
async def test_get_actions(hass, device_reg, entity_reg):
|
||||
"""Test we get the expected actions from a switch."""
|
||||
"""Test we get the expected actions from a NEW_DOMAIN."""
|
||||
config_entry = MockConfigEntry(domain="test", data={})
|
||||
config_entry.add_to_hass(hass)
|
||||
device_entry = device_reg.async_get_or_create(
|
||||
|
@ -51,7 +52,7 @@ async def test_get_actions(hass, device_reg, entity_reg):
|
|||
},
|
||||
]
|
||||
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
||||
assert actions == expected_actions
|
||||
assert_lists_same(actions, expected_actions)
|
||||
|
||||
|
||||
async def test_action(hass):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue