← 返回 Skills 市场
usimic

Ha Integration Patterns

作者 usimic · GitHub ↗ · v1.0.0
cross-platform ✓ 安全检测通过
1066
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install ha-integration-patterns
功能描述
Home Assistant custom integration patterns and architectural decisions. Use when building HACS integrations, custom components, or API bridges for Home Assistant. Covers service response data, HTTP views, storage APIs, and integration architecture.
使用说明 (SKILL.md)

Home Assistant Integration Patterns

Service Response Data Pattern

The Problem

By default, HA services are "fire-and-forget" and return empty arrays [].

The Solution (HA 2023.7+)

Register service with supports_response:

from homeassistant.helpers.service import SupportsResponse

hass.services.async_register(
    domain, 
    "get_full_config", 
    handle_get_full_config,
    schema=GET_CONFIG_SCHEMA,
    supports_response=SupportsResponse.ONLY,  # ← KEY PARAMETER
)

Call with ?return_response flag:

curl -X POST "$HA_URL/api/services/your_domain/get_full_config?return_response"

Response Handler

async def handle_get_full_config(hass: HomeAssistant, call: ServiceCall):
    """Handle the service call and return data."""
    # ... your logic ...
    return {"entities": entity_data, "automations": automation_data}

HTTP View vs Service: When to Use Each

Use Case Use Don't Use
Return complex data HTTP View Service (without response support)
Fire-and-forget actions Service HTTP View
Trigger automations Service HTTP View
Query state/config HTTP View Internal storage APIs

HTTP View Pattern

For data retrieval APIs:

from homeassistant.components.http import HomeAssistantView

class OpenClawConfigView(HomeAssistantView):
    """HTTP view for retrieving config."""
    url = "/api/openclaw/config"
    name = "api:openclaw:config"
    requires_auth = True

    async def get(self, request):
        hass = request.app["hass"]
        config = await get_config_data(hass)
        return json_response(config)

# Register in async_setup:
hass.http.register_view(OpenClawConfigView())

Critical: Avoid Internal APIs

Never use underscore-prefixed APIs — they're private and change between versions.

Wrong:

storage_collection = hass.data["_storage_collection"]

Right:

# Use public APIs only
from homeassistant.helpers.storage import Store
store = Store(hass, STORAGE_VERSION, STORAGE_KEY)

Storage Patterns

For Small Data (Settings, Cache)

from homeassistant.helpers.storage import Store

STORAGE_KEY = "your_domain.storage"
STORAGE_VERSION = 1

store = Store(hass, STORAGE_VERSION, STORAGE_KEY)

# Save
data = {"entities": modified_entities}
await store.async_save(data)

# Load
data = await store.async_load()

For Large Data (History, Logs)

Use external database or file storage, not HA storage helpers.


Breaking Changes to Watch

Change Version Migration
Conversation agents 2025.x+ Use async_process directly
Service response data 2023.7+ Add supports_response param
Config entry migration 2022.x+ Use async_migrate_entry

Always check: https://www.home-assistant.io/blog/ for your target version range.


HACS Integration Structure

custom_components/your_domain/
├── __init__.py          # async_setup_entry
├── config_flow.py       # UI configuration
├── manifest.json        # Dependencies, version
├── services.yaml        # Service definitions
└── storage_services.py  # Your storage logic

Minimal manifest.json

{
  "domain": "your_domain",
  "name": "Your Integration",
  "codeowners": ["@yourusername"],
  "config_flow": true,
  "dependencies": [],
  "requirements": [],
  "version": "1.0.0"
}

Testing Checklist

  • Service calls return expected data (with ?return_response)
  • HTTP views accessible with auth token
  • No underscore-prefixed API usage
  • Storage persists across restarts
  • Config flow creates config entry
  • Error handling returns meaningful messages

Documentation Resources

  • Integration basics: developers.home-assistant.io/docs/creating_integration_index
  • Service calls: developers.home-assistant.io/docs/dev_101_services
  • HTTP views: developers.home-assistant.io/docs/api/webserver
  • Breaking changes: home-assistant.io/blog/ (filter by version)
  • HACS guidelines: hacs.xyz/docs/publish/start

