Add domain_suffix option
This commit is contained in:
@@ -37,8 +37,11 @@ sslpsk.sslpsk._sslobj = _sslobj
|
|||||||
|
|
||||||
|
|
||||||
class HCSocket:
|
class HCSocket:
|
||||||
def __init__(self, host, psk64, iv64=None):
|
def __init__(self, host, psk64, iv64=None, domain_suffix=""):
|
||||||
self.host = host
|
self.host = host
|
||||||
|
if domain_suffix:
|
||||||
|
self.host = f"{host}.{domain_suffix}"
|
||||||
|
|
||||||
self.psk = base64url(psk64 + "===")
|
self.psk = base64url(psk64 + "===")
|
||||||
self.debug = False
|
self.debug = False
|
||||||
|
|
||||||
@@ -49,11 +52,11 @@ class HCSocket:
|
|||||||
self.enckey = hmac(self.psk, b"ENC")
|
self.enckey = hmac(self.psk, b"ENC")
|
||||||
self.mackey = hmac(self.psk, b"MAC")
|
self.mackey = hmac(self.psk, b"MAC")
|
||||||
self.port = 80
|
self.port = 80
|
||||||
self.uri = "ws://" + host + ":80/homeconnect"
|
self.uri = f"ws://{host}:80/homeconnect"
|
||||||
else:
|
else:
|
||||||
self.http = False
|
self.http = False
|
||||||
self.port = 443
|
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
|
# don't connect automatically so that debug etc can be set
|
||||||
# self.reconnect()
|
# self.reconnect()
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ from HCSocket import HCSocket, now
|
|||||||
@click.option("--mqtt_certfile")
|
@click.option("--mqtt_certfile")
|
||||||
@click.option("--mqtt_keyfile")
|
@click.option("--mqtt_keyfile")
|
||||||
@click.option("--mqtt_clientname", default="hcpy1")
|
@click.option("--mqtt_clientname", default="hcpy1")
|
||||||
|
@click.option("--domain_suffix", default="")
|
||||||
@click_config_file.configuration_option()
|
@click_config_file.configuration_option()
|
||||||
def hc2mqtt(
|
def hc2mqtt(
|
||||||
devices_file: str,
|
devices_file: str,
|
||||||
@@ -40,6 +41,7 @@ def hc2mqtt(
|
|||||||
mqtt_certfile: str,
|
mqtt_certfile: str,
|
||||||
mqtt_keyfile: str,
|
mqtt_keyfile: str,
|
||||||
mqtt_clientname: str,
|
mqtt_clientname: str,
|
||||||
|
domain_suffix: str
|
||||||
):
|
):
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
@@ -101,6 +103,7 @@ def hc2mqtt(
|
|||||||
f"Hello {devices_file=} {mqtt_host=} {mqtt_prefix=} "
|
f"Hello {devices_file=} {mqtt_host=} {mqtt_prefix=} "
|
||||||
f"{mqtt_port=} {mqtt_username=} {mqtt_password=} "
|
f"{mqtt_port=} {mqtt_username=} {mqtt_password=} "
|
||||||
f"{mqtt_ssl=} {mqtt_cafile=} {mqtt_certfile=} {mqtt_keyfile=} {mqtt_clientname=}"
|
f"{mqtt_ssl=} {mqtt_cafile=} {mqtt_certfile=} {mqtt_keyfile=} {mqtt_clientname=}"
|
||||||
|
f"{domain_suffix=}"
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(devices_file, "r") as f:
|
with open(devices_file, "r") as f:
|
||||||
@@ -130,7 +133,7 @@ def hc2mqtt(
|
|||||||
|
|
||||||
for device in devices:
|
for device in devices:
|
||||||
mqtt_topic = mqtt_prefix + device["name"]
|
mqtt_topic = mqtt_prefix + device["name"]
|
||||||
thread = Thread(target=client_connect, args=(client, device, mqtt_topic))
|
thread = Thread(target=client_connect, args=(client, device, mqtt_topic, domain_suffix))
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
client.loop_forever()
|
client.loop_forever()
|
||||||
@@ -140,7 +143,7 @@ global dev
|
|||||||
dev = {}
|
dev = {}
|
||||||
|
|
||||||
|
|
||||||
def client_connect(client, device, mqtt_topic):
|
def client_connect(client, device, mqtt_topic, domain_suffix):
|
||||||
host = device["host"]
|
host = device["host"]
|
||||||
name = device["name"]
|
name = device["name"]
|
||||||
|
|
||||||
@@ -192,7 +195,7 @@ def client_connect(client, device, mqtt_topic):
|
|||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
try:
|
try:
|
||||||
print(now(), name, f"connecting to {host}")
|
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)
|
dev[name] = HCDevice(ws, device)
|
||||||
dev[name].run_forever(on_message=on_message, on_open=on_open, on_close=on_close)
|
dev[name].run_forever(on_message=on_message, on_open=on_open, on_close=on_close)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user