[FIX] Third time the charm
This commit is contained in:
parent
2120685cdf
commit
a3927ba66c
@ -67,8 +67,13 @@ 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:
|
||||||
@ -77,30 +82,17 @@ 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
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
script_obj = script_comp.scripts.get(entity_id)
|
||||||
if not state:
|
if not script_obj:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get script name from entity_id
|
|
||||||
script_name = entity_id.split(".", 1)[1]
|
|
||||||
|
|
||||||
# Get service description which includes field definitions
|
|
||||||
fields = {}
|
|
||||||
try:
|
|
||||||
service_desc = hass.services.async_describe_service("script", script_name)
|
|
||||||
if service_desc and "fields" in service_desc:
|
|
||||||
fields = service_desc["fields"]
|
|
||||||
except Exception as e:
|
|
||||||
_LOGGER.debug(f"Could not get service description for {entity_id}: {e}")
|
|
||||||
|
|
||||||
scripts.append(
|
scripts.append(
|
||||||
{
|
{
|
||||||
"entity_id": entity_id,
|
"entity_id": entity_id,
|
||||||
"friendly_name": state.attributes.get(
|
"friendly_name": script_obj.name or entity_id,
|
||||||
"friendly_name", entity_id
|
"description": script_obj.description or "",
|
||||||
),
|
"fields": script_obj.fields or {},
|
||||||
"description": state.attributes.get("description", ""),
|
"mode": script_obj.mode,
|
||||||
"fields": fields,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -109,6 +101,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
"count": len(scripts),
|
"count": len(scripts),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def get_entity_metadata(call: ServiceCall) -> dict[str, Any]:
|
async def get_entity_metadata(call: ServiceCall) -> dict[str, Any]:
|
||||||
entity_id = call.data.get(CONF_ENTITY_ID)
|
entity_id = call.data.get(CONF_ENTITY_ID)
|
||||||
if not entity_id:
|
if not entity_id:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user