Maybe this one will be the one
This commit is contained in:
parent
a3927ba66c
commit
adbf33d3c7
@ -9,6 +9,7 @@ from homeassistant.core import HomeAssistant, ServiceCall, SupportsResponse
|
|||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers import area_registry as ar
|
from homeassistant.helpers import area_registry as ar
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
from homeassistant.components.script import async_get_script_fields
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -67,13 +68,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
|
|
||||||
async def get_exposed_scripts(call: ServiceCall) -> dict[str, Any]:
|
async def get_exposed_scripts(call: ServiceCall) -> dict[str, Any]:
|
||||||
entity_reg = er.async_get(hass)
|
entity_reg = er.async_get(hass)
|
||||||
script_comp = hass.data.get("script")
|
|
||||||
|
|
||||||
scripts: list[dict[str, Any]] = []
|
scripts: list[dict[str, Any]] = []
|
||||||
|
|
||||||
if not script_comp:
|
|
||||||
return {"scripts": [], "count": 0}
|
|
||||||
|
|
||||||
for entity_id in hass.states.async_entity_ids("script"):
|
for entity_id in hass.states.async_entity_ids("script"):
|
||||||
entity_entry = entity_reg.async_get(entity_id)
|
entity_entry = entity_reg.async_get(entity_id)
|
||||||
if not entity_entry:
|
if not entity_entry:
|
||||||
@ -82,17 +78,22 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
if MCP_ACCESSIBLE_LABEL not in entity_entry.labels:
|
if MCP_ACCESSIBLE_LABEL not in entity_entry.labels:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
script_obj = script_comp.scripts.get(entity_id)
|
fields = await async_get_script_fields(hass, entity_id)
|
||||||
if not script_obj:
|
|
||||||
continue
|
state = hass.states.get(entity_id)
|
||||||
|
|
||||||
scripts.append(
|
scripts.append(
|
||||||
{
|
{
|
||||||
"entity_id": entity_id,
|
"entity_id": entity_id,
|
||||||
"friendly_name": script_obj.name or entity_id,
|
"friendly_name": state.attributes.get(
|
||||||
"description": script_obj.description or "",
|
"friendly_name", entity_id
|
||||||
"fields": script_obj.fields or {},
|
)
|
||||||
"mode": script_obj.mode,
|
if state
|
||||||
|
else entity_id,
|
||||||
|
"description": state.attributes.get("description", "")
|
||||||
|
if state
|
||||||
|
else "",
|
||||||
|
"fields": fields or {},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user