-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(homeassistant): add tuya presence sensor zha quirk
- Loading branch information
1 parent
329d9a5
commit e6ac6d8
Showing
7 changed files
with
499 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
{lib, ...} @ args: let | ||
listModulesRecursive = dir: | ||
listFilesWithSuffixRecursive = suffix: dir: | ||
lib.filter | ||
(p: lib.hasSuffix ".nix" p && !(lib.hasPrefix "_" (builtins.baseNameOf p))) | ||
(p: lib.hasSuffix suffix p && !(lib.hasPrefix "_" (builtins.baseNameOf p))) | ||
(lib.filesystem.listFilesRecursive dir); | ||
|
||
listModulesRecursive = listFilesWithSuffixRecursive ".nix"; | ||
|
||
listModulesRecursive' = dir: | ||
lib.filter | ||
(p: p != dir + "/default.nix") | ||
(listModulesRecursive dir); | ||
in { | ||
my = | ||
{ | ||
inherit listModulesRecursive listModulesRecursive'; | ||
inherit listFilesWithSuffixRecursive listModulesRecursive listModulesRecursive'; | ||
} | ||
// lib.foldr (path: acc: acc // (import path args)) {} (listModulesRecursive' ./.); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
config, | ||
lib, | ||
... | ||
}: let | ||
inherit (lib) escapeShellArg escapeShellArgs mdDoc mkAfter mkIf mkOption types; | ||
|
||
cfg = config.services.home-assistant; | ||
|
||
quirksDir = "${cfg.configDir}/zha-quirks"; | ||
in { | ||
# Extend home-assistant module with extra options | ||
options.services.home-assistant = { | ||
customZhaQuirks = mkOption { | ||
type = types.listOf types.path; | ||
default = []; | ||
description = mdDoc '' | ||
List of custom ZHA (Zigbee) quirks to load. | ||
Available quirks can be found below `pkgs.my.home-assistant-custom-zha-quirks`. | ||
''; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
systemd.services.home-assistant.preStart = let | ||
copyZhaQuirks = '' | ||
mkdir -p ${escapeShellArg quirksDir} | ||
# remove quirks symlinked in from below the /nix/store | ||
readarray -d "" quirks < <(find ${escapeShellArg quirksDir} -maxdepth 1 -type l -print0) | ||
for quirk in "''${quirks[@]}"; do | ||
if [[ "$(readlink "$quirk")" =~ ^${escapeShellArg builtins.storeDir} ]]; then | ||
rm "$quirk" | ||
fi | ||
done | ||
# recreate symlinks for desired quirks | ||
declare -a quirks=(${escapeShellArgs cfg.customZhaQuirks}) | ||
for quirk in "''${quirks[@]}"; do | ||
ln -fs "$quirk" ${escapeShellArg quirksDir} | ||
done | ||
''; | ||
in | ||
mkAfter copyZhaQuirks; | ||
|
||
services.home-assistant = { | ||
config = { | ||
zha = mkIf (cfg.customZhaQuirks != []) { | ||
enable_quirks = true; | ||
custom_quirks_path = quirksDir; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Custom quirks for ZHA | ||
# https://github.com/zigpy/zha-device-handlers | ||
{ | ||
lib, | ||
runCommandLocal, | ||
... | ||
}: let | ||
mkQuirk = quirkPath: | ||
runCommandLocal (builtins.baseNameOf quirkPath) {} '' | ||
cp ${quirkPath} $out | ||
''; | ||
|
||
customQuirks = builtins.listToAttrs ( | ||
map | ||
(quirkPath: | ||
lib.nameValuePair | ||
(lib.removeSuffix ".py" (builtins.baseNameOf quirkPath)) | ||
(mkQuirk quirkPath)) | ||
(lib.my.listFilesWithSuffixRecursive ".py" ./.) | ||
); | ||
in | ||
customQuirks |
Oops, something went wrong.