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 area_registry as ar
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.components.script import async_get_script_fields
|
||||
|
||||
_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]:
|
||||
entity_reg = er.async_get(hass)
|
||||
script_comp = hass.data.get("script")
|
||||
|
||||
scripts: list[dict[str, Any]] = []
|
||||
|
||||
if not script_comp:
|
||||
return {"scripts": [], "count": 0}
|
||||
|
||||
for entity_id in hass.states.async_entity_ids("script"):
|
||||
entity_entry = entity_reg.async_get(entity_id)
|
||||
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:
|
||||
continue
|
||||
|
||||
script_obj = script_comp.scripts.get(entity_id)
|
||||
if not script_obj:
|
||||
continue
|
||||
fields = await async_get_script_fields(hass, entity_id)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
scripts.append(
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"friendly_name": script_obj.name or entity_id,
|
||||
"description": script_obj.description or "",
|
||||
"fields": script_obj.fields or {},
|
||||
"mode": script_obj.mode,
|
||||
"friendly_name": state.attributes.get(
|
||||
"friendly_name", entity_id
|
||||
)
|
||||
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