Skip to content

Commit 09118a0

Browse files
committed
enhanced CRC error reporting for Onewire fixes foe Evo Home in FHZ4J
1 parent c0ac9ac commit 09118a0

File tree

12 files changed

+182
-109
lines changed

12 files changed

+182
-109
lines changed

de.ibapl.openhab.binding.fhz4j/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>de.ibapl.openhab</groupId>
88
<artifactId>ibapl-oh</artifactId>
9-
<version>4.2.0-0-SNAPSHOT</version>
9+
<version>4.2.0.0-SNAPSHOT</version>
1010
<relativePath>..</relativePath>
1111
</parent>
1212
<groupId>de.ibapl.openhab</groupId>

de.ibapl.openhab.binding.fhz4j/src/main/java/de/ibapl/openhab/fhz4j/handler/EvoHomeHandler.java

+55-38
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
import de.ibapl.fhz4j.protocol.evohome.EvoHomeDeviceMessage;
3232
import de.ibapl.fhz4j.protocol.evohome.ZoneTemperature;
3333
import de.ibapl.fhz4j.protocol.evohome.messages.AbstractZoneSetpointPayloadMessage;
34+
import de.ibapl.fhz4j.protocol.evohome.messages.AbstractZoneTemperaturePayloadMessage;
3435
import de.ibapl.fhz4j.protocol.evohome.messages.ZoneConfigPayloadMessage;
36+
import de.ibapl.fhz4j.protocol.evohome.messages.ZoneConfigRequestMessage;
3537
import de.ibapl.fhz4j.protocol.evohome.messages.ZoneHeatDemandInformationMessage;
38+
import de.ibapl.fhz4j.protocol.evohome.messages.ZoneSetpointRequestMessage;
3639
import static de.ibapl.openhab.fhz4j.FHZ4JBindingConstants.*;
3740
import java.io.IOException;
3841
import java.util.logging.Level;
@@ -99,7 +102,7 @@ public void initialize() {
99102
try {
100103
deviceId = ((Number) configuration.get("deviceId")).intValue();
101104
} catch (Exception e) {
102-
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, "Can't parse deviceId");
105+
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, "Can''t parse deviceId");
103106
evoHomeRadiatorHandlerStatus = ThingStatusDetail.HANDLER_INITIALIZING_ERROR;
104107
return;
105108
}
@@ -138,7 +141,7 @@ public void updateFromMsg(EvoHomeDeviceMessage msg) {
138141
}
139142
case ZONE_TEMPERATURE -> {
140143
//From SingleZoneThermostat and RadiatorController and MultZoneController
141-
final AbstractZoneSetpointPayloadMessage m = (AbstractZoneSetpointPayloadMessage) msg;
144+
final AbstractZoneTemperaturePayloadMessage m = (AbstractZoneTemperaturePayloadMessage) msg;
142145
switch (m.deviceId1.type) {
143146
case RADIATOR_CONTROLLER, SINGLE_ZONE_THERMOSTAT -> //TODO ZoneID ???
144147
updateState(new ChannelUID(getThing().getUID(), CHANNEL_TEMPERATURE_MEASURED),
@@ -150,56 +153,70 @@ public void updateFromMsg(EvoHomeDeviceMessage msg) {
150153
}
151154
}
152155
default -> {
156+
LOGGER.log(Level.SEVERE, "Can''t handle ZONE_TEMPERATURE message: {0}", msg);
153157
}
154158
}
155159
}
156160
case ZONE_SETPOINT -> {
157-
//From RadiatorController and MultZoneController
158-
final AbstractZoneSetpointPayloadMessage m = (AbstractZoneSetpointPayloadMessage) msg;
159-
switch (m.deviceId1.type) {
160-
case RADIATOR_CONTROLLER, SINGLE_ZONE_THERMOSTAT -> //TODO ZoneID ???
161-
updateState(new ChannelUID(getThing().getUID(), CHANNEL_DESIRED_TEMPERATURE),
162-
new DecimalType(m.zoneTemperatures.get(0).temperature));
163-
case MULTI_ZONE_CONTROLLER -> {
164-
for (ZoneTemperature zoneTemperature : m.zoneTemperatures) {
165-
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_DESIRED_TEMPERATURE, zoneTemperature.zone)),
166-
new DecimalType(zoneTemperature.temperature));
161+
if (msg instanceof AbstractZoneSetpointPayloadMessage m) {
162+
//From RadiatorController and MultZoneController
163+
switch (m.deviceId1.type) {
164+
case RADIATOR_CONTROLLER, SINGLE_ZONE_THERMOSTAT -> //TODO ZoneID ???
165+
updateState(new ChannelUID(getThing().getUID(), CHANNEL_DESIRED_TEMPERATURE),
166+
new DecimalType(m.zoneTemperatures.get(0).temperature));
167+
case MULTI_ZONE_CONTROLLER -> {
168+
for (ZoneTemperature zoneTemperature : m.zoneTemperatures) {
169+
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_DESIRED_TEMPERATURE, zoneTemperature.zone)),
170+
new DecimalType(zoneTemperature.temperature));
171+
}
172+
}
173+
default -> {
174+
LOGGER.log(Level.SEVERE, "Can''t handle ZONE_SETPOINT message: {0}", msg);
167175
}
168176
}
169-
default -> {
170-
}
177+
} else if (msg instanceof ZoneSetpointRequestMessage m) {
178+
LOGGER.log(Level.INFO, "ZoneSetpointRequestMessage received ZONE_SETPOINT payload: \"{0}\"", m);
179+
} else {
180+
LOGGER.log(Level.SEVERE, "Can''t handle ZONE_SETPOINT message: {0}", msg);
171181
}
172182
}
173183
case ZONE_CONFIG -> {
174-
final ZoneConfigPayloadMessage zpm = (ZoneConfigPayloadMessage) msg;
175-
switch (zpm.deviceId1.type) {
176-
case RADIATOR_CONTROLLER, SINGLE_ZONE_THERMOSTAT -> {
177-
updateState(new ChannelUID(getThing().getUID(), CHANNEL_MIN_TEMP),
178-
new DecimalType(zpm.zones.get(0).minTemperature));
179-
updateState(new ChannelUID(getThing().getUID(), CHANNEL_MAX_TEMP),
180-
new DecimalType(zpm.zones.get(0).maxTemperature));
181-
updateState(new ChannelUID(getThing().getUID(), CHANNEL_OPERATION_LOCK),
182-
zpm.zones.get(0).operationLock ? OnOffType.ON : OnOffType.OFF);
183-
updateState(new ChannelUID(getThing().getUID(), CHANNEL_WINDOW_FUNCTION),
184-
zpm.zones.get(0).windowFunction ? OnOffType.ON : OnOffType.OFF);
185-
}
186-
case MULTI_ZONE_CONTROLLER -> {
187-
for (ZoneConfigPayloadMessage.ZoneParams zoneParam : zpm.zones) {
188-
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_MIN_TEMP, zoneParam.zoneId)),
189-
new DecimalType(zoneParam.minTemperature));
190-
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_MAX_TEMP, zoneParam.zoneId)),
191-
new DecimalType(zoneParam.maxTemperature));
192-
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_OPERATION_LOCK, zoneParam.zoneId)),
193-
zoneParam.operationLock ? OnOffType.ON : OnOffType.OFF);
194-
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_WINDOW_FUNCTION, zoneParam.zoneId)),
195-
zoneParam.windowFunction ? OnOffType.ON : OnOffType.OFF);
184+
if (msg instanceof ZoneConfigPayloadMessage zpm) {
185+
switch (zpm.deviceId1.type) {
186+
case RADIATOR_CONTROLLER, SINGLE_ZONE_THERMOSTAT -> {
187+
updateState(new ChannelUID(getThing().getUID(), CHANNEL_MIN_TEMP),
188+
new DecimalType(zpm.zones.get(0).minTemperature));
189+
updateState(new ChannelUID(getThing().getUID(), CHANNEL_MAX_TEMP),
190+
new DecimalType(zpm.zones.get(0).maxTemperature));
191+
updateState(new ChannelUID(getThing().getUID(), CHANNEL_OPERATION_LOCK),
192+
zpm.zones.get(0).operationLock ? OnOffType.ON : OnOffType.OFF);
193+
updateState(new ChannelUID(getThing().getUID(), CHANNEL_WINDOW_FUNCTION),
194+
zpm.zones.get(0).windowFunction ? OnOffType.ON : OnOffType.OFF);
195+
}
196+
case MULTI_ZONE_CONTROLLER -> {
197+
for (ZoneConfigPayloadMessage.ZoneParams zoneParam : zpm.zones) {
198+
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_MIN_TEMP, zoneParam.zoneId)),
199+
new DecimalType(zoneParam.minTemperature));
200+
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_MAX_TEMP, zoneParam.zoneId)),
201+
new DecimalType(zoneParam.maxTemperature));
202+
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_OPERATION_LOCK, zoneParam.zoneId)),
203+
zoneParam.operationLock ? OnOffType.ON : OnOffType.OFF);
204+
updateState(new ChannelUID(getThing().getUID(), String.format(_XX_TEMPLATE, CHANNEL_WINDOW_FUNCTION, zoneParam.zoneId)),
205+
zoneParam.windowFunction ? OnOffType.ON : OnOffType.OFF);
206+
}
207+
}
208+
default -> {
209+
LOGGER.log(Level.SEVERE, "Can''t handle ZONE_SETPOINT message: {0}", msg);
196210
}
197211
}
198-
default -> {
199-
}
212+
} else if (msg instanceof ZoneConfigRequestMessage m) {
213+
LOGGER.log(Level.INFO, "ZoneConfigRequestMessage received ZONE_CONFIG payload: \"{0}\"", m);
214+
} else {
215+
LOGGER.log(Level.SEVERE, "Can''t handle ZONE_CONFIG message: {0}", msg);
200216
}
201217
}
202218
default -> {
219+
LOGGER.log(Level.SEVERE, "Can''t handle {0} message: {1}", new Object[]{msg.command, msg});
203220
}
204221
}
205222
}

