From d280603bd18cb27ce2e6bf6a0f8a163d8568214f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Thu, 25 Apr 2019 15:54:24 +0200 Subject: [PATCH] nixos/home-assistant: account for introduction of manifest.json The `availableComponents` now only contain a single attribute for every integration. --- .../modules/services/misc/home-assistant.nix | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix index 7f8d31bcf0b8..f1b351246740 100644 --- a/nixos/modules/services/misc/home-assistant.nix +++ b/nixos/modules/services/misc/home-assistant.nix @@ -21,32 +21,23 @@ let availableComponents = cfg.package.availableComponents; - # Given component "parentConfig.platform", returns whether config.parentConfig - # is a list containing a set with set.platform == "platform". + usedPlatforms = config: + if isAttrs config then + optional (config ? platform) config.platform + ++ concatMap usedPlatforms (attrValues config) + else if isList config then + concatMap usedPlatforms config + else [ ]; + + # Given a component "platform", looks up whether it is used in the config + # as `platform = "platform";`. # - # For example, the component sensor.luftdaten is used as follows: + # For example, the component mqtt.sensor is used as follows: # config.sensor = [ { - # platform = "luftdaten"; + # platform = "mqtt"; # ... # } ]; - # - # Beginning with 0.87 Home Assistant is migrating their components to the - # scheme "platform.subComponent", e.g. "hue.light" instead of "light.hue". - # See https://developers.home-assistant.io/blog/2019/02/19/the-great-migration.html. - # Hence, we also check whether we find an entry in the config when interpreting - # the first part of the path as the component. - useComponentPlatform = component: - let - path = splitString "." component; - # old: platform is the last part of path - parentConfig = attrByPath (init path) null cfg.config; - platform = last path; - # new: platform is the first part of the path - parentConfig' = attrByPath (tail path) null cfg.config; - platform' = head path; - in - (isList parentConfig && any (item: item.platform or null == platform) parentConfig) - || (isList parentConfig' && any (item: item.platform or null == platform') parentConfig'); + useComponentPlatform = component: elem component (usedPlatforms cfg.config); # Returns whether component is used in config useComponent = component: