Use real devices in automation and script tests (#102785)

This commit is contained in:
Erik Montnemery 2023-10-25 16:09:39 +02:00 committed by GitHub
parent e734a4bc53
commit b83ada8c19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 29 deletions

View file

@ -13,7 +13,7 @@ import pytest
import voluptuous as vol
# Otherwise can't test just this file (import order issue)
from homeassistant import exceptions
from homeassistant import config_entries, exceptions
import homeassistant.components.scene as scene
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -33,6 +33,7 @@ from homeassistant.core import (
from homeassistant.exceptions import ConditionError, HomeAssistantError, ServiceNotFound
from homeassistant.helpers import (
config_validation as cv,
device_registry as dr,
entity_registry as er,
script,
template,
@ -43,6 +44,7 @@ from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from tests.common import (
MockConfigEntry,
async_capture_events,
async_fire_time_changed,
async_mock_service,
@ -4532,12 +4534,23 @@ async def test_set_redefines_variable(
assert_action_trace(expected_trace)
async def test_validate_action_config(hass: HomeAssistant) -> None:
async def test_validate_action_config(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Validate action config."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.add_to_hass(hass)
mock_device = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(dr.CONNECTION_NETWORK_MAC, "00:00:00:00:00:02")},
)
def templated_device_action(message):
return {
"device_id": "abcd",
"device_id": mock_device.id,
"domain": "mobile_app",
"message": f"{message} {{{{ 5 + 5}}}}",
"type": "notify",