diff --git a/modules/nixos/home-assistant.nix b/modules/nixos/home-assistant.nix index 0c28062b..70185a7c 100644 --- a/modules/nixos/home-assistant.nix +++ b/modules/nixos/home-assistant.nix @@ -42,6 +42,7 @@ in { // { default = elem "androidtv" cfg.extraComponents; }; + grocy.enable = mkEnableOption "Grocy custom component"; brother.enable = mkEnableOption "brother" // { @@ -251,6 +252,9 @@ in { adb-shell androidtvremote2 ]) + (mkIf cfg.grocy.enable [ + (python3Packages.callPackage ../../packages/grocy/pygrocy.nix { }) + ]) ]; extraComponents = mkMerge [ [ diff --git a/nixos/home-assistant.nix b/nixos/home-assistant.nix index cd34cf25..808c940d 100644 --- a/nixos/home-assistant.nix +++ b/nixos/home-assistant.nix @@ -114,6 +114,7 @@ in { prometheus = {}; wake_on_lan = {}; }; + grocy.enable = true; extraComponents = [ "zha" "esphome" diff --git a/packages/grocy/pygrocy.nix b/packages/grocy/pygrocy.nix new file mode 100644 index 00000000..3d59aba1 --- /dev/null +++ b/packages/grocy/pygrocy.nix @@ -0,0 +1,63 @@ +{ lib +, buildPythonPackage +, fetchFromGitHub +, backports-zoneinfo +, deprecation +, pydantic +, requests +, responses +, pre-commit +, isort +, vcrpy +, pytest +, pytest-recording +, pytest-mock +, pythonOlder +# requires an instance of grocy api running... +, doCheckGrocy ? false +}: let + inherit (lib.lists) optional optionals; + inherit (lib.strings) optionalString; +in buildPythonPackage rec { + pname = "pygrocy"; + version = "2.1.0"; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "SebRut"; + repo = "pygrocy"; + rev = "v${version}"; + hash = "sha256-ijwcdWMeBnYPhrNYt/IxucPvzc+0InudLxJSMVwulNw="; + }; + + postPatch = optionalString (!doCheckGrocy) '' + rm test/test_grocy.py + ''; + + propagatedBuildInputs = [ + requests + deprecation + pydantic + ] ++ optional (pythonOlder "3.9") backports-zoneinfo; + + pythonImportsCheck = [ + "pygrocy" + ]; + + checkInputs = [ + pytest + pytest-recording + pytest-mock + ] ++ optionals doCheckGrocy [ + responses + pre-commit + isort + vcrpy + ]; + + meta = { + homepage = "https://github.com/SebRut/pygrocy"; + license = lib.licenses.mit; + broken = pythonOlder "3.8"; + }; +}