Home Assistant 集成 OpenWrt 项目教程

Home Assistant 集成 OpenWrt 项目教程

hass_openwrtHome Assistant integration with OpenWrt devices项目地址:https://gitcode.com/gh_mirrors/ha/hass_openwrt

1. 项目的目录结构及介绍

hass_openwrt/
├── custom_components/
│   └── openwrt/
│       ├── __init__.py
│       ├── sensor.py
│       ├── switch.py
│       ├── binary_sensor.py
│       ├── services.py
│       └── config_flow.py
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
└── hacs.json
  • custom_components/openwrt/: 包含所有与 OpenWrt 集成的核心文件。
    • __init__.py: 初始化文件,负责注册组件。
    • sensor.py: 定义传感器实体。
    • switch.py: 定义开关实体。
    • binary_sensor.py: 定义二进制传感器实体。
    • services.py: 定义服务。
    • config_flow.py: 配置流文件,用于配置向导。
  • .gitignore: Git 忽略文件。
  • CHANGELOG.md: 变更日志。
  • LICENSE: 许可证文件。
  • README.md: 项目说明文档。
  • hacs.json: HACS 配置文件。

2. 项目的启动文件介绍

项目的启动文件是 custom_components/openwrt/__init__.py。该文件负责初始化 OpenWrt 集成,并注册传感器、开关和二进制传感器等实体。

# custom_components/openwrt/__init__.py

import logging
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType

_LOGGER = logging.getLogger(__name__)

async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
    _LOGGER.info("Setting up OpenWrt integration")
    # 注册传感器、开关和二进制传感器等实体
    hass.helpers.discovery.load_platform('sensor', 'openwrt', {}, config)
    hass.helpers.discovery.load_platform('switch', 'openwrt', {}, config)
    hass.helpers.discovery.load_platform('binary_sensor', 'openwrt', {}, config)
    return True

3. 项目的配置文件介绍

项目的配置文件主要是 configuration.yaml 文件,用于配置 Home Assistant 集成 OpenWrt 的相关参数。

# configuration.yaml

openwrt:
  host: '192.168.1.1'
  username: 'admin'
  password: 'your_password'
  sensors:
    - type: 'clients'
    - type: 'mesh_peers'
  switches:
    - type: 'wps'
  binary_sensors:
    - type: 'connectivity'
  • host: OpenWrt 设备的 IP 地址。
  • username: 登录用户名。
  • password: 登录密码。
  • sensors: 配置传感器类型。
  • switches: 配置开关类型。
  • binary_sensors: 配置二进制传感器类型。

以上是 Home Assistant 集成 OpenWrt 项目的详细教程,涵盖了项目的目录结构、启动文件和配置文件的介绍。希望对您有所帮助!

hass_openwrtHome Assistant integration with OpenWrt devices项目地址:https://gitcode.com/gh_mirrors/ha/hass_openwrt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

束恺俭Jessie

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值