Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[openthermgateway] Add support for Ventilation/Heat Recovery units #11203

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
18a6645
Added support for Ventilation/Heat Recovery units
ArjenKorevaar Aug 13, 2021
887700e
Fixed vh_ventilationsetpoint issue and updated readme
ArjenKorevaar Aug 29, 2021
45de4f4
TSP and FHB indices are zero-based
ArjenKorevaar Sep 4, 2021
77a1629
Updated README
ArjenKorevaar Sep 4, 2021
3e06fa2
Replaced == with equals()
ArjenKorevaar Nov 27, 2021
210066c
Fixed a few code analysis messages and review comments
ArjenKorevaar Dec 18, 2021
986298c
[openthermgateway] align communication fixes & synchronization
andrewfg Feb 3, 2022
ebb99c8
[openthermgateway] fix potential NPE & decouple thread tasks
andrewfg Feb 3, 2022
b36ac99
[openthermgateway] delete unnecessary method
andrewfg Feb 3, 2022
8c215e7
[openthermgateway] remove unneccessary this. prefixes
andrewfg Feb 3, 2022
bd4bb8b
[openthermgateway] remove unneccessary this. prefixes
andrewfg Feb 3, 2022
6d275b3
[openthermgateway] remove unneccessary this. prefixes
andrewfg Feb 3, 2022
818c3bd
[openthermgateway] remove unneccessary this. prefixes
andrewfg Feb 3, 2022
0260288
[openthermgateway] revert Number:Dimensionless to Number:time
andrewfg Feb 3, 2022
7fe544e
[openthermgateway] revert Number:Dimensionless to Number:time
andrewfg Feb 3, 2022
34724e9
[openthermgateway] adopt suggestion of @fwolter
andrewfg Feb 3, 2022
dfcd977
[openthermgateway] decouple thread tasks
andrewfg Feb 3, 2022
9126601
[openthermgateway] spotless
andrewfg Feb 3, 2022
c710f62
[openthermgateway] convert timeout constants to config params
andrewfg Feb 3, 2022
2534d4c
[openthermgateway] spotless
andrewfg Feb 3, 2022
fba0377
[openthermgateway] tweak ReadMe as suggested by @fwolter
andrewfg Feb 3, 2022
269f4b9
[openthermgateway] remove potential NPE warnings
andrewfg Feb 3, 2022
47d4696
[openthermgateway] restore `diag` channel to boiler
andrewfg Feb 5, 2022
d181d62
[openthermgateway] update readme for Number:Time items
andrewfg Feb 7, 2022
344e89d
[openthermgateway] fix thing initialization
andrewfg Feb 7, 2022
20039f8
[openthermgateway] sparser logger messages
andrewfg Feb 10, 2022
93b9075
[openthermgateway] adopt reviewer suggestion
andrewfg Feb 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
520 changes: 365 additions & 155 deletions bundles/org.openhab.binding.openthermgateway/README.md

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.openthermgateway.handler;

import static org.openhab.binding.openthermgateway.internal.OpenThermGatewayBindingConstants.*;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.openthermgateway.internal.DataItem;
import org.openhab.binding.openthermgateway.internal.DataItemGroup;
import org.openhab.binding.openthermgateway.internal.Message;
import org.openhab.binding.openthermgateway.internal.TspFhbSizeDataItem;
import org.openhab.binding.openthermgateway.internal.TspFhbValueDataItem;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.type.ChannelKind;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link BaseDeviceHandler} is a base class for actual Things.
*
* @author Arjen Korevaar - Initial contribution
*/
@NonNullByDefault
public abstract class BaseDeviceHandler extends BaseThingHandler {

private final Logger logger = LoggerFactory.getLogger(BaseDeviceHandler.class);

public BaseDeviceHandler(Thing thing) {
super(thing);
}

@Override
public void initialize() {
Bridge bridge = getBridge();

if (bridge == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Bridge is missing");
andrewfg marked this conversation as resolved.
Show resolved Hide resolved
} else if (bridge.getStatus() != ThingStatus.ONLINE) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
andrewfg marked this conversation as resolved.
Show resolved Hide resolved
} else {
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
andrewfg marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
Bridge bridge = getBridge();

if (bridge != null) {
OpenThermGatewayHandler handler = (OpenThermGatewayHandler) bridge.getHandler();
if (handler != null) {
handler.handleCommand(channelUID, command);
}
} else {
logger.debug("Bridge is missing");
}
}

public void receiveMessage(Message message) {
DataItem[] dataItems = DataItemGroup.DATAITEMGROUPS.get(message.getID());

if (dataItems == null) {
logger.debug("No DataItem found for message id {}", message.getID());
return;
}

for (DataItem dataItem : dataItems) {
if (dataItem instanceof TspFhbSizeDataItem) {
logger.debug("Received TSP or FHB size message {} ({})", message.getID(), dataItem.getSubject());

verifyTspFhbChannels(((TspFhbSizeDataItem) dataItem).getValueId(),
message.getUInt(dataItem.getByteType()));
} else {
String channelId = dataItem.getChannelId(message);

if (thing.getChannel(channelId) == null || !dataItem.hasValidCodeType(message)) {
continue;
}

State state = dataItem.createState(message);

logger.debug("Received update for channel {}: {}", channelId, state);
updateState(channelId, state);
}
}
}

private void verifyTspFhbChannels(int id, int size) {
// Dynamically create TSP or FHB value channels based on TSP or FHB size message
ThingHandlerCallback callback = getCallback();

if (callback == null) {
logger.debug("Unable to get thing handler callback");
return;
}

DataItem[] dataItems = DataItemGroup.DATAITEMGROUPS.get(id);

if (dataItems == null) {
logger.debug("Unable to find dataItem for id {}", id);
return;
}

if (dataItems.length != 1) {
logger.debug("Found zero or multiple dataItems for id {}", id);
return;
}

TspFhbValueDataItem dataItem = (TspFhbValueDataItem) dataItems[0];

logger.debug("Checking number of TSP or FHB channels for DATA-ID {}: {}", id, size);

// A generic Number:Dimensionless channel type for TSP and FHB values
ChannelTypeUID channelTypeUID = new ChannelTypeUID(BINDING_ID, CHANNEL_TSPFHB);

List<Channel> channels = new ArrayList<>(getThing().getChannels());

boolean changed = false;
for (int i = 0; i < size; i++) {
String channelId = dataItem.getChannelId(i);
ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId);

if (!channels.stream().map(Channel::getUID).anyMatch(channelUID::equals)) {
String label = dataItem.getLabel(i);

logger.debug("Adding channel {}", channelId);

channels.add(callback.createChannelBuilder(channelUID, channelTypeUID).withKind(ChannelKind.STATE)
.withLabel(label).build());
changed = true;
} else {
logger.debug("Channel {} already exists", channelId);
}
}

if (changed) {
logger.debug("Updating Thing with new channels");
updateThing(editThing().withChannels(channels).build());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.openthermgateway.handler;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.Thing;

/**
* The {@link BoilerHandler} represemts a boiler with thermostat.
*
* @author Arjen Korevaar - Initial contribution
*/
@NonNullByDefault
public class BoilerHandler extends BaseDeviceHandler {

public BoilerHandler(Thing thing) {
super(thing);
}
}
Loading