2024年11月22日星期五 上午12:44:38

How to Building a Home Assistant Custom Integration step by step

1 年 前
#20319 引用
How to Building a Home Assistant Custom Component step by step

https://aarongodfrey.dev/home%20automation/building_a_home_assistant_custom_component_part_1/#project-structure


This is the first part of a multi-part tutorial to create a Home Assistant custom component.

Part 1 - Project Structure and Basics (Reading Now!)
Part 2 - Unit Testing and Continuous Integration
Part 3 - Config Flow
Part 4 - Options Flow
Part 5 - Debugging

Home Assistant插件开发简明指南
开发Home Assistant插件可以让你将自定义功能添加到你的智能家居系统中。本文将指导你如何创建一个基本的Home Assistant插件。
环境搭建
首先,确保你安装了Python 3.8或更高版本。使用以下命令创建并激活一个虚拟环境:
python3 -m venv ha_devsource ha_dev/bin/activate
创建插件目录
在Home Assistant的custom_components目录下创建你的插件目录:

mkdir -p ~/.homeassistant/custom_components/my_plugincd ~/.homeassistant/custom_components/my_plugin
插件结构
创建以下文件:
__init__.py: 插件的入口文件。
manifest.json: 插件的元数据文件。
sensor.py: 如果你创建的是一个传感器插件。
编写代码
在__init__.py中,编写插件的初始化代码:


useful links


https://bbs.hassbian.com/thread-25696-1-1.html  cn
0
1 年 前
#20350 引用

Custom Integration Directory Architecture
Custom Integration File Structure


Home Assistant 的集成  遵循特定的目录结构,以便于管理和运行各个集成。以下是基本的目录结构

Custom Integration Directory Architecture


.Server  software
Raspberry Pi 3B
└── .Debain 11 OS
    ├── Python virtual environment  - Home Assistant Core 2022.3.0
    │   ├── /home/homeassistant/.homeassistant/custom_components
    │   │   ├── /xiaomi_gateway3
    │   │   ├── /xiaomi_miot
    │   │   ├── /...
    │   │   └── /mijia_miot
    │   ├── /home/homeassistant/.homeassistant/.storage
    │   └──
    │       └──
    ├──
    ├──
    ├──
    ├──
    └──

每个独立的目录代表一个独立的集成,包含该加载该集成的必要文件。

0
1 年 前
#20351 引用


Custom Integration File Structure

Home Assistant Core can be extended with integrations. Each integration is responsible for a specific domain within Home Assistant. Integrations can listen for or trigger events, offer services, and maintain states.
Integrations are written in Python .

software
Home Assistant Core
└── ./custom_components
    ├── /mijia_miot
    │   ├── /core
    │   │   ├── /const.py
    │   │   ├── /miot_spec.py
    │   │   ├── /...
    │   │   └── /translation_languages.py
    │   ├── /translations
    │   │   ├── /en.json
    │   │   ├── /en.json
    │   │   ├── /...
    │   │   └── /hzh-Hans.json
    │   ├── /manifest.json
    │   └──
    │       └──
    ├──
    ├──
    ├──
    ├──
    └──

Make Python virtual environment + Home Assistant Core run automatically


0
1 年 前
#20372 引用
Step 1. Create file named with Manifest.json


https://developers.home-assistant.io/docs/creating_integration_manifest

Every integration has a manifest file to specify basic information about an integration. This file is stored as manifest.json in your integration directory. It is required to add such a file.

path:/home/homeassistant/.homeassistant/custom_components/mijia_miot/Manifest.json



Manifest.json

{
  "domain": "your_domain_name",
  "name": "Your Integration",
  "codeowners": [],
  "dependencies": [],
  "documentation": "https://www.example.com",
  "integration_type": "hub",
  "iot_class": "cloud_polling",
  "requirements": [],
}





{
  "name": "Mijia Miot",
  "domain": "mijia_miot",
  "version": "0.7.5",
  "config_flow": true,
  "iot_class": "cloud_polling",
  "documentation": "https://github.com/al-one/hass-xiaomi-miot",
  "issue_tracker": "https://github.com/al-one/hass-xiaomi-miot/issues",
  "codeowners": ["@freemsly"],
  "dependencies": [
    "http",
    "persistent_notification",
    "ffmpeg"
  ],
  "after_dependencies": ["homekit"],
  "requirements": [
    "construct==2.10.56",
    "python-miio>=0.5.6",
    "micloud>=0.3"
  ]
}


0
1 年 前
#22503 引用
step 2.restart ha
0
1 年 前
#22504 引用
step 3:add integration test

run ok
0
1 年 前
#22560 引用
Home Assistant的集成现在有一个manifest项叫iot_class,分为

cloud_xx
local_xx


local_xx的一般都支持断网控制,cloud_xx的,这个问题不一概而论,有的可以,有的不可以。
0
1 个月 前
#46566 引用
根目录 包含了核心的源代码和配置文件。
__init__.py: 初始化文件,定义了DashCast组件在Home Assistant中的入口点。
manifest.json: 组件的元数据文件,描述组件的基本信息如名称、作者、所需API权限等。
translations: 存放多语言资源文件夹。
services.yaml: 定义自定义服务的yaml文件,如load_url服务,允许加载指定URL的内容到Chromecast

                        
原文链接:https://blog.csdn.net/gitblog_00021/article/details/141798262
0