Skip to content

Commit

Permalink
Ensure script services have a name
Browse files Browse the repository at this point in the history
  • Loading branch information
spacegaier committed Mar 29, 2021
1 parent 1c9a9be commit 9464cb4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions homeassistant/components/python_script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
import voluptuous as vol

from homeassistant.const import SERVICE_RELOAD
from homeassistant.const import CONF_DESCRIPTION, CONF_NAME, SERVICE_RELOAD
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.service import async_set_service_schema
from homeassistant.loader import bind_hass
Expand Down Expand Up @@ -71,6 +71,8 @@
"get_age",
}

CONF_FIELDS = "fields"


class ScriptError(HomeAssistantError):
"""When a script error occurs."""
Expand Down Expand Up @@ -125,8 +127,9 @@ def python_script_service_handler(call):
hass.services.register(DOMAIN, name, python_script_service_handler)

service_desc = {
"description": services_dict.get(name, {}).get("description", ""),
"fields": services_dict.get(name, {}).get("fields", {}),
CONF_NAME: services_dict.get(name, {}).get("name", name),
CONF_DESCRIPTION: services_dict.get(name, {}).get("description", ""),
CONF_FIELDS: services_dict.get(name, {}).get("fields", {}),
}
async_set_service_schema(hass, DOMAIN, name, service_desc)

Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/python_script/services.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Describes the format for available python_script services

reload:
name: Reload
description: Reload all available python_scripts
4 changes: 3 additions & 1 deletion homeassistant/components/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
ATTR_ENTITY_ID,
ATTR_NAME,
CONF_ALIAS,
CONF_DESCRIPTION,
CONF_ICON,
CONF_MODE,
CONF_NAME,
CONF_SEQUENCE,
CONF_VARIABLES,
SERVICE_RELOAD,
Expand Down Expand Up @@ -45,7 +47,6 @@
ATTR_LAST_TRIGGERED = "last_triggered"
ATTR_VARIABLES = "variables"

CONF_DESCRIPTION = "description"
CONF_EXAMPLE = "example"
CONF_FIELDS = "fields"

Expand Down Expand Up @@ -241,6 +242,7 @@ async def service_handler(service):

# Register the service description
service_desc = {
CONF_NAME: cfg.get(CONF_ALIAS, ""),
CONF_DESCRIPTION: cfg[CONF_DESCRIPTION],
CONF_FIELDS: cfg[CONF_FIELDS],
}
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/script/services.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# Describes the format for available python_script services

reload:
name: Reload
description: Reload all the available scripts

turn_on:
name: Turn on
description: Turn on script
target:

turn_off:
name: Turn off
description: Turn off script
target:

toggle:
name: Toggle
description: Toggle script
target:
1 change: 1 addition & 0 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
CONF_DEFAULT = "default"
CONF_DELAY = "delay"
CONF_DELAY_TIME = "delay_time"
CONF_DESCRIPTION = "description"
CONF_DEVICE = "device"
CONF_DEVICES = "devices"
CONF_DEVICE_CLASS = "device_class"
Expand Down

0 comments on commit 9464cb4

Please sign in to comment.