Skip to content

Commit

Permalink
Builds!
Browse files Browse the repository at this point in the history
  • Loading branch information
daft-panda committed Oct 1, 2023
1 parent 109f8d8 commit 70dc057
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 396 deletions.
436 changes: 136 additions & 300 deletions ebusd-thermostat/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ebusd-thermostat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
rumqttc = { version = "0.22.0", features = ["use-rustls"] }
tokio = { version = "1.30.0", features = ["rt", "rt-multi-thread", "macros", "sync", "net"] }
tokio-tungstenite = { version = "*", features = ["rustls-tls-native-roots"] }
reqwest = { version = "0.11.18", features = ["rustls-tls"] }
reqwest = { version = "0.11.18", default-features=false, features = ["rustls-tls"] }
serde = { version = "1.0.183", features = ["derive"] }
serde_json = { version = "1.0.104" }
anyhow = "1.0.72"
Expand Down
24 changes: 7 additions & 17 deletions ebusd-thermostat/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
# syntax=docker/dockerfile:1

ARG RUST_VERSION=1.72.1
ARG APP_NAME=ebusd-thermostat
FROM rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
WORKDIR /

RUN \
<<EOF
set -e
cargo build --locked --release
cp ./target/release/$APP_NAME /bin/ebusd-thermostat
EOF

ARG BUILD_FROM
FROM $BUILD_FROM

COPY --from=build /bin/ebusd-thermostat /bin/
COPY ./ ./

RUN set -e && \
apk add --no-cache cargo && \
cargo build --locked --release

COPY rootfs /
RUN chmod a+x ./run.sh

CMD [ "/bin/ebusd-thermostat" ]
CMD [ "./run.sh" ]
12 changes: 5 additions & 7 deletions ebusd-thermostat/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: "ebusd thermostat"
version: "1.0.0"
slug: folder
description: >-
"Control your ebus heater connected via ebusd"
slug: ebusd_thermostat
description: "Control your ebus heater connected via ebusd"
init: false
arch:
- i386
- amd64
Expand All @@ -11,18 +11,16 @@ map:
- config:rw
- ssl
homeassistant_api: true
image: repo/{arch}-ebusd-thermostat
options:
ha_api_address: "http://supervisor/core/"
ha_api_token: null
ha_api_address: "http://supervisor/core"
ebusd_address: null
thermometer_entity: null
mqtt_host: "localhost"
mqtt_username: "mqtt"
mqtt_password: "mqtt"

schema:
ha_api_address: str
ha_api_address: "str?"
ha_api_token: "str?"
ebusd_address: str
thermometer_entity: str
Expand Down
3 changes: 3 additions & 0 deletions ebusd-thermostat/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bashio

./target/release/ebusd-thermostat
2 changes: 1 addition & 1 deletion ebusd-thermostat/src/homeassistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Api {
}

