From 41707ac4ae65c0fc0aa1a43e4954247a98f16653 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Thu, 19 Sep 2024 22:16:11 -0400 Subject: [PATCH] feat(hass): package spotifyplus --- .../homie/modules/home-assistant/assist.nix | 5 +- .../modules/home-assistant/bluetooth.nix | 50 +++++++---- .../homie/modules/home-assistant/default.nix | 1 + flake.lock | Bin 54299 -> 55866 bytes flake.nix | Bin 9105 -> 9533 bytes inputs.nix | 15 ++++ legacyPackages/hass-components/default.nix | 28 +++++- .../extended-ollama-conversation.nix | 34 -------- .../extended-ollama-conversation/default.nix | 23 +++++ .../extended-ollama-conversation/openai.nix | 19 ++++ .../hass-components/spotifyplus/default.nix | 28 ++++++ .../spotifyplus/smartinspect.nix | 23 +++++ .../spotifyplus/spotifywebapi.nix | 35 ++++++++ .../hass-components/spotifyplus/urllib3.nix | 82 ++++++++++++++++++ 14 files changed, 287 insertions(+), 56 deletions(-) delete mode 100644 legacyPackages/hass-components/extended-ollama-conversation.nix create mode 100644 legacyPackages/hass-components/extended-ollama-conversation/default.nix create mode 100644 legacyPackages/hass-components/extended-ollama-conversation/openai.nix create mode 100644 legacyPackages/hass-components/spotifyplus/default.nix create mode 100644 legacyPackages/hass-components/spotifyplus/smartinspect.nix create mode 100644 legacyPackages/hass-components/spotifyplus/spotifywebapi.nix create mode 100644 legacyPackages/hass-components/spotifyplus/urllib3.nix diff --git a/devices/homie/modules/home-assistant/assist.nix b/devices/homie/modules/home-assistant/assist.nix index 9bfcf06b..19967ce4 100644 --- a/devices/homie/modules/home-assistant/assist.nix +++ b/devices/homie/modules/home-assistant/assist.nix @@ -12,7 +12,10 @@ services = { home-assistant = { customComponents = builtins.attrValues { - inherit (self.legacyPackages.${pkgs.system}.hass-components) extended-ollama-conversation; + inherit + (self.legacyPackages.${pkgs.system}.hass-components) + extended-ollama-conversation + ; }; extraComponents = [ diff --git a/devices/homie/modules/home-assistant/bluetooth.nix b/devices/homie/modules/home-assistant/bluetooth.nix index 0e27def5..f87c6910 100644 --- a/devices/homie/modules/home-assistant/bluetooth.nix +++ b/devices/homie/modules/home-assistant/bluetooth.nix @@ -2,10 +2,38 @@ config, lib, pkgs, + self, ... -}: { - # Turn On the speaker automatically when openwakeword is used +}: let + inherit (lib) getExe; + + turnOnUE = pkgs.writeShellApplication { + name = "turnOnUE"; + + runtimeInputs = [config.hardware.bluetooth.package]; + + text = '' + cmd=0x0003 + bt_device_addr=88:C6:26:93:4B:77 + + # This is the MAC address on the first line of `bluetootctl show` + # without the `:` and with `01` added at the end + bt_controller_addr=E848B8C8200001 + + exec gatttool -b $bt_device_addr --char-write-req --handle=$cmd --value=$bt_controller_addr + ''; + }; +in { + environment.systemPackages = [turnOnUE]; + services.home-assistant = { + customComponents = builtins.attrValues { + inherit + (self.legacyPackages.${pkgs.system}.hass-components) + spotifyplus + ; + }; + extraComponents = [ "mpd" @@ -16,23 +44,9 @@ "xiaomi_ble" ]; + # Turn On the speaker automatically when openwakeword is used config = { - shell_command.turn_on_ue = lib.getExe (pkgs.writeShellApplication { - name = "turnOnUE"; - - runtimeInputs = [config.hardware.bluetooth.package]; - - text = '' - cmd=0x0003 - bt_device_addr=88:C6:26:93:4B:77 - - # This is the MAC address on the first line of `bluetootctl show` - # without the `:` and with `01` added at the end - bt_controller_addr=E848B8C8200001 - - exec gatttool -b $bt_device_addr --char-write-req --handle=$cmd --value=$bt_controller_addr - ''; - }); + shell_command.turn_on_ue = getExe turnOnUE; automation = [ { diff --git a/devices/homie/modules/home-assistant/default.nix b/devices/homie/modules/home-assistant/default.nix index 2c4a74dd..86e37e6e 100644 --- a/devices/homie/modules/home-assistant/default.nix +++ b/devices/homie/modules/home-assistant/default.nix @@ -53,6 +53,7 @@ "isal" "met" "spotify" + "switchbot" "upnp" "yamaha_musiccast" ]; diff --git a/flake.lock b/flake.lock index 3b4d465c2cbe886fe9f26c44094be2ab3c74abaa..38d7582f8203c0c009c32db2785fb16c1b3e5d60 100644 GIT binary patch delta 745 zcmaiy%We}f6o!S0R8&}%fM8QX7IaZi?YY?Fh)qKw%Bxm|HRqC0!sP z@dA~X2qAXt0t)J)D|i$hfj1x_5eWsU-uaxP-~V@hzx%Xw_I2s=li{6!_LLVUvEb@K z(&L$II+HBav^|9NI8vS*#C|{dGjgtUeA6{OWuR%}z8_0$xur*|B8!+FENlTS0UifO4%e~x=VxA8Kl?dc$qgm^FExLJZ z2pawEzgoPJjsiiG#7h(n6_0{A3Pq?6XR93tp{teDI<+CUg*!G*Ei5Gwwq-hwONGTb zHzZ?|Ds{-EGK zeww$;%KpA2-nQQ?`)>8$bgs`nR70?>*qg?4@-ubMHB88{O#y~ba2EjTnkI#obTF4L ab%_8BA^k18fHMyJe{vIm(fhO4w|@cp1qF8i delta 28 mcmV+%0OS9K`@|~L{6;)UOKr04M diff --git a/inputs.nix b/inputs.nix index 18a218a2..d3d1ab97 100644 --- a/inputs.nix +++ b/inputs.nix @@ -172,6 +172,21 @@ let owner = "TheNimaj"; repo = "extended_ollama_conversation"; } + { + name = "spotifyplus-src"; + owner = "thlucas1"; + repo = "homeassistantcomponent_spotifyplus"; + } + { + name = "smartinspect-src"; + owner = "thlucas1"; + repo = "SmartInspectPython"; + } + { + name = "spotifywebapi-src"; + owner = "thlucas1"; + repo = "SpotifyWebApiPython"; + } { name = "wakewords-src"; diff --git a/legacyPackages/hass-components/default.nix b/legacyPackages/hass-components/default.nix index bbbd9141..e434660e 100644 --- a/legacyPackages/hass-components/default.nix +++ b/legacyPackages/hass-components/default.nix @@ -1,7 +1,29 @@ {pkgs, ...} @ inputs: pkgs.lib.makeScope pkgs.newScope (hass: let - buildHassComponent = file: - hass.callPackage file (inputs // {}); + spotPython3Packages = pkgs.python3Packages.override { + overrides = self: super: rec { + smartinspect = pkgs.callPackage ./spotifyplus/smartinspect.nix { + inherit (inputs) smartinspect-src; + python3Packages = spotPython3Packages; + }; + + spotifywebapi = pkgs.callPackage ./spotifyplus/spotifywebapi.nix { + inherit (inputs) spotifywebapi-src; + inherit smartinspect urllib3; + python3Packages = spotPython3Packages; + }; + + urllib3 = spotPython3Packages.callPackage ./spotifyplus/urllib3.nix {}; + }; + }; + + buildHassComponent = file: extraArgs: + hass.callPackage file (inputs // extraArgs // {}); in { - extended-ollama-conversation = buildHassComponent ./extended-ollama-conversation.nix; + extended-ollama-conversation = buildHassComponent ./extended-ollama-conversation { + openai = import ./extended-ollama-conversation/openai.nix pkgs; + }; + spotifyplus = buildHassComponent ./spotifyplus { + python3Packages = spotPython3Packages; + }; }) diff --git a/legacyPackages/hass-components/extended-ollama-conversation.nix b/legacyPackages/hass-components/extended-ollama-conversation.nix deleted file mode 100644 index affc726b..00000000 --- a/legacyPackages/hass-components/extended-ollama-conversation.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ - extended-ollama-conversation-src, - buildHomeAssistantComponent, - fetchFromGitHub, - python3Packages, - ... -}: let - inherit (builtins) fromJSON readFile; - - manifest = fromJSON (readFile "${extended-ollama-conversation-src}/custom_components/extended_ollama_conversation/manifest.json"); - - openai = python3Packages.openai.overrideAttrs (o: rec { - name = "${o.pname}-${version}"; - version = "1.3.8"; - - src = fetchFromGitHub { - owner = "openai"; - repo = "openai-python"; - rev = "refs/tags/v${version}"; - hash = "sha256-yU0XWEDYl/oBPpYNFg256H0Hn5AaJiP0vOQhbRLnAxQ="; - }; - - disabledTests = o.disabledTests ++ ["test_retrying_timeout_errors_doesnt_leak" "test_retrying_status_errors_doesnt_leak"]; - }); -in - buildHomeAssistantComponent { - owner = "TheNimaj"; - - inherit (manifest) domain version; - - src = extended-ollama-conversation-src; - - propagatedBuildInputs = [python3Packages.ollama openai]; - } diff --git a/legacyPackages/hass-components/extended-ollama-conversation/default.nix b/legacyPackages/hass-components/extended-ollama-conversation/default.nix new file mode 100644 index 00000000..dc46649e --- /dev/null +++ b/legacyPackages/hass-components/extended-ollama-conversation/default.nix @@ -0,0 +1,23 @@ +{ + extended-ollama-conversation-src, + buildHomeAssistantComponent, + openai, + python3Packages, + ... +}: let + inherit (builtins) fromJSON readFile; + + manifest = fromJSON (readFile "${extended-ollama-conversation-src}/custom_components/extended_ollama_conversation/manifest.json"); +in + buildHomeAssistantComponent { + owner = "TheNimaj"; + + inherit (manifest) domain version; + + src = extended-ollama-conversation-src; + + propagatedBuildInputs = [ + python3Packages.ollama + openai + ]; + } diff --git a/legacyPackages/hass-components/extended-ollama-conversation/openai.nix b/legacyPackages/hass-components/extended-ollama-conversation/openai.nix new file mode 100644 index 00000000..5ff86ad2 --- /dev/null +++ b/legacyPackages/hass-components/extended-ollama-conversation/openai.nix @@ -0,0 +1,19 @@ +pkgs: +pkgs.python3Packages.openai.overrideAttrs (o: rec { + name = "${o.pname}-${version}"; + version = "1.3.8"; + + src = pkgs.fetchFromGitHub { + owner = "openai"; + repo = "openai-python"; + rev = "refs/tags/v${version}"; + hash = "sha256-yU0XWEDYl/oBPpYNFg256H0Hn5AaJiP0vOQhbRLnAxQ="; + }; + + disabledTests = + o.disabledTests + ++ [ + "test_retrying_timeout_errors_doesnt_leak" + "test_retrying_status_errors_doesnt_leak" + ]; +}) diff --git a/legacyPackages/hass-components/spotifyplus/default.nix b/legacyPackages/hass-components/spotifyplus/default.nix new file mode 100644 index 00000000..7b7f5a7b --- /dev/null +++ b/legacyPackages/hass-components/spotifyplus/default.nix @@ -0,0 +1,28 @@ +{ + spotifyplus-src, + buildHomeAssistantComponent, + python3Packages, + ... +}: let + inherit (builtins) fromJSON readFile; + + manifest = fromJSON (readFile "${spotifyplus-src}/custom_components/spotifyplus/manifest.json"); +in + buildHomeAssistantComponent { + owner = "thlucas1"; + + inherit (manifest) domain version; + + src = spotifyplus-src; + + propagatedBuildInputs = with python3Packages; [ + oauthlib + platformdirs + requests + requests_oauthlib + zeroconf + smartinspect # overridden in this python3Packages + spotifywebapi # overridden in this python3Packages + urllib3 # overridden in this python3Packages + ]; + } diff --git a/legacyPackages/hass-components/spotifyplus/smartinspect.nix b/legacyPackages/hass-components/spotifyplus/smartinspect.nix new file mode 100644 index 00000000..d2ff697a --- /dev/null +++ b/legacyPackages/hass-components/spotifyplus/smartinspect.nix @@ -0,0 +1,23 @@ +{ + smartinspect-src, + python3Packages, + ... +}: let + inherit (builtins) elemAt head readFile split; + tag = head (split "\"" (elemAt (split "VERSION:str = \"" (readFile "${smartinspect-src}/smartinspectpython/siconst.py")) 2)); +in + python3Packages.buildPythonPackage { + pname = "smartinspectPython"; + version = "${tag}+${smartinspect-src.shortRev}"; + + src = smartinspect-src; + + propagatedBuildInputs = with python3Packages; [ + pycryptodome + watchdog + ]; + + pythonImportsCheck = [ + "smartinspectpython" + ]; + } diff --git a/legacyPackages/hass-components/spotifyplus/spotifywebapi.nix b/legacyPackages/hass-components/spotifyplus/spotifywebapi.nix new file mode 100644 index 00000000..265ae2fa --- /dev/null +++ b/legacyPackages/hass-components/spotifyplus/spotifywebapi.nix @@ -0,0 +1,35 @@ +{ + spotifywebapi-src, + python3Packages, + ... +}: let + inherit (builtins) elemAt head readFile split; + tag = head (split "\"" (elemAt (split "VERSION:str = \"" (readFile "${spotifywebapi-src}/spotifywebapipython/const.py")) 2)); +in + python3Packages.buildPythonPackage { + pname = "spotifywebapiPython"; + version = "${tag}+${spotifywebapi-src.shortRev}"; + + src = spotifywebapi-src; + + patchPhase = '' + substituteInPlace ./setup.py --replace-warn \ + "docspdoc/build/spotifywebapiPython/" \ + "docspdoc/build/spotifywebapipython/" + ''; + + propagatedBuildInputs = with python3Packages; [ + lxml + oauthlib + platformdirs + requests + requests_oauthlib + zeroconf + smartinspect # overridden in this python3Packages + urllib3 # overridden in this python3Packages + ]; + + pythonImportsCheck = [ + "spotifywebapipython" + ]; + } diff --git a/legacyPackages/hass-components/spotifyplus/urllib3.nix b/legacyPackages/hass-components/spotifyplus/urllib3.nix new file mode 100644 index 00000000..5d8dfc8e --- /dev/null +++ b/legacyPackages/hass-components/spotifyplus/urllib3.nix @@ -0,0 +1,82 @@ +# From nixpkgs 4c0061c983a2bcb888f5c478cfb7631ec1090c22 +{ + lib, + brotli, + brotlicffi, + buildPythonPackage, + certifi, + cryptography, + fetchPypi, + idna, + isPyPy, + mock, + pyopenssl, + pysocks, + pytest-freezegun, + pytest-timeout, + pytestCheckHook, + python-dateutil, + tornado, + trustme, +}: +buildPythonPackage rec { + pname = "urllib3"; + version = "1.26.16"; + format = "setuptools"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-jxNfZQJ1a95rKpsomJ31++h8mXDOyqaQQe3M5/BYmxQ="; + }; + + propagatedBuildInputs = + passthru.optional-dependencies.brotli + ++ passthru.optional-dependencies.socks; + + nativeCheckInputs = [ + python-dateutil + mock + pytest-freezegun + pytest-timeout + pytestCheckHook + tornado + trustme + ]; + + doCheck = false; + + preCheck = '' + export CI # Increases LONG_TIMEOUT + ''; + + pythonImportsCheck = [ + "urllib3" + ]; + + passthru.optional-dependencies = { + brotli = + if isPyPy + then [ + brotlicffi + ] + else [ + brotli + ]; + secure = [ + certifi + cryptography + idna + pyopenssl + ]; + socks = [ + pysocks + ]; + }; + + meta = with lib; { + description = "Powerful, sanity-friendly HTTP client for Python"; + homepage = "https://github.com/shazow/urllib3"; + changelog = "https://github.com/urllib3/urllib3/blob/${version}/CHANGES.rst"; + license = licenses.mit; + }; +}