Skip to content

Commit

Permalink
nixos/home-assistant: account for "The Great Migration"
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Schütz committed Mar 2, 2019
1 parent 27fb4f4 commit 971187e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions nixos/modules/services/misc/home-assistant.nix
Expand Up @@ -29,14 +29,24 @@ let
# platform = "luftdaten";
# ...
# } ];
#
# 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;
in isList parentConfig && any
(item: item.platform or null == platform)
parentConfig;
# 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');

# Returns whether component is used in config
useComponent = component:
Expand Down

0 comments on commit 971187e

Please sign in to comment.