refactor(hass): cleanup and use python3Packages.callPkg

This commit is contained in:
matt1432 2025-04-07 10:36:30 -04:00
parent 7003519e18
commit a4064bf1b1
16 changed files with 57 additions and 121 deletions
packages/coloryou/coloryou
scopedPackages/hass-components
default.nix
extended-ollama-conversation
material-symbols
netdaemon
spotifyplus
tuya-local
yamaha-soundbar

File diff suppressed because one or more lines are too long

View file

@ -1,45 +0,0 @@
#!/usr/bin/env python
"""
The original script:
https://github.com/dharmx/vile/blob/7d486c128c7e553912673755f97b118aaab0193d/src/shell/playerctl.py#L2
"""
import argparse
import json
from material_color_utilities_python import themeFromImage, hexFromArgb, Image
def range_type(value_string):
value = int(value_string)
if value not in range(0, 101):
raise argparse.ArgumentTypeError("%s is out of range, choose in [0-100]" % value)
return value
parser = argparse.ArgumentParser(
prog='coloryou',
description='This program extract Material You colors from an image. It returns them as a JSON object for scripting.')
parser.add_argument("image_path", help="A full path to your image", type=str)
parser.add_argument('-i', '--image', dest='image', default=40, type=range_type, metavar='i', choices=range(0,101), help="Value should be within [0, 100] (default: %(default)s). Set the tone for the main image accent.")
parser.add_argument('-b', '--button', dest='button', default=90, type=range_type, metavar='i', choices=range(0,101), help="Value should be within [0, 100] (default: %(default)s). Set the tone for the button accent.")
parser.add_argument('-t', '--text', dest='text', default=10, type=range_type, metavar='i', choices=range(0,101), help="Value should be within [0, 100] (default: %(default)s). Set the tone for the button text accent.")
parser.add_argument('-o', '--hover', dest='hover', default=80, type=range_type, metavar='i', choices=range(0,101), help="Value should be within [0, 100] (default: %(default)s). Set the tone for the hovering effect accent.")
args = parser.parse_args()
img = Image.open(args.image_path)
basewidth = 64
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize),Image.Resampling.LANCZOS)
theme = themeFromImage(img).get("palettes").get("primary")
parsed_colors = {"imageAccent": hexFromArgb(theme.tone(args.image)),
"buttonAccent": hexFromArgb(theme.tone(args.button)),
"buttonText": hexFromArgb(theme.tone(args.text)),
"hoverAccent": hexFromArgb(theme.tone(args.hover))}
print(json.dumps(parsed_colors))

View file

@ -1,19 +0,0 @@
{python3Packages}:
python3Packages.buildPythonPackage rec {
pname = "coloryou";
version = "0.0.1";
src = ./.;
propagatedBuildInputs = with python3Packages; [utils material-color-utilities];
postInstall = ''
mv -v $out/bin/coloryou.py $out/bin/coloryou
'';
meta = {
description = ''
Get Material You colors from an image.
'';
};
}

View file

@ -1,2 +0,0 @@
material-color-utilities
utils

View file

@ -1,7 +0,0 @@
from distutils.core import setup
setup(
name='coloryou',
version='0.0.1',
scripts=['coloryou.py',],
)

View file

@ -1,7 +0,0 @@
with import <nixpkgs> {};
with pkgs.python311Packages;
buildPythonPackage rec {
name = "coloryou";
src = ./.;
propagatedBuildInputs = [material-color-utilities utils];
}

View file

