nixos/home-assistant: support platform=... scheme for autoExtraComponents
See https://home-assistant.io/components/sensor.luftdaten/ for an example component using that scheme.
This commit is contained in:
parent
88c16a63c6
commit
59eb19224b
|
@ -9,8 +9,27 @@ let
|
|||
|
||||
availableComponents = pkgs.home-assistant.availableComponents;
|
||||
|
||||
# Given component "parentConfig.platform", returns whether config.parentConfig
|
||||
# is a list containing a set with set.platform == "platform".
|
||||
#
|
||||
# For example, the component sensor.luftdaten is used as follows:
|
||||
# config.sensor = [ {
|
||||
# platform = "luftdaten";
|
||||
# ...
|
||||
# } ];
|
||||
useComponentPlatform = component:
|
||||
let
|
||||
path = splitString "." component;
|
||||
parentConfig = attrByPath (init path) null cfg.config;
|
||||
platform = last path;
|
||||
in isList parentConfig && any
|
||||
(item: item.platform or null == platform)
|
||||
parentConfig;
|
||||
|
||||
# Returns whether component is used in config
|
||||
useComponent = component: hasAttrByPath (splitString "." component) cfg.config;
|
||||
useComponent = component:
|
||||
hasAttrByPath (splitString "." component) cfg.config
|
||||
|| useComponentPlatform component;
|
||||
|
||||
# List of components used in config
|
||||
extraComponents = filter useComponent availableComponents;
|
||||
|
|
Loading…
Reference in New Issue