Skip to content

Commit

Permalink
Merge pull request #95 from saveriol/execute-hc-login-on-first-run
Browse files Browse the repository at this point in the history
Execute hc login on first run
  • Loading branch information
pmagyar authored Oct 7, 2024
2 parents 24d4ec1 + c3a0bd4 commit 6fe5376
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
16 changes: 14 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
FROM python:3.10-slim

ARG BASHIO_VERSION="v0.16.2"
ARG BASHIO_SHA256="d0f0c780c4badd103c00c572b1bf9645520d15a8a8070d6e3d64e35cb9f583aa"

WORKDIR /app

COPY requirements.txt ./

RUN apt-get update && \
apt-get install -y --no-install-recommends gcc python3-dev libssl-dev libxml2-dev libxslt-dev python3-dev jq && \
apt-get install -y --no-install-recommends curl tar gcc python3-dev libssl-dev libxml2-dev libxslt-dev python3-dev jq && \
pip3 install -r requirements.txt && \
apt-get remove -y gcc python3-dev libssl-dev && \
apt-get autoremove -y
apt-get autoremove -y \
&& curl -J -L -o /tmp/bashio.tar.gz \
"https://github.com/hassio-addons/bashio/archive/${BASHIO_VERSION}.tar.gz" \
&& echo "${BASHIO_SHA256} /tmp/bashio.tar.gz" | sha256sum --check \
&& mkdir /tmp/bashio \
&& tar zxvf \
/tmp/bashio.tar.gz \
--strip 1 -C /tmp/bashio \
&& mv /tmp/bashio/lib /usr/lib/bashio \
&& ln -s /usr/lib/bashio/bashio /usr/bin/bashio

COPY hc2mqtt.py hc-login.py HADiscovery.py HCDevice.py HCSocket.py HCxml2json.py run.sh ./

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Installing `sslpsk` needs some extra steps:
![laptop in a clothes washer with a display DoorState:Closed](images/doorclose.jpg)

```bash
hc-login.py $USERNAME $PASSWORD > config/devices.json
hc-login.py $USERNAME $PASSWORD config/devices.json
```

or
Expand Down
11 changes: 10 additions & 1 deletion hc-login.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def debug(*args):

email = sys.argv[1]
password = sys.argv[2]
devicefile = sys.argv[3]

headers = {"User-Agent": "hc-login/1.0"}

Expand Down Expand Up @@ -312,5 +313,13 @@ def b64random(num):
machine = xml2json(features, description)
config["description"] = machine["description"]
config["features"] = augment_device_features(machine["features"])
print("Discovered device: " + config["name"] + " - Device hostname: " + config["host"])

print(json.dumps(configs, indent=4))
with open(devicefile, "w") as f:
json.dump(configs, f, ensure_ascii=True, indent=4)

print(
"Success. You can now edit "
+ devicefile
+ ", if needed, and run hc2mqtt.py or start Home Assistant addon again"
)
7 changes: 6 additions & 1 deletion home-assistant-addon/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ arch:
- armv7
- i386
map:
- addon_config:rw
- share
url: https://github.com/hcpy2-0/hcpy
panel_title: HCPY
options:
HCPY_DEVICES_FILE: "config/devices.json"
HCPY_DEVICES_FILE: "/config/devices.json"
HCPY_MQTT_HOST: localhost
HCPY_MQTT_PORT: 1883
HCPY_MQTT_PREFIX: "homeconnect/"
Expand All @@ -30,6 +31,8 @@ options:
HCPY_HA_DISCOVERY: true
HCPY_DOMAIN_SUFFIX: ""
HCPY_DEBUG: false
HCPY_HOMECONNECT_EMAIL: ""
HCPY_HOMECONNECT_PASSWORD: ""
schema:
HCPY_DEVICES_FILE: str
HCPY_MQTT_HOST: str
Expand All @@ -45,4 +48,6 @@ schema:
HCPY_DOMAIN_SUFFIX: str
HCPY_HA_DISCOVERY: bool?
HCPY_DEBUG: bool?
HCPY_HOMECONNECT_EMAIL: email
HCPY_HOMECONNECT_PASSWORD: password
startup: services
35 changes: 29 additions & 6 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
#!/bin/bash
if [ -f /data/options.json ]; then
set -o allexport
eval "$(jq -r 'to_entries[]|"\(.key)=\"\(.value)\""' /data/options.json)"
set +o allexport
exec python3 hc2mqtt.py
#!/usr/bin/env bashio
CONFIG_PATH=/data/options.json
if [ -f ${CONFIG_PATH} ]; then

set -o allexport
HCPY_DEVICES_FILE="$(bashio::config 'HCPY_DEVICES_FILE')"
HCPY_MQTT_HOST="$(bashio::config 'HCPY_MQTT_HOST')"
HCPY_MQTT_PORT="$(bashio::config 'HCPY_MQTT_PORT')"
HCPY_MQTT_PREFIX="$(bashio::config 'HCPY_MQTT_PREFIX')"
HCPY_MQTT_USERNAME="$(bashio::config 'HCPY_MQTT_USERNAME')"
HCPY_MQTT_PASSWORD="$(bashio::config 'HCPY_MQTT_PASSWORD')"
HCPY_MQTT_SSL="$(bashio::config 'HCPY_MQTT_SSL')"
HCPY_MQTT_CAFILE="$(bashio::config 'HCPY_MQTT_CAFILE')"
HCPY_MQTT_CERTFILE="$(bashio::config 'HCPY_MQTT_CERTFILE')"
HCPY_MQTT_KEYFILE="$(bashio::config 'HCPY_MQTT_KEYFILE')"
HCPY_MQTT_CLIENTNAME="$(bashio::config 'HCPY_MQTT_CLIENTNAME')"
HCPY_HA_DISCOVERY="$(bashio::config 'HCPY_HA_DISCOVERY')"
HCPY_DOMAIN_SUFFIX="$(bashio::config 'HCPY_DOMAIN_SUFFIX')"
HCPY_DEBUG="$(bashio::config 'HCPY_DEBUG')"
HCPY_HOMECONNECT_EMAIL="$(bashio::config 'HCPY_HOMECONNECT_EMAIL')"
HCPY_HOMECONNECT_PASSWORD="$(bashio::config 'HCPY_HOMECONNECT_PASSWORD')"
set +o allexport

if [ ! -f "${HCPY_DEVICES_FILE}" ]; then
echo "File not found ${HCPY_DEVICES_FILE}"
echo "Trying to retrieve devices.json"
exec python3 hc-login.py $HCPY_HOMECONNECT_EMAIL $HCPY_HOMECONNECT_PASSWORD ${HCPY_DEVICES_FILE}
fi
exec python3 hc2mqtt.py
fi
exec python3 hc2mqtt.py --config ./config/config.ini

0 comments on commit 6fe5376

Please sign in to comment.