Use a config.ini file
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ __*
|
||||
*.json
|
||||
*.zip
|
||||
*.sh
|
||||
*.ini
|
||||
|
||||
20
README.md
20
README.md
@@ -41,7 +41,7 @@ Installing `sslpsk` needs some extra steps:
|
||||

|
||||
|
||||
```bash
|
||||
hc-login $USERNAME $PASSWORD > config.json
|
||||
hc-login $USERNAME $PASSWORD > devices.json
|
||||
```
|
||||
|
||||
The `hc-login` script perfoms the OAuth process to login to your
|
||||
@@ -58,8 +58,24 @@ your mDNS or DNS server resolves the names correctly.
|
||||
|
||||
## Home Connect to MQTT
|
||||
|
||||
Use the following config/config.ini example:
|
||||
|
||||
```
|
||||
devices_file = "/config/devices.json"
|
||||
mqtt_host = "localhost"
|
||||
mqtt_username = "mqtt"
|
||||
mqtt_password = "password"
|
||||
mqtt_port = 1883
|
||||
mqtt_prefix = "homeconnect/"
|
||||
mqtt_ssl = False
|
||||
mqtt_cafile = None
|
||||
mqtt_certfile = None
|
||||
mqtt_keyfile = None
|
||||
mqtt_clientname="hcpy"
|
||||
```
|
||||
|
||||
```bash
|
||||
hc2mqtt config.json
|
||||
hc2mqtt --config config/config.ini
|
||||
```
|
||||
|
||||
This tool will establish websockets to the local devices and
|
||||
|
||||
14
hc2mqtt
14
hc2mqtt
@@ -7,13 +7,14 @@ import time
|
||||
from threading import Thread
|
||||
|
||||
import click
|
||||
import click_config_file
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
from HCDevice import HCDevice
|
||||
from HCSocket import HCSocket, now
|
||||
|
||||
@click.command()
|
||||
@click.argument("config_file")
|
||||
@click.option("-d", "--devices_file", default="config/devices.json")
|
||||
@click.option("-h", "--mqtt_host", default="localhost")
|
||||
@click.option("-p", "--mqtt_prefix", default="homeconnect/")
|
||||
@click.option("--mqtt_port", default=1883, type=int)
|
||||
@@ -24,13 +25,14 @@ from HCSocket import HCSocket, now
|
||||
@click.option("--mqtt_certfile")
|
||||
@click.option("--mqtt_keyfile")
|
||||
@click.option("--mqtt_clientname", default="hcpy")
|
||||
@click_config_file.configuration_option()
|
||||
|
||||
def hc2mqtt(config_file: str, mqtt_host: str, mqtt_prefix: str, mqtt_port: int, mqtt_username: str,
|
||||
def hc2mqtt(devices_file: str, mqtt_host: str, mqtt_prefix: str, mqtt_port: int, mqtt_username: str,
|
||||
mqtt_password: str, mqtt_ssl: bool, mqtt_cafile: str, mqtt_certfile: str, mqtt_keyfile: str, mqtt_clientname: str):
|
||||
click.echo(f"Hello {config_file=} {mqtt_host=} {mqtt_prefix=} {mqtt_port=} {mqtt_username=} {mqtt_password=} "
|
||||
click.echo(f"Hello {devices_file=} {mqtt_host=} {mqtt_prefix=} {mqtt_port=} {mqtt_username=} {mqtt_password=} "
|
||||
f"{mqtt_ssl=} {mqtt_cafile=} {mqtt_certfile=} {mqtt_keyfile=} {mqtt_clientname=}")
|
||||
|
||||
with open(config_file, "r") as f:
|
||||
with open(devices_file, "r") as f:
|
||||
devices = json.load(f)
|
||||
|
||||
client = mqtt.Client(mqtt_clientname)
|
||||
@@ -120,8 +122,8 @@ def client_connect(client, device, mqtt_topic):
|
||||
|
||||
# new_topic = topics[topic]
|
||||
# if new_topic == "remaining":
|
||||
# state["remainingseconds"] = value
|
||||
# value = "%d:%02d" % (value / 60 / 60, (value / 60) % 60)
|
||||
# state["remainingseconds"] = value
|
||||
# value = "%d:%02d" % (value / 60 / 60, (value / 60) % 60)
|
||||
|
||||
new_topic = device_topics[topic]
|
||||
state[new_topic] = value
|
||||
|
||||
@@ -6,4 +6,5 @@ sslpsk
|
||||
paho.mqtt==1.6.1
|
||||
lxml
|
||||
click
|
||||
click-config-file
|
||||
requests
|
||||
|
||||
Reference in New Issue
Block a user