@ -8,14 +8,14 @@ lib.makeScope pkgs.newScope (hass: let
inherit (self.lib) mergeAttrsList;
python3Packages = pkgs.python313Packages.override {
overrides = final: prev: (mergeAttrsList (map (x: x python3Packages final prev) [
overrides = final: prev: (mergeAttrsList (map (fn: fn python3Packages final prev) [
(import ./spotifyplus/overrides.nix ({inherit pkgs;} // inputs))
(import ./tuya-local/overrides.nix {inherit pkgs;})
]));
};
buildHassComponent = file: extraArgs:
hass.callPackage file (inputs // extraArgs // {inherit python3Packages;});
python3Packages.callPackage file (inputs // extraArgs // {});
in {
extended-ollama-conversation = buildHassComponent ./extended-ollama-conversation {};

View file

@ -3,30 +3,26 @@
buildHomeAssistantComponent,
extended-ollama-conversation-src,
# deps
python3Packages,
ollama,
openai,
...
}: 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;
prePatch = ''
substituteInPlace ./custom_components/extended_ollama_conversation/manifest.json \
--replace-warn "ollama~=0.3.0" "ollama>=0.3.0"
'';
propagatedBuildInputs = with python3Packages; [
dependencies = [
ollama
openai
];
ignoreVersionRequirement = ["ollama"];
meta = {
homepage = "https://github.com/TheNimaj/extended_ollama_conversation";
description = ''

View file

@ -6,7 +6,6 @@
...
}: let
inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${material-symbols-src}/custom_components/material_symbols/manifest.json");
in
buildHomeAssistantComponent {

View file

@ -4,21 +4,19 @@
buildHomeAssistantComponent,
netdaemon-src,
# deps
python3Packages,
awesomeversion,
...
}: let
inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${netdaemon-src}/custom_components/netdaemon/manifest.json");
in
buildHomeAssistantComponent {
owner = "net-daemon";
inherit (manifest) domain version;
src = netdaemon-src;
propagatedBuildInputs = with python3Packages; [
dependencies = [
awesomeversion
];

View file

@ -4,21 +4,27 @@
buildHomeAssistantComponent,
spotifyplus-src,
# deps
python3Packages,
oauthlib,
platformdirs,
requests,
requests_oauthlib,
soco,
urllib3,
zeroconf,
smartinspect, # overridden in python3Packages
spotifywebapi, # overridden in 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; [
dependencies = [
oauthlib
platformdirs
requests
@ -26,10 +32,14 @@ in
soco
urllib3
zeroconf
smartinspect # overridden in python3Packages
spotifywebapi # overridden in python3Packages
smartinspect
spotifywebapi
];
# Upstream sometimes forgets to bump version number.
# Since we're guaranteed to have lastest git, this is safe
ignoreVersionRequirement = ["spotifywebapipython"];
meta = {
license = lib.licenses.mit;
homepage = "https://github.com/thlucas1/homeassistantcomponent_spotifyplus";

View file

@ -4,11 +4,11 @@
pkgs,
...
}: python3Packages: final: prev: rec {
smartinspect = pkgs.callPackage ./smartinspect.nix {
inherit python3Packages smartinspect-src;
smartinspect = python3Packages.callPackage ./smartinspect.nix {
inherit smartinspect-src;
};
spotifywebapi = pkgs.callPackage ./spotifywebapi.nix {
inherit python3Packages smartinspect spotifywebapi-src;
spotifywebapi = python3Packages.callPackage ./spotifywebapi.nix {
inherit smartinspect spotifywebapi-src;
};
urllib3 = pkgs.selfPackages.urllib3.override {
inherit python3Packages;

View file

@ -1,21 +1,23 @@
{
# nix build inputs
lib,
buildPythonPackage,
smartinspect-src,
# deps
python3Packages,
pycryptodome,
watchdog,
...
}: let
inherit (builtins) elemAt head readFile split;
tag = head (split "\"" (elemAt (split "VERSION:str = \"" (readFile "${smartinspect-src}/smartinspectpython/siconst.py")) 2));
in
python3Packages.buildPythonPackage {
buildPythonPackage {
pname = "smartinspectPython";
version = "${tag}+${smartinspect-src.shortRev}";
src = smartinspect-src;
propagatedBuildInputs = with python3Packages; [
dependencies = [
pycryptodome
watchdog
];

View file

@ -1,22 +1,34 @@
{
# nix build inputs
lib,
buildPythonPackage,
spotifywebapi-src,
# deps
python3Packages,
lxml,
oauthlib,
platformdirs,
pychromecast,
pyotp,
requests,
requests_oauthlib,
setuptools,
soco,
urllib3,
zeroconf,
smartinspect, # overridden in 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 {
buildPythonPackage {
pname = "spotifywebapiPython";
version = "${tag}+${spotifywebapi-src.shortRev}";
pyproject = true;
src = spotifywebapi-src;
propagatedBuildInputs = with python3Packages; [
dependencies = [
lxml
oauthlib
platformdirs
@ -28,7 +40,7 @@ in
soco
urllib3
zeroconf
smartinspect # overridden in python3Packages
smartinspect
];
pythonImportsCheck = [

View file

@ -4,21 +4,20 @@
buildHomeAssistantComponent,
tuya-local-src,
# deps
python3Packages,
tinytuya,
tuya-device-sharing-sdk,
...
}: let
inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${tuya-local-src}/custom_components/tuya_local/manifest.json");
in
buildHomeAssistantComponent {
owner = "make-all";
inherit (manifest) domain version;
src = tuya-local-src;
propagatedBuildInputs = with python3Packages; [
dependencies = [
tinytuya
tuya-device-sharing-sdk
];

View file

@ -3,11 +3,12 @@
buildHomeAssistantComponent,
yamaha-soundbar-src,
# deps
python3Packages,
async-upnp-client,
chardet,
validators,
...
}: let
inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${yamaha-soundbar-src}/custom_components/yamaha_soundbar/manifest.json");
in
buildHomeAssistantComponent {
@ -16,7 +17,7 @@ in
inherit (manifest) domain version;
src = yamaha-soundbar-src;
propagatedBuildInputs = with python3Packages; [
dependencies = [
async-upnp-client
chardet
validators