Lesson Learned

From HA-OpenClaw Bridge attempt:

"80% of our issues were discoverable with 30-60 minutes of upfront docs reading. We jumped straight to coding based on assumptions rather than reading how HA actually works."

Use skills/pre-coding-research/ methodology before starting.

安全使用建议
This appears to be a straightforward, coherent guide for writing Home Assistant integrations. Before using it in a production project: (1) cross-check examples and breaking-change notes against the official Home Assistant developer docs (the skill provides links); (2) be aware example commands reference an HA_URL and auth token — keep tokens secret and test in a dev instance; (3) the skill has no source/homepage listed — if you plan to copy templates or manifest content into a published integration (HACS), confirm licensing and origin; (4) always review any code you paste into an integration (the guidance is safe, but mistakes in your implementation can introduce vulnerabilities).
功能分析
Type: OpenClaw Skill Name: ha-integration-patterns Version: 1.0.0 The skill bundle contains metadata and a markdown document providing architectural guidance and best practices for developing Home Assistant integrations. The content is purely educational, offering advice on service responses, HTTP views, storage, and avoiding internal APIs. There are no executable commands for the agent, no prompt injection attempts, no data exfiltration, or any other malicious indicators. The provided code snippets are illustrative examples for human developers, not instructions for the AI agent to execute.
能力评估
Purpose & Capability
The name/description (HA integration patterns) matches the SKILL.md content: service responses, HTTP views, storage, manifest structure, and testing guidance. There are no unrelated requirements (no binaries, env vars, or installs) that conflict with the stated purpose.
Instruction Scope
The instructions stay on-topic: describe HA APIs, code examples, and testing checks. The doc does not ask the agent to read unrelated system files, exfiltrate data, or call unexpected external endpoints. Minor note: examples reference an environment variable ($HA_URL) and mention using auth tokens, but these are illustrative examples relevant to testing and expected for integration development.
Install Mechanism
No install spec and no code files — instruction-only content. This minimizes on-disk execution risk; nothing is downloaded or installed by the skill itself.
Credentials
The skill declares no required environment variables or credentials, which is proportional for documentation/guidance. Example snippets reference an HA_URL and auth tokens for testing, which is expected for Home Assistant integrations but are not requested by the skill itself.
Persistence & Privilege
always is false and the skill is not asking for any elevated or persistent platform privileges. Autonomous model invocation is allowed (platform default) but the skill is instruction-only so it cannot execute code or persist artifacts on its own.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install ha-integration-patterns
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /ha-integration-patterns 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of Home Assistant Integration Patterns documentation. - Provides architectural guidance for Home Assistant custom integrations, HACS components, and API bridges. - Explains how to return data from services with the new `supports_response` parameter. - Details when to use HTTP views versus services, with code samples. - Highlights safe use of storage APIs, avoiding internal/private APIs. - Includes HACS integration file structure and minimal `manifest.json` example. - Features a practical testing checklist and documentation links. - Summarizes key lessons learned from real integration scenarios.
元数据
Slug ha-integration-patterns
版本 1.0.0
许可证
累计安装 1
当前安装数 1
历史版本数 1
常见问题

Ha Integration Patterns 是什么?

Home Assistant custom integration patterns and architectural decisions. Use when building HACS integrations, custom components, or API bridges for Home Assistant. Covers service response data, HTTP views, storage APIs, and integration architecture. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1066 次。

如何安装 Ha Integration Patterns?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install ha-integration-patterns」即可一键安装,无需额外配置。

Ha Integration Patterns 是免费的吗?

是的,Ha Integration Patterns 完全免费(开源免费),可自由下载、安装和使用。

Ha Integration Patterns 支持哪些平台?

Ha Integration Patterns 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Ha Integration Patterns?

由 usimic(@usimic)开发并维护,当前版本 v1.0.0。

💬 留言讨论