Fix fan device actions (#102797)

This commit is contained in:
Erik Montnemery 2023-10-26 05:22:38 +02:00 committed by GitHub
parent e5078a3e13
commit 43ac77ca2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -3,14 +3,24 @@ from __future__ import annotations
import voluptuous as vol import voluptuous as vol
from homeassistant.components.device_automation import toggle_entity from homeassistant.components.device_automation import (
async_validate_entity_schema,
toggle_entity,
)
from homeassistant.const import CONF_DOMAIN from homeassistant.const import CONF_DOMAIN
from homeassistant.core import Context, HomeAssistant from homeassistant.core import Context, HomeAssistant
from homeassistant.helpers.typing import ConfigType, TemplateVarsType from homeassistant.helpers.typing import ConfigType, TemplateVarsType
from . import DOMAIN from . import DOMAIN
ACTION_SCHEMA = toggle_entity.ACTION_SCHEMA.extend({vol.Required(CONF_DOMAIN): DOMAIN}) _ACTION_SCHEMA = toggle_entity.ACTION_SCHEMA.extend({vol.Required(CONF_DOMAIN): DOMAIN})
async def async_validate_action_config(
hass: HomeAssistant, config: ConfigType
) -> ConfigType:
"""Validate config."""
return async_validate_entity_schema(hass, config, _ACTION_SCHEMA)
async def async_get_actions( async def async_get_actions(

View File

@ -171,6 +171,7 @@ async def test_action(
hass.bus.async_fire("test_event_turn_off") hass.bus.async_fire("test_event_turn_off")
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(turn_off_calls) == 1 assert len(turn_off_calls) == 1
assert turn_off_calls[0].data["entity_id"] == entry.entity_id
assert len(turn_on_calls) == 0 assert len(turn_on_calls) == 0
assert len(toggle_calls) == 0 assert len(toggle_calls) == 0
@ -178,6 +179,7 @@ async def test_action(
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(turn_off_calls) == 1 assert len(turn_off_calls) == 1
assert len(turn_on_calls) == 1 assert len(turn_on_calls) == 1
assert turn_on_calls[0].data["entity_id"] == entry.entity_id
assert len(toggle_calls) == 0 assert len(toggle_calls) == 0
hass.bus.async_fire("test_event_toggle") hass.bus.async_fire("test_event_toggle")
@ -185,6 +187,7 @@ async def test_action(
assert len(turn_off_calls) == 1 assert len(turn_off_calls) == 1
assert len(turn_on_calls) == 1 assert len(turn_on_calls) == 1
assert len(toggle_calls) == 1 assert len(toggle_calls) == 1
assert toggle_calls[0].data["entity_id"] == entry.entity_id
async def test_action_legacy( async def test_action_legacy(