Skip to content

Commit

Permalink
anounce panel url in mqtt,
Browse files Browse the repository at this point in the history
add write config as argument
docker ha peresist config
  • Loading branch information
dafik committed Nov 21, 2023
1 parent 6e557ac commit 79a1d85
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 128 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ build/
/config/config-typescript/*
/config/editor/*
/docs/*
/docker/ha/sbc2ha.jar
2 changes: 1 addition & 1 deletion app/src/main/java/com/dfi/sbc2ha/Sbc2ha.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private Sbc2ha(long startTime) {
public static void main(String[] args) {
try {
long startTime = System.currentTimeMillis();
log.info("App starting {}", Version.VERSION);
log.info("App starting {}", Version.getVersion());

configFile = getConfigFile(args);
sbc2ha = new Sbc2ha(startTime);
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/com/dfi/sbc2ha/Version.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.dfi.sbc2ha;

public class Version {
public static final String VERSION = "java-0.0.6";
public static String getVersion(){
return Version.class.getPackage().getImplementationVersion();
private static final String VERSION = "java-0.0.7";

public static String getVersion() {
String implementationVersion = Version.class.getPackage().getImplementationVersion();
if (implementationVersion == null) {
return VERSION;
}
return implementationVersion;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.dfi.sbc2ha.components.platform.ha.autodiscovery.message;

import com.dfi.sbc2ha.Version;
import com.dfi.sbc2ha.components.platform.bus.ModbusFactory;
import com.dfi.sbc2ha.components.platform.ha.autodiscovery.HaDeviceType;
import com.dfi.sbc2ha.components.platform.ha.autodiscovery.SbcDeviceType;
import com.dfi.sbc2ha.components.sensor.modbus.ModbusSensor;
import com.dfi.sbc2ha.config.sbc2ha.definition.actuator.ActuatorConfig;
import com.dfi.sbc2ha.config.sbc2ha.definition.actuator.CoverConfig;
Expand All @@ -16,16 +19,16 @@
import com.dfi.sbc2ha.config.sbc2ha.definition.sensor.modbus.ModbusSensorDefinition;
import com.dfi.sbc2ha.config.sbc2ha.definition.sensor.modbus.Register;
import com.dfi.sbc2ha.config.sbc2ha.definition.sensor.oneWire.therm.DS18B20;
import com.dfi.sbc2ha.components.platform.bus.ModbusFactory;
import com.dfi.sbc2ha.components.platform.ha.autodiscovery.HaDeviceType;
import com.dfi.sbc2ha.components.platform.ha.autodiscovery.SbcDeviceType;
import com.dfi.sbc2ha.services.state.sensor.ButtonState;
import com.dfi.sbc2ha.web.Server;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -330,7 +333,15 @@ public DeviceAvailability(String topic, String model) {
identifiers.add(topic);
this.model = model;
name = topic;
swVersion = Version.VERSION;
swVersion = Version.getVersion();

try {
InetAddress localHost = InetAddress.getLocalHost();
configurationUrl = "http://" + localHost.getHostAddress() + ":" + Server.getPort();
} catch (UnknownHostException ignored) {

}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void prepareAutodiscovery() {
manager.addDisplayLine("prepare autodiscovery");
Availability.setTopicPrefix(mqttConfig.getTopicPrefix());
Availability.setModel("boneIO Relay Board");
Availability.setVersion(Version.VERSION);
Availability.setVersion(Version.getVersion());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private void drawUptime(List<?> lines) {
//g2d.drawString("java", 73, 15);

g2d.setFont(fontSmall);
g2d.drawString("version: " + Version.VERSION, 3, 30);
g2d.drawString("version: " + Version.getVersion(), 3, 30);

try {
g2d.drawString((String) lines.get(0), 3, 42);
Expand Down
21 changes: 8 additions & 13 deletions app/src/main/java/com/dfi/sbc2ha/web/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@


public class Server {
public static final int PORT = 8080;
private final String configFile;
private final EventBus eventBus = EventBus.getDefault();

public Server(String configFile) {
this.configFile = configFile;
port(8080);
int port = getPort();
port(port);
staticFiles.location("/editor");
webSocket("/ws/device", DeviceWebsocket.class);
webSocket("/ws/logs", LogWebsocket.class);
Expand All @@ -64,7 +66,11 @@ public Server(String configFile) {
});
}

private Route getConfigJson() {
public static int getPort() {
return PORT;
}

private Route getConfigJson() {
return (request, res) -> {
String filePath = ConfigProvider.getCachedFileName(configFile);
byte[] bytes = Files.readAllBytes(Paths.get(filePath));
Expand All @@ -90,17 +96,10 @@ private Route renderIndex() {
private Route convert() {
return (request, response) -> {
try {





List<Path> uploadFiles = getUploadFiles(request);
if (uploadFiles.size() == 1) {
return ConverterService.convert(uploadFiles.get(0));
}


} catch (RuntimeException e) {
response.status(HttpStatus.BAD_REQUEST_400);
return e.getMessage();
Expand All @@ -115,8 +114,6 @@ private Route writeCache() {
String inputFileName = "cache";
Path config = getUploadFile(request, inputFileName);
ConfigService.writeCache(config);


} catch (Exception e) {
response.status(HttpStatus.BAD_REQUEST_400);
return e.getMessage();
Expand Down Expand Up @@ -218,10 +215,8 @@ private List<Path> getUploadFiles(Request req) throws IOException, ServletExcept
File uploadDir = new File("/tmp/upload");
uploadDir.mkdir();


req.attribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement("/temp"));


HttpServletRequest raw = req.raw();
Collection<Part> parts = raw.getParts();

Expand Down
Loading

0 comments on commit 79a1d85

Please sign in to comment.