pub async fn state_updates(&self) -> anyhow::Result<Receiver<Event>> {
let url = Url::parse(&format!("{}/api/websocket", self.url.clone()))?;
let url = Url::parse(&format!("{}/websocket", self.url.clone()))?;
let (ws, _) = connect_async(url).await?;
let (mut write, mut read) = ws.split();
// await auth required message
Expand Down
52 changes: 42 additions & 10 deletions ebusd-thermostat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,49 @@ mod homeassistant;
use crate::ebusd::Ebusd;
use crate::homeassistant::Api;
use anyhow::{anyhow, bail};
use log::{debug, error, info, LevelFilter};
use log::{debug, error, info, trace, LevelFilter};
use rumqttc::{AsyncClient, Event, EventLoop, Incoming, MqttOptions, QoS};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::path::Path;
use std::str::FromStr;
use std::{env, fs};
use tokio::sync::mpsc::{channel, Receiver};
use tokio::time::{sleep, Duration, Instant};
use tokio::{io, pin, select};

#[tokio::main]
async fn main() {
env_logger::builder()
.filter(None, LevelFilter::Debug)
.filter(None, LevelFilter::Trace)
.init();

let options_file = Path::new("/data/options.json");
let options: Options =
serde_json::from_slice(fs::read(options_file).unwrap().as_slice()).unwrap();
debug!("Read options: {:?}", options);

let mut thermostat = match Thermostat::new(
"homeassistant:8123".to_string(),
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI1MzMxM2Y3YTEwN2I0ZDNkYWZkNzdiNGFkNWUyMDRjYiIsImlhdCI6MTY5MTY5NDU4MSwiZXhwIjoyMDA3MDU0NTgxfQ.G7Wg08F9P272gouaZwI18PmwH3rmqgR1zJG7px3bco0".to_string(),
"homeassistant:8888".to_string(),
"sensor.multisensor_7_air_temperature_2".to_string(),
"homeassistant".to_string(),
"mqtt".to_string(),
"mqtt".to_string(),
options
.ha_api_address
.unwrap_or_else(|| "http://supervisor/core".to_string()),
options
.ha_api_token
.unwrap_or_else(|| match env::var("SUPERVISOR_TOKEN") {
Ok(v) => v,
Err(_) => {
error!("SUPERVISOR_TOKEN env var is not set\n Available env vars:");
for (key, value) in env::vars() {
error!("{key}: {value}");
}
panic!("Exiting");
}
}),
options.ebusd_address,
options.thermometer_entity,
options.mqtt_host,
options.mqtt_username,
options.mqtt_password,
)
.await
{
Expand Down Expand Up @@ -187,7 +208,7 @@ impl Thermostat {
}

let mut ebusd = Ebusd::new(ebusd_address).await?;
ebusd.define_message( "wi,BAI,SetModeOverride,Betriebsart,,08,B510,00,hcmode,,UCH,,,,flowtempdesired,,D1C,,,,hwctempdesired,,D1C,,,,hwcflowtempdesired,,UCH,,,,setmode1,,UCH,,,,disablehc,,BI0,,,,disablehwctapping,,BI1,,,,disablehwcload,,BI2,,,,setmode2,,UCH,,,,remoteControlHcPump,,BI0,,,,releaseBackup,,BI1,,,,releaseCooling,,BI2".to_string()).await?;
ebusd.define_message( "wi,BAI,SetModeOverride,OperatingMode,,08,B510,00,hcmode,,UCH,,,,flowtempdesired,,D1C,,,,hwctempdesired,,D1C,,,,hwcflowtempdesired,,UCH,,,,setmode1,,UCH,,,,disablehc,,BI0,,,,disablehwctapping,,BI1,,,,disablehwcload,,BI2,,,,setmode2,,UCH,,,,remoteControlHcPump,,BI0,,,,releaseBackup,,BI1,,,,releaseCooling,,BI2".to_string()).await?;

Ok(Self {
ebusd,
Expand Down Expand Up @@ -444,3 +465,14 @@ impl Thermostat {
Ok(())
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Options {
ha_api_address: Option<String>,
ha_api_token: Option<String>,
ebusd_address: String,
thermometer_entity: String,
mqtt_host: String,
mqtt_username: String,
mqtt_password: String,
}
13 changes: 13 additions & 0 deletions example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,18 @@ RUN \
curl -sSLf -o /usr/bin/tempio \
"https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}"

# Install requirements for add-on
RUN \
apk add --no-cache \
python3

# Copy root filesystem
COPY rootfs /

WORKDIR /data

# Copy data for add-on
COPY run.sh /
RUN chmod a+x /run.sh

CMD [ "/run.sh" ]
57 changes: 0 additions & 57 deletions example/apparmor.txt

This file was deleted.

6 changes: 3 additions & 3 deletions example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ slug: example
description: Example add-on
url: "https://github.com/home-assistant/addons-example/tree/main/example"
arch:
- armhf
- armv7
- aarch64
- amd64
- i386
Expand All @@ -17,4 +15,6 @@ options:
message: "Hello world..."
schema:
message: "str?"
image: "ghcr.io/home-assistant/{arch}-addon-example"
startup: services
ports:
8000/tcp: 8000
5 changes: 5 additions & 0 deletions example/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv bashio

echo "Hello world!"

cat /data/options.json

0 comments on commit 70dc057

Please sign in to comment.