Skip to content

Commit

Permalink
Merge branch 'v1.0.1rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed Aug 23, 2024
2 parents efa45df + d8f18dd commit f87728c
Show file tree
Hide file tree
Showing 19 changed files with 363 additions and 168 deletions.
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

35 changes: 18 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
plugins {
java
application
id("net.ltgt.errorprone") version "3.0.1"
jacoco
id("org.sonarqube") version "4.0.0.2929"
id("com.google.cloud.tools.jib") version "3.3.1"
id("com.gorylenko.gradle-git-properties") version "2.4.1"
alias(libs.plugins.errorprone)
alias(libs.plugins.sonarqube)
alias(libs.plugins.git.properties)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.jib)
}

repositories {
Expand All @@ -14,24 +15,24 @@ repositories {
}

group = "com.homeclimatecontrol.esphome2influxdb"
version = "1.0.0"
version = "1.0.1"

dependencies {
implementation("org.apache.logging.log4j:log4j-api:2.20.0")
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
implementation("org.yaml:snakeyaml:1.33")
implementation(libs.log4j.api)
implementation(libs.log4j.core)
implementation(libs.jackson.databind)
implementation(libs.jackson.dataformat.yaml)

// https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client.mqttv3
implementation("org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5")
implementation(libs.hivemq.mqtt.client)

implementation("org.influxdb:influxdb-java:2.23")
implementation(libs.influxdb)

testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.3")
testImplementation("org.mockito:mockito-core:5.2.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
testImplementation("org.assertj:assertj-core:3.24.2")
errorprone("com.google.errorprone:error_prone_core:2.18.0")
testImplementation(libs.junit5.api)
testImplementation(libs.junit5.params)
testImplementation(libs.mockito)
testRuntimeOnly(libs.junit5.engine)
testImplementation(libs.assertj.core)
errorprone(libs.errorprone)
}

application {
Expand Down
84 changes: 84 additions & 0 deletions docs/build/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
esphome2influxdb: Build for (not with) Docker
==

## Pull

Run `docker pull climategadgets/esphome2influxdb` and then proceed to [configuration section](#configure-and-run) below - don't forget to adjust the image name to `climategadgets/esphome2influxdb`.

Just in case, the image is hosted at https://hub.docker.com/r/climategadgets/esphome2influxdb.

## Build

Simply run `./gradlew jibDockerBuild`, this will build the image into the local Docker container (might need `sudo` if Docker is only configured to run as `root`).
See [Jib Gradle Plugin](https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin) docs for details.
Mind the image name, it will be different for different release trains.

### Build on Raspberry Pi

The above will work seamlessly only on `amd64` architectures. If you need to build the image on Raspberry Pi, apply the following diff:

```
diff --git a/build.gradle.kts b/build.gradle.kts
index e38dbe8..1eaebe3 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -74,6 +74,16 @@ sonarqube {
jib {
+ from {
+ platforms {
+ platform {
+ architecture = "arm"
+ os = "linux"
+ }
+ }
+ }
+
to {
image ="climategadgets/esphome2influxdb"
}
```

> NOTE: Ideally, this should be seamless, but it is not quite trivial and there's no demand. If it bothers you, please [submit a ticket](https://github.com/home-climate-control/esphome2influxdb/issues).
## Configure and Run

By default, the `esphome2influxdb` Docker image will be created with configuration found in `src/main/resources/esphome2influxdb.yaml` (specifically, source host of `mqtt-esphome` and target host of `influxdb-esphome`).

To make it do something meaningful, either create DNS records for these hosts and pass them to Docker daemon when you create the container, and/or provide your own configuration and map Docker volumes
(this is the preferred option since you will have to provide your tags at some point anyway, see [Tagging](../tagging.md) for details).

### Option 1 (default configuration, use this to make sure it works)

```
docker run \
--name esphome2influxdb-defaultconf \
--rm -it \
-e TZ=${your-time-zone} \
--dns ${your-dns-server-host} \
--dns-search ${your-search-domain} \
esphome2influxdb
```

With this configuration, the logs will be only stored in the container - execute `docker exec -it esphome2influxdb-defaultconf /bin/bash` to connect to it and see what's going on.

### Option 2 (custom configuration, logs exposed - this is what you'll have to do in the long run)

```
docker run \
--name esphome2influxdb \
--restart=unless-stopped \
-e TZ=${your-time-zone} \
--dns ${your-dns-server-host} \
--dns-search ${your-search-domain} \
-v ${your-esphome2influxdb-config-directory}:/app/conf \
-v ${your-esphome2influxdb-log-directory}:/app/logs \
esphome2influxdb
```

Config directory must have a `esphome2influxdb.yaml` file containing the configuration (see [Minimal Configuration](../minimal-configuration.md) for details).

---
[^^^ Index](../index.md)
10 changes: 10 additions & 0 deletions docs/build/gradle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
esphome2influxdb: Build with Gradle
==

Run `./gradlew installDist` (Java 17 or higher).

This will generate a relocatable directory tree in `./build/install/esphome2influxdb`,
including a runnable Shell script at `./build/install/esphome2influxdb/bin/esphome2influxdb`.

---
[^^^ Index](../index.md)
6 changes: 5 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ esphome2influxdb: Docs
## Current Limitations

* Currently works only with [ESPHome Sensor](https://esphome.io/components/sensor/index.html) components, more to come.
* The project's just been open sourced, documentation is coming, keep checking this wiki for updates.
* The project's just been open sourced, documentation is coming, keep checking this document tree for updates.

## Release Notes

[Here](./release-notes.md).

## Further Down the Rabbit Hole

Expand Down
7 changes: 7 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
esphome2influxdb: Release Notes
==

## v1.0.1 (2024-08-22)

* Eclipse Paho MQTT has been replaced with [HiveMQ](https://github.com/hivemq/hivemq-mqtt-client) ([#17](https://github.com/home-climate-control/esphome2influxdb/issues/17))
* Quality of Life improvements
34 changes: 34 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[versions]

assertj = "3.26.3"
errorprone = "2.30.0"
influxdb = "2.24"
jackson = "2.17.2"
jib = "3.4.3"
junit5 = "5.11.0"
log4j = "2.22.0"
mockito = "5.12.0"
hivemq-mqtt = "1.3.3"
sonarqube = "4.4.1.3373"

[libraries]

assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj" }
errorprone = { module = "com.google.errorprone:error_prone_core", version.ref = "errorprone" }
hivemq-mqtt-client = { module = "com.hivemq:hivemq-mqtt-client", version.ref = "hivemq-mqtt" }
influxdb = { module = "org.influxdb:influxdb-java", version.ref = "influxdb" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
jackson-dataformat-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "jackson" }
junit5-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" }
junit5-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit5" }
junit5-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit5" }
log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }
mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }

[plugins]
errorprone = { id = "net.ltgt.errorprone", version = "4.0.1" }
git-properties = { id = "com.gorylenko.gradle-git-properties", version = "2.4.2" }
gradle-versions = { id = "com.github.ben-manes.versions", version = "0.51.0"}
jib = { id = "com.google.cloud.tools.jib", version.ref = "jib" }
sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
29 changes: 17 additions & 12 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.homeclimatecontrol.esphome2influxdb;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.yaml.snakeyaml.Yaml;

import java.io.StringReader;
import java.io.StringWriter;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.yaml.snakeyaml.Yaml;

/**
* Main configuration class.
*/
Expand All @@ -22,7 +22,7 @@ public class Configuration implements Verifiable {
public Set<InfluxDbEndpoint> targets = new LinkedHashSet<>();
public Set<Object> devices = new LinkedHashSet<>();

private Set<Device> parsed = new LinkedHashSet<>();
private final Set<Device> parsed = new LinkedHashSet<>();

/**
* Verify the currently loaded configuration.
Expand Down Expand Up @@ -106,7 +106,7 @@ private void parseDevices() {
logger.trace("{}: {}", o.getClass().getName(), o);

@SuppressWarnings({ "unchecked" })
Map<String, String> m = (Map<String, String>) o;
var m = (Map<String, String>) o;
String type = m.get("type");

if (type == null) {
Expand Down Expand Up @@ -146,7 +146,6 @@ private void parseDevices() {
}

public Set<Device> getDevices() {

return parsed;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.homeclimatecontrol.esphome2influxdb;

import java.util.Map;
import java.util.TreeMap;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;

import java.util.Map;
import java.util.TreeMap;

public abstract class Device implements Verifiable {

protected final Logger logger = LogManager.getLogger();
Expand Down Expand Up @@ -75,7 +75,7 @@ public void verify() {
// ...but if the topic doesn't contain the source, and the source is not specified, we blow up anyway,
// ...and only set the name to default (being same as source) if it is not explicitly provided.

String[] result = resolve(topicPrefix);
var result = resolve(topicPrefix);

// Topic prefix may mutate
topicPrefix = result[0];
Expand Down Expand Up @@ -182,8 +182,8 @@ private String resolveSource(String topic) {
throw new IllegalArgumentException("Can't accept null topic here");
}

String[] tokens = topic.split("/");
String result = tokens[tokens.length - 1];
var tokens = topic.split("/");
var result = tokens[tokens.length - 1];
var deviceOffset = 2;

if ("".equals(result)) {
Expand All @@ -193,7 +193,7 @@ private String resolveSource(String topic) {
}

// Make sure that we're working with the right device
String type = tokens[tokens.length - deviceOffset];
var type = tokens[tokens.length - deviceOffset];

if (!getType().literal.equals(type)) {

Expand Down
Loading

0 comments on commit f87728c

Please sign in to comment.