diff --git a/custom_components/mcp_bridge/__init__.py b/custom_components/mcp_bridge/__init__.py index cb02fd0..6db314e 100644 --- a/custom_components/mcp_bridge/__init__.py +++ b/custom_components/mcp_bridge/__init__.py @@ -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 {}, } )