Skip to content

Commit

Permalink
Merge pull request #71 from Meatballs1/domain_suffix
Browse files Browse the repository at this point in the history
Add domain_suffix option
  • Loading branch information
pmagyar authored May 14, 2024
2 parents c71ce21 + 753d418 commit ec0a9b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 6 additions & 3 deletions HCSocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ def _sslobj(sock):


class HCSocket:
def __init__(self, host, psk64, iv64=None):
def __init__(self, host, psk64, iv64=None, domain_suffix=""):
self.host = host
if domain_suffix:
self.host = f"{host}.{domain_suffix}"

self.psk = base64url(psk64 + "===")
self.debug = False

Expand All @@ -49,11 +52,11 @@ def __init__(self, host, psk64, iv64=None):
self.enckey = hmac(self.psk, b"ENC")
self.mackey = hmac(self.psk, b"MAC")
self.port = 80
self.uri = "ws://" + host + ":80/homeconnect"
self.uri = f"ws://{host}:80/homeconnect"
else:
self.http = False
self.port = 443
self.uri = "wss://" + host + ":443/homeconnect"
self.uri = f"wss://{host}:443/homeconnect"

# don't connect automatically so that debug etc can be set
# self.reconnect()
Expand Down
12 changes: 8 additions & 4 deletions hc2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@click.option("--mqtt_certfile")
@click.option("--mqtt_keyfile")
@click.option("--mqtt_clientname", default="hcpy1")
@click.option("--domain_suffix", default="")
@click.option("--debug/--no-debug", default=False)
@click_config_file.configuration_option()
def hc2mqtt(
Expand All @@ -41,6 +42,7 @@ def hc2mqtt(
mqtt_certfile: str,
mqtt_keyfile: str,
mqtt_clientname: str,
domain_suffix: str,
debug: bool,
):

Expand Down Expand Up @@ -103,7 +105,7 @@ def on_message(client, userdata, msg):
f"Hello {devices_file=} {mqtt_host=} {mqtt_prefix=} "
f"{mqtt_port=} {mqtt_username=} {mqtt_password=} "
f"{mqtt_ssl=} {mqtt_cafile=} {mqtt_certfile=} {mqtt_keyfile=} {mqtt_clientname=}"
f"{debug=}"
f"{domain_suffix=} {debug=}"
)

with open(devices_file, "r") as f:
Expand Down Expand Up @@ -133,7 +135,9 @@ def on_message(client, userdata, msg):

for device in devices:
mqtt_topic = mqtt_prefix + device["name"]
thread = Thread(target=client_connect, args=(client, device, mqtt_topic, debug))
thread = Thread(
target=client_connect, args=(client, device, mqtt_topic, domain_suffix, debug)
)
thread.start()

client.loop_forever()
Expand All @@ -143,7 +147,7 @@ def on_message(client, userdata, msg):
dev = {}


def client_connect(client, device, mqtt_topic, debug):
def client_connect(client, device, mqtt_topic, domain_suffix, debug):
host = device["host"]
name = device["name"]

Expand Down Expand Up @@ -195,7 +199,7 @@ def on_close(ws, code, message):
time.sleep(3)
try:
print(now(), name, f"connecting to {host}")
ws = HCSocket(host, device["key"], device.get("iv", None))
ws = HCSocket(host, device["key"], device.get("iv", None), domain_suffix)
dev[name] = HCDevice(ws, device, debug)
dev[name].run_forever(on_message=on_message, on_open=on_open, on_close=on_close)
except Exception as e:
Expand Down
4 changes: 3 additions & 1 deletion home-assistant-addon/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: "HomeConnect2MQTT"
description: "Run HCPY as addon"
version: "v0.1.0"
version: "v0.1.1"
slug: "hcpy"
image: ghcr.io/hcpy2-0/hcpy
init: false
Expand All @@ -27,6 +27,7 @@ options:
HCPY_MQTT_CERTFILE: ""
HCPY_MQTT_KEYFILE: ""
HCPY_MQTT_CLIENTNAME: "hcpy1"
HCPY_DOMAIN_SUFFIX: ""
HCPY_DEBUG: false
schema:
HCPY_DEVICES_FILE: str
Expand All @@ -40,5 +41,6 @@ schema:
HCPY_MQTT_CERTFILE: str
HCPY_MQTT_KEYFILE: str
HCPY_MQTT_CLIENTNAME: str
HCPY_DOMAIN_SUFFIX: str
HCPY_DEBUG: bool?
startup: services

0 comments on commit ec0a9b5

Please sign in to comment.