Packages

Home Assistant 中的 Packages 提供了将不同组件的配置捆绑在一起的方法。 我们已经在添加设备页面上介绍了两种配置样式(一起或单独指定平台条目)。 这两种配置方法都需要在主配置文件configuration.yaml 中创建组件键。 使用 Packages, 我们可以使用 splitting the configuration 中引入的 !include 指令来包含不同的组件或部分配置。


Packages 在配置中的核心 homeassistant/packages 下配置,Packages 名称(无空格,全部小写)采用后跟一个带有 Packages config的字典的格式。 例如,package pack_1 将被创建为:

homeassistant:
  ...
  packages: 
    pack_1:
      ...package configuration here...

package 的配置可以包括: switch, light, automation, groups 或大部分的Home Assistant组件。

它可以使用 !include 指定内联或单独的YAML文件。
内联示例,main configuration.yaml

homeassistant:
  ...
  packages: 
    pack_1:
      switch:
        - platform: rest
          ...
      light:
        - platform: rpi
          ...

Include example, main configuration.yaml:

homeassistant:
  ...
  packages: 
    pack_1: !include my_package.yaml

文件 my_package.yaml 包含“顶级”配置:

switch:
  - platform: rest
    ...
light:
  - platform: rpi
    ...
  1. Components where entities are identified by a key that will represent the entity_id ({key: config}) need to have unique ‘keys’ between packages and the main configuration file.

    For example if we have the following in the main config. You are not allowed to re-use “my_input” again for input_boolean in a package:

    yaml input_boolean: my_input:

  2. Any component that is not a platform [2], or dictionaries with Entity ID keys [3] cannot be merged and can only occur once between all packages and the main configuration.

对于要合并的 packages 有一些规则:

  1. 组件名称只能使用基本形式(例如 switchswitch 1switch aa 不被接受)。
  2. 基于平台的组件总是可以合并( light, switch 等)。
  3. 实体由这种键标识:entity_id( {key: config} )的组件,需要在 packages 和主配置文件之间具有唯一的“键”。例如,如果我们在主配置中有以下内容。 您不能在 package 中再次用“my_input”对于 input_boolean
         yaml input_boolean: my_input:
  4. 任何不是平台[2]的组件或实体ID键[3]的字典无法合并,在所有 packages 和主配置之间只能出现一次。

 Components inside packages can only specify platform entries using configuration style 1, where all the platforms are grouped under the component name.

注意: packages 中的组件只能使用配置样式1指定平台条目,其中所有平台都分组在组件名称下。

Create a packages folder

One way to organise packages would be to create a folder named “packages” in your Home Assistant configuration directory. In the packages directory you can store any number of packages in a YAML file. This entry in your configuration.yaml will load all packages:

homeassistant:
  packages: !include_dir_named packages

This uses the concept splitting the configuration and will include all files in a directory with the keys representing the filenames. See the documentation about splitting the configuration for more information about !include_dir_named and other include statements that might be helpful.

创建一个 Package 包文件夹

组织 Package 的一种方法是在Home Assistant配置目录中创建一个名为“packages”的文件夹。 在packages目录中,您可以将任意数量的 Package 存储在YAML文件中。 您的 configuration.yaml 中的此条目将加载所有 Package :

homeassistant:
  packages: !include_dir_named packages

这使用拆分配置的概念,并将包含目录中包含代表文件名的键的所有文件。 有关拆分配置的更多信息,请参阅有关include_dir_named和其他可能有帮助的include语句的文档。

转载于:https://my.oschina.net/u/3379895/blog/1069063

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值