mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add an action enum to command_line (#190154)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Services for the command_line integration."""
|
||||
|
||||
from homeassistant.const import SERVICE_RELOAD
|
||||
from enum import StrEnum
|
||||
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.helpers.entity_platform import async_get_platforms
|
||||
from homeassistant.helpers.reload import async_integration_yaml_config
|
||||
@@ -11,6 +12,12 @@ from .helpers import async_load_platforms
|
||||
from .utils import async_refresh_shell_template_issues
|
||||
|
||||
|
||||
class CommandLineService(StrEnum):
|
||||
"""Store keys for Command Line services."""
|
||||
|
||||
RELOAD = "reload"
|
||||
|
||||
|
||||
async def _async_reload_config(call: ServiceCall) -> None:
|
||||
"""Reload Command Line."""
|
||||
hass = call.hass
|
||||
@@ -29,4 +36,6 @@ async def _async_reload_config(call: ServiceCall) -> None:
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Register the command_line services."""
|
||||
async_register_admin_service(hass, DOMAIN, SERVICE_RELOAD, _async_reload_config)
|
||||
async_register_admin_service(
|
||||
hass, DOMAIN, CommandLineService.RELOAD, _async_reload_config
|
||||
)
|
||||
|
||||
@@ -21,17 +21,13 @@ from homeassistant.components.command_line.const import DOMAIN
|
||||
from homeassistant.components.command_line.notify import (
|
||||
async_get_service as async_get_notify_service,
|
||||
)
|
||||
from homeassistant.components.command_line.services import CommandLineService
|
||||
from homeassistant.components.command_line.utils import build_shell_template_issue_id
|
||||
from homeassistant.components.notify import (
|
||||
DOMAIN as NOTIFY_DOMAIN,
|
||||
BaseNotificationService,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
SERVICE_RELOAD,
|
||||
STATE_ON,
|
||||
STATE_OPEN,
|
||||
__version__ as HA_VERSION,
|
||||
)
|
||||
from homeassistant.const import STATE_ON, STATE_OPEN, __version__ as HA_VERSION
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
@@ -107,7 +103,7 @@ async def test_reload_service(
|
||||
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_RELOAD,
|
||||
CommandLineService.RELOAD,
|
||||
{},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -126,7 +122,7 @@ async def test_reload_service(
|
||||
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_RELOAD,
|
||||
CommandLineService.RELOAD,
|
||||
{},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -175,7 +171,9 @@ async def test_reload_prunes_stale_template_issue(
|
||||
|
||||
yaml_path = get_fixture_path("configuration_empty.yaml", "command_line")
|
||||
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
|
||||
await hass.services.async_call(DOMAIN, SERVICE_RELOAD, {}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN, CommandLineService.RELOAD, {}, blocking=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert not any(
|
||||
@@ -227,7 +225,9 @@ async def test_reload_keeps_valid_template_issue_and_ignore_state(
|
||||
patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path),
|
||||
mock_asyncio_subprocess_run(b"safe_value\n"),
|
||||
):
|
||||
await hass.services.async_call(DOMAIN, SERVICE_RELOAD, {}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN, CommandLineService.RELOAD, {}, blocking=True
|
||||
)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
kept_issue = issue_registry.issues.get((DOMAIN, issue.issue_id))
|
||||
@@ -294,7 +294,9 @@ async def test_reload_keeps_issues_of_entities_set_up_again(
|
||||
async_get_service_later,
|
||||
),
|
||||
):
|
||||
await hass.services.async_call(DOMAIN, SERVICE_RELOAD, {}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN, CommandLineService.RELOAD, {}, blocking=True
|
||||
)
|
||||
notify_setup.set()
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user