Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
b28bb18287
|
|||
|
088643cae5
|
|||
|
89e4c5e7f0
|
|||
|
e553adc033
|
|||
|
f77d2a6efa
|
|||
|
9c9f9b5d14
|
22
flake.lock
generated
22
flake.lock
generated
@@ -2,7 +2,9 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"dream2nix": {
|
"dream2nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
"purescript-overlay": "purescript-overlay",
|
"purescript-overlay": "purescript-overlay",
|
||||||
"pyproject-nix": "pyproject-nix"
|
"pyproject-nix": "pyproject-nix"
|
||||||
},
|
},
|
||||||
@@ -38,18 +40,17 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1729850857,
|
"lastModified": 1732014248,
|
||||||
"narHash": "sha256-WvLXzNNnnw+qpFOmgaM3JUlNEH+T4s22b5i2oyyCpXE=",
|
"narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "41dea55321e5a999b17033296ac05fe8a8b5a257",
|
"rev": "23e89b7da85c3640bbc2173fe04f4bd114342367",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"id": "nixpkgs",
|
||||||
"ref": "nixpkgs-unstable",
|
"ref": "nixos-unstable",
|
||||||
"repo": "nixpkgs",
|
"type": "indirect"
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"purescript-overlay": {
|
"purescript-overlay": {
|
||||||
@@ -95,10 +96,7 @@
|
|||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"dream2nix": "dream2nix",
|
"dream2nix": "dream2nix",
|
||||||
"nixpkgs": [
|
"nixpkgs": "nixpkgs"
|
||||||
"dream2nix",
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"slimlock": {
|
"slimlock": {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
|
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||||
dream2nix.url = "github:nix-community/dream2nix";
|
dream2nix.url = "github:nix-community/dream2nix";
|
||||||
nixpkgs.follows = "dream2nix/nixpkgs";
|
dream2nix.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
@@ -16,6 +17,11 @@
|
|||||||
"x86_64-linux"
|
"x86_64-linux"
|
||||||
];
|
];
|
||||||
in {
|
in {
|
||||||
|
nixosModules = rec {
|
||||||
|
hcpy = import ./module.nix self;
|
||||||
|
default = hcpy;
|
||||||
|
};
|
||||||
|
|
||||||
packages = eachSystem (system: let
|
packages = eachSystem (system: let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in rec {
|
in rec {
|
||||||
@@ -25,6 +31,7 @@
|
|||||||
./package.nix
|
./package.nix
|
||||||
{
|
{
|
||||||
paths.projectRootFile = "flake.nix";
|
paths.projectRootFile = "flake.nix";
|
||||||
|
paths.lockFile = "lock.${system}.json";
|
||||||
paths.projectRoot = ./.;
|
paths.projectRoot = ./.;
|
||||||
paths.package = ./.;
|
paths.package = ./.;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,9 @@
|
|||||||
},
|
},
|
||||||
"charset-normalizer": {
|
"charset-normalizer": {
|
||||||
"is_direct": false,
|
"is_direct": false,
|
||||||
"sha256": "8cda06946eac330cbe6598f77bb54e690b4ca93f593dee1568ad22b04f347c15",
|
"sha256": "7f683ddc7eedd742e2889d2bfb96d69573fde1d92fcb811979cdb7165bb9c7d3",
|
||||||
"type": "url",
|
"type": "url",
|
||||||
"url": "https://files.pythonhosted.org/packages/16/92/92a76dc2ff3a12e69ba94e7e05168d37d0345fa08c87e1fe24d0c2a42223/charset_normalizer-3.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
|
"url": "https://files.pythonhosted.org/packages/f8/01/344ec40cf5d85c1da3c1f57566c59e0c9b56bcc5566c08804a95a6cc8257/charset_normalizer-3.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
|
||||||
"version": "3.4.0"
|
"version": "3.4.0"
|
||||||
},
|
},
|
||||||
"click": {
|
"click": {
|
||||||
@@ -59,9 +59,9 @@
|
|||||||
},
|
},
|
||||||
"lxml": {
|
"lxml": {
|
||||||
"is_direct": false,
|
"is_direct": false,
|
||||||
"sha256": "3879cc6ce938ff4eb4900d901ed63555c778731a96365e53fadb36437a131a99",
|
"sha256": "b1c8c20847b9f34e98080da785bb2336ea982e7f913eed5809e5a3c872900f32",
|
||||||
"type": "url",
|
"type": "url",
|
||||||
"url": "https://files.pythonhosted.org/packages/0a/6e/94537acfb5b8f18235d13186d247bca478fea5e87d224644e0fe907df976/lxml-5.3.0-cp312-cp312-manylinux_2_28_x86_64.whl",
|
"url": "https://files.pythonhosted.org/packages/05/9e/87492d03ff604fbf656ed2bf3e2e8d28f5d58ea1f00ff27ac27b06509079/lxml-5.3.0-cp310-cp310-manylinux_2_28_x86_64.whl",
|
||||||
"version": "5.3.0"
|
"version": "5.3.0"
|
||||||
},
|
},
|
||||||
"paho-mqtt": {
|
"paho-mqtt": {
|
||||||
@@ -155,5 +155,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"invalidationHash": "8b77dd84722cef2a9d624d9674be2397c777c8b180b813df1327f67470dd3476"
|
"invalidationHash": "ffec585af8e2f405564c1aa26829f11dbf9265334a938576ea9f416033be7da5"
|
||||||
}
|
}
|
||||||
104
module.nix
Normal file
104
module.nix
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
self: {
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
system,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
with lib; let
|
||||||
|
cfg = config.services.hcpy;
|
||||||
|
bridgeConfig =
|
||||||
|
cfg.config
|
||||||
|
// {
|
||||||
|
devices_file = cfg.devicesFile;
|
||||||
|
};
|
||||||
|
hcpy = pkgs.writeShellApplication {
|
||||||
|
name = "hcpy-service";
|
||||||
|
runtimeInputs = [self.packages.${system}.default];
|
||||||
|
text = ''
|
||||||
|
if [ ! -f "${cfg.devicesFile}" ]; then
|
||||||
|
echo "Device file does not exist, requesting login to HomeConnect cloud";
|
||||||
|
hcpy login "$(cat "${cfg.homeconnect.usernameFile}")" \
|
||||||
|
"$(cat "${cfg.homeconnect.passwordFile}")" \
|
||||||
|
"${cfg.devicesFile}";
|
||||||
|
fi
|
||||||
|
|
||||||
|
hcpy run ${cli.toGNUCommandLineShell {} bridgeConfig} \
|
||||||
|
--mqtt_username "$(cat "${cfg.mqtt.usernameFile}")" \
|
||||||
|
--mqtt_password "$(cat "${cfg.mqtt.passwordFile}")"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
options.services.hcpy = {
|
||||||
|
enable = mkEnableOption "HomeConnect bridge service";
|
||||||
|
|
||||||
|
homeconnect = {
|
||||||
|
usernameFile = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
description = "Path to file containing single line with HomeConnect account username";
|
||||||
|
example = "/run/hc.username.key";
|
||||||
|
};
|
||||||
|
|
||||||
|
passwordFile = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
description = "Path to file containing single line with HomeConnect account password";
|
||||||
|
example = "/run/hc.password.key";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
mqtt = {
|
||||||
|
usernameFile = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
description = "Path to file containing single line with MQTT client username";
|
||||||
|
example = "/run/mqtt.username.key";
|
||||||
|
};
|
||||||
|
|
||||||
|
passwordFile = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
description = "Path to file containing single line with MQTT client password";
|
||||||
|
example = "/run/mqtt.password.key";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
devicesFile = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
description = "Path to JSON file fetched from HomeConnect API";
|
||||||
|
example = "/var/lib/hcpy/devices.json";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
description = "The configuration of hcpy bridge";
|
||||||
|
example = {
|
||||||
|
mqtt_host = "localhost";
|
||||||
|
mqtt_prefix = "homeconnect/";
|
||||||
|
mqtt_port = 8883;
|
||||||
|
mqtt_ssl = true;
|
||||||
|
mqtt_cafile = "/run/ca.pem";
|
||||||
|
mqtt_certfile = "/run/cert.crt";
|
||||||
|
mqtt_keyfile = "/run/cert.key";
|
||||||
|
mqtt_clientname = "hcpy1";
|
||||||
|
domain_suffix = "";
|
||||||
|
debug = true;
|
||||||
|
ha-discovery = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
systemd.services.hcpy = {
|
||||||
|
enable = true;
|
||||||
|
description = "HomeConnect bridge service";
|
||||||
|
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
wants = ["network-online.target"];
|
||||||
|
after = ["network-online.target"];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${hcpy}/bin/hcpy-service";
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = 10;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ in rec {
|
|||||||
inherit (pyproject.project) name version;
|
inherit (pyproject.project) name version;
|
||||||
|
|
||||||
deps = {nixpkgs, ...}: {
|
deps = {nixpkgs, ...}: {
|
||||||
python = nixpkgs.python3;
|
python = nixpkgs.python310;
|
||||||
inherit (nixpkgs) openssl;
|
inherit (nixpkgs) openssl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
name = "hcpy"
|
name = "hcpy"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
description = "HC to MQTT bridge"
|
description = "HC to MQTT bridge"
|
||||||
requires-python = ">=3.7"
|
requires-python = "==3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bs4",
|
"bs4",
|
||||||
"requests",
|
"requests",
|
||||||
@@ -20,5 +20,5 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
hc-login = "hcpy:hc_login"
|
hc-login = "hcpy.hc_login:main"
|
||||||
hc2mqtt = "hcpy.hc2mqtt:hc2mqtt"
|
hc2mqtt = "hcpy.hc2mqtt:hc2mqtt"
|
||||||
@@ -31,7 +31,7 @@ from hcpy.HCxml2json import xml2json
|
|||||||
# requests_log.setLevel(logging.DEBUG)
|
# requests_log.setLevel(logging.DEBUG)
|
||||||
# requests_log.propagate = True
|
# requests_log.propagate = True
|
||||||
|
|
||||||
|
def main():
|
||||||
def debug(*args):
|
def debug(*args):
|
||||||
print(*args, file=sys.stderr)
|
print(*args, file=sys.stderr)
|
||||||
|
|
||||||
@@ -323,3 +323,6 @@ print(
|
|||||||
+ devicefile
|
+ devicefile
|
||||||
+ ", if needed, and run hc2mqtt.py or start Home Assistant addon again"
|
+ ", if needed, and run hc2mqtt.py or start Home Assistant addon again"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ pkgs.writeShellApplication rec {
|
|||||||
#/ --mqtt_cafile - CA certifications file for SSL connection
|
#/ --mqtt_cafile - CA certifications file for SSL connection
|
||||||
#/ --mqtt_certfile - certification file for SSL connection
|
#/ --mqtt_certfile - certification file for SSL connection
|
||||||
#/ --mqtt_keyfile - certification key file for SSL connection
|
#/ --mqtt_keyfile - certification key file for SSL connection
|
||||||
#/ --mqtt_clientname" - name of MQTT broker client, default="hcpy1"
|
#/ --mqtt_clientname - name of MQTT broker client, default="hcpy1"
|
||||||
#/ --domain_suffix - the suffix of the domain, default=""
|
#/ --domain_suffix - the suffix of the domain, default=""
|
||||||
#/ --debug/--no-debug - enable debug mode
|
#/ --debug/--no-debug - enable debug mode
|
||||||
#/ --ha-discovery - enable HomeAssistant discovery
|
#/ --ha-discovery - enable HomeAssistant discovery
|
||||||
|
|||||||
Reference in New Issue
Block a user