de.ibapl.openhab.binding.fhz4j/src/main/java/de/ibapl/openhab/fhz4j/handler/SpswBridgeHandler.java

+33-19
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import java.time.format.DateTimeFormatter;
6363
import java.util.EnumSet;
6464
import java.util.HashMap;
65+
import java.util.List;
6566
import java.util.Map;
6667
import java.util.concurrent.Future;
6768
import java.util.logging.Level;
@@ -298,7 +299,7 @@ public void onIOException(IOException ioe) {
298299
}
299300
}
300301

301-
private final SerialPortSocketFactory serialPortSocketFactory;
302+
private final List<SerialPortSocketFactory> serialPortSocketFactories;
302303

303304
private static final String PORT_PARAM = "port";
304305
private static final String SPEED_PARAM = "speed";
@@ -331,28 +332,37 @@ public void onIOException(IOException ioe) {
331332
private final CronScheduler cronScheduler;
332333
private ScheduledCompletableFuture refreshJob;
333334

334-
public SpswBridgeHandler(Bridge bridge, SerialPortSocketFactory serialPortSocketFactory, CronScheduler cronScheduler) {
335+
public SpswBridgeHandler(Bridge bridge, List<SerialPortSocketFactory> serialPortSocketFactories, CronScheduler cronScheduler) {
335336
super(bridge);
336-
this.serialPortSocketFactory = serialPortSocketFactory;
337+
this.serialPortSocketFactories = serialPortSocketFactories;
337338
this.cronScheduler = cronScheduler;
338339
protocolFHT = true;
339340
}
340341

341342
private SerialPortSocket createSerialPortSocket() throws IOException {
342343
String opendString = DateTimeFormatter.ISO_INSTANT.format(Instant.now());
343-
final SerialPortSocket sps = serialPortSocketFactory.open(port);
344-
if (logSerialPort) {
345-
LoggingSerialPortSocket result = LoggingSerialPortSocket.wrapWithCustomOutputStream(sps,
346-
new SupressReadTimeoutExceptionLogWriter(new FileOutputStream("CUL_SpswBridgeHandler_" + opendString + ".log.txt"),
347-
true,
348-
TimeStampLogging.UTC,
349-
true));
350-
logExplainRead = result;
351-
logExplainWrite = result;
352-
return result;
353-
} else {
354-
return sps;
344+
for (SerialPortSocketFactory spsf : serialPortSocketFactories) {
345+
try {
346+
final SerialPortSocket sps = spsf.open(port);
347+
if (logSerialPort) {
348+
LoggingSerialPortSocket result = LoggingSerialPortSocket.wrapWithCustomOutputStream(sps,
349+
new SupressReadTimeoutExceptionLogWriter(new FileOutputStream("CUL_SpswBridgeHandler_" + opendString + ".log.txt"),
350+
true,
351+
TimeStampLogging.UTC,
352+
true));
353+
logExplainRead = result;
354+
logExplainWrite = result;
355+
return result;
356+
} else {
357+
logExplainRead = null;
358+
logExplainWrite = null;
359+
return sps;
360+
}
361+
} catch (Exception e) {
362+
LOGGER.log(Level.INFO, "Can't use spsw factory: " + spsf, e);
363+
}
355364
}
365+
throw new RuntimeException("No useable spsw factory found");
356366
}
357367

358368
@Override
@@ -421,7 +431,8 @@ private void initCulAdapter() throws IOException {
421431

422432
@Override
423433
public void initialize() {
424-
LOGGER.log(Level.FINE, "Initializing SpswBridgeHandler.");
434+
//TODO make log level fine
435+
LOGGER.log(Level.INFO, "Initializing SpswBridgeHandler: {0}", this);
425436

426437
Configuration config = getThing().getConfiguration();
427438

@@ -470,11 +481,12 @@ public void initialize() {
470481
try {
471482
culAdapter = new CulAdapter(createSerialPortSocket(), new Listener(), speed);
472483
initCulAdapter();
473-
} catch (IOException e) {
474-
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
484+
} catch (IOException ioe) {
485+
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, ioe.getMessage());
486+
LOGGER.log(Level.SEVERE, "Got IOE in CUL Adapter during initialization", ioe);
475487
try {
476488
culAdapter.close();
477-
} catch (Exception e1) {
489+
} catch (Exception e) {
478490
LOGGER.log(Level.SEVERE, "Could not shutdown fhzAdapter", e);
479491
}
480492
culAdapter = null;
@@ -497,6 +509,8 @@ public void initialize() {
497509

498510
@Override
499511
public void dispose() {
512+
//TODO make log level fine
513+
LOGGER.log(Level.INFO, "Disposing SpswBridgeHandler: {0}", this);
500514
if (refreshJob != null) {
501515
refreshJob.cancel(true);
502516
refreshJob = null;

de.ibapl.openhab.binding.fhz4j/src/main/java/de/ibapl/openhab/fhz4j/internal/FHZ4JHandlerFactory.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import de.ibapl.spsw.api.SerialPortSocketFactory;
3434
import java.util.HashMap;
3535
import java.util.Hashtable;
36+
import java.util.List;
3637
import java.util.Map;
3738
import java.util.Set;
3839
import java.util.logging.Logger;
@@ -71,7 +72,7 @@ public class FHZ4JHandlerFactory extends BaseThingHandlerFactory {
7172
FHZ4JBindingConstants.THING_TYPE_FHZ4J_MULTI_ZONE_CONTROLLER_EVO_HOME);
7273

7374
@Reference
74-
private SerialPortSocketFactory serialPortSocketFactory;
75+
private List<SerialPortSocketFactory> serialPortSocketFactories;
7576

7677
@Reference
7778
private CronScheduler cronScheduler;
@@ -104,12 +105,16 @@ protected ThingHandler createHandler(Thing thing) {
104105
final Hms100TfHandler hms100TkHandler = new Hms100TfHandler(thing);
105106
return hms100TkHandler;
106107
} else if (thingTypeUID.equals(FHZ4JBindingConstants.BRIDGE_TYPE_FHZ4J_RS232)) {
107-
if (serialPortSocketFactory == null) {
108-
logger.severe("serialPortSocketFactory == null");
108+
if (serialPortSocketFactories == null) {
109+
logger.severe("serialPortSocketFactories == null");
110+
//TODO
111+
return null;
112+
} else if (serialPortSocketFactories.isEmpty()) {
113+
logger.severe("serialPortSocketFactories is empty");
109114
//TODO
110115
return null;
111116
} else {
112-
final SpswBridgeHandler spswBridgeHandler = new SpswBridgeHandler((Bridge) thing, serialPortSocketFactory, cronScheduler);
117+
final SpswBridgeHandler spswBridgeHandler = new SpswBridgeHandler((Bridge) thing, serialPortSocketFactories, cronScheduler);
113118
registerDiscoveryService(spswBridgeHandler);
114119
return spswBridgeHandler;
115120
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<addon:addon id="fhz4j" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xmlns:addon="https://openhab.org/schemas/addon/v1.0.0"
4-
xsi:schemaLocation="https://openhab.org/schemas/addon/v1.0.0 https://openhab.org/schemas/addon-1.0.0.xsd">
5-
6-
<type>binding</type>
7-
<name>Fhz4J Binding</name>
8-
<description>The Fhz binding integrates the Fhz and EvoHome systems via the CUL RF-receiver.</description>
9-
<connection>local</connection>
10-
11-
</addon:addon>
2+
<addon:addon xmlns:addon="https://openhab.org/schemas/addon/v1.0.0"
3+
id="fhz4j"
4+
xsi:schemaLocation="https://openhab.org/schemas/addon/v1.0.0 https://openhab.org/schemas/addon-1.0.0.xsd"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6+
7+
<type>binding</type>
8+
<name>Fhz4J Binding</name>
9+
<description>The Fhz binding integrates the Fhz and EvoHome systems via the CUL RF-receiver.</description>
10+
<connection>local</connection>
11+
12+
</addon:addon>

de.ibapl.openhab.binding.onewire4j/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>de.ibapl.openhab</groupId>
88
<artifactId>ibapl-oh</artifactId>
9-
<version>4.2.0-0-SNAPSHOT</version>
9+
<version>4.2.0.0-SNAPSHOT</version>
1010
<relativePath>..</relativePath>
1111
</parent>
1212
<groupId>de.ibapl.openhab</groupId>

0 commit comments

Comments
 (0)