Skip to content

Commit

Permalink
Merge pull request #121 from openbase/feature/#62_openhab_3.2_support
Browse files Browse the repository at this point in the history
Feature/#62 openhab 4.0.4 support
  • Loading branch information
lhuxohl authored Nov 7, 2023
2 parents 5ccb18a + b59bbaf commit 7109649
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
5 changes: 3 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ ENV \
BCO_HOME="/home/bco/data" \
BCO_LOGS="/home/bco/data/log" \
BCO_BINARY="/usr/bin/bco" \
BCO_OPTIONS=""
MQTT_BROKER="mqtt-broker" \
BCO_OPTIONS="--host ${MQTT_BROKER}"

# Basic build-time metadata as defined at http://label-schema.org
LABEL org.label-schema.build-date=$BUILD_DATE \
Expand Down Expand Up @@ -111,7 +112,7 @@ ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

# Configure healthcheck
# todo: make sure only the registry availability is checks since devices are not maintained by this instance.
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate >/dev/null || exit 1
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate --host ${MQTT_BROKER} > /dev/null || exit 1

# switch to root, let the entrypoint drop back to bco user
USER root
Expand Down
4 changes: 2 additions & 2 deletions docker/bco-demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FROM openbaseorg/bco:${BCO_BASE_IMAGE_VERSION}
ENV \
JAVA_OPTS="" \
OPENHAB_CONF="/etc/openhab2" \
BCO_OPTIONS="--db /tmp/bco/db" \
BCO_OPTIONS="--db /tmp/bco/db --host ${MQTT_BROKER}" \
BCO_MODULE_PREPARE_SCRIPT="bco-module-prepare.sh"

# Basic build-time metadata as defined at http://label-schema.org
Expand Down Expand Up @@ -51,7 +51,7 @@ COPY --from=builder /workspace/db /usr/share/bco/db/

# Configure healthcheck
# todo: make sure only device offered by this device manager are checked
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate >/dev/null || exit 1
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate --host ${MQTT_BROKER} >/dev/null || exit 1

# switch to root, let the entrypoint drop back to bco user
USER root
Expand Down
3 changes: 1 addition & 2 deletions docker/device-manager/openhab/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ FROM openbaseorg/bco:${BCO_BASE_IMAGE_VERSION}
ENV \
JAVA_OPTS="" \
OPENHAB_CONF="/etc/openhab2" \
BCO_OPTIONS="" \
BCO_MODULE_PREPARE_SCRIPT="bco-module-prepare.sh"

# Basic build-time metadata as defined at http://label-schema.org
Expand All @@ -33,7 +32,7 @@ RUN ln -s /usr/local/bin/${BCO_MODULE_PREPARE_SCRIPT} && \

# Configure healthcheck
# todo: make sure only device offered by this device manager are checked
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate >/dev/null || exit 1
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate --host ${MQTT_BROKER} >/dev/null || exit 1

# switch to root, let the entrypoint drop back to bco user
USER root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.openhab.core.io.rest.core.thing.EnrichedThingDTO;
import org.openhab.core.items.dto.ItemDTO;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.dto.AbstractThingDTO;
import org.openhab.core.thing.dto.ChannelDTO;
import org.openhab.core.thing.dto.ThingDTO;
import org.openhab.core.thing.link.dto.ItemChannelLinkDTO;
Expand Down Expand Up @@ -84,7 +85,7 @@ public class SynchronizationProcessor {
* @return a device unit config for the thing as described above
* @throws NotAvailableException if no device could be found
*/
public static UnitConfig getDeviceForThing(final ThingDTO thingDTO) throws CouldNotPerformException {
public static UnitConfig getDeviceForThing(final AbstractThingDTO thingDTO) throws CouldNotPerformException {
// iterate over all devices
for (final UnitConfig deviceUnitConfig : Registries.getUnitRegistry().getUnitConfigsByUnitTypeFiltered(UnitType.DEVICE, false)) {
// get the most global meta config
Expand Down Expand Up @@ -135,7 +136,7 @@ public static String getUniquePrefix(final String uniqueId) {
return uniquePrefix.toString();
}

public static UnitConfig getLocationForThing(final ThingDTO thingDTO) throws CouldNotPerformException, InterruptedException {
public static UnitConfig getLocationForThing(final AbstractThingDTO thingDTO) throws CouldNotPerformException, InterruptedException {
if (thingDTO.location != null) {
List<UnitConfig> locationConfigs = Registries.getUnitRegistry(true).getUnitConfigsByLabelAndUnitType(thingDTO.location, UnitType.LOCATION);

Expand Down Expand Up @@ -178,7 +179,7 @@ public static DeviceClass getDeviceClassByDiscoveryResult(final DiscoveryResultD
return resolveDeviceClass(discoveryResult.label, discoveryResult.thingTypeUID, properties);
}

public static DeviceClass getDeviceClassForThing(final ThingDTO thingDTO) throws CouldNotPerformException {
public static DeviceClass getDeviceClassForThing(final AbstractThingDTO thingDTO) throws CouldNotPerformException {
return resolveDeviceClass(thingDTO.label, thingDTO.thingTypeUID, thingDTO.properties);
}

Expand All @@ -193,7 +194,7 @@ public static GatewayClass getGatewayClassByDiscoveryResult(final DiscoveryResul
return resolveGatewayClass(discoveryResult.label, discoveryResult.thingTypeUID, properties);
}

public static GatewayClass getGatewayClassForThing(final ThingDTO thingDTO) throws CouldNotPerformException {
public static GatewayClass getGatewayClassForThing(final AbstractThingDTO thingDTO) throws CouldNotPerformException {
return resolveGatewayClass(thingDTO.label, thingDTO.thingTypeUID, thingDTO.properties);
}

Expand Down Expand Up @@ -368,7 +369,7 @@ public static Map<ServiceType, ServicePattern> generateServiceMap(final UnitConf
return serviceTypePatternMap;
}

private static String getChannelUID(final UnitConfig unitConfig, final ServiceType serviceType, final ServicePattern servicePattern, final ThingDTO thingDTO) throws CouldNotPerformException {
private static String getChannelUID(final UnitConfig unitConfig, final ServiceType serviceType, final ServicePattern servicePattern, final EnrichedThingDTO thingDTO) throws CouldNotPerformException {
String channelUID = "";
// todo: validate that unit host is available by using UnitConfigProcessor.isHostUnitAvailable(unitConfig) and make sure apps are handled as well.
final UnitConfig deviceUnitConfig = Registries.getUnitRegistry().getUnitConfigById(unitConfig.getUnitHostId());
Expand Down Expand Up @@ -410,7 +411,7 @@ private static String getChannelUID(final UnitConfig unitConfig, final ServiceTy
return channelUID;
}

public static void registerAndValidateItems(final UnitConfig unitConfig, final ThingDTO thingDTO) throws CouldNotPerformException {
public static void registerAndValidateItems(final UnitConfig unitConfig, final EnrichedThingDTO thingDTO) throws CouldNotPerformException {
final List<ItemChannelLinkDTO> itemChannelLinks = OpenHABRestCommunicator.getInstance().getItemChannelLinks();
for (final Entry<ServiceType, ServicePattern> entry : generateServiceMap(unitConfig).entrySet()) {
final ServiceType serviceType = entry.getKey();
Expand Down Expand Up @@ -581,7 +582,7 @@ public static boolean updateUnitToThing(final EnrichedThingDTO thing, final Unit
* @param thingDTO the thing to be removed.
* @throws CouldNotPerformException if removing the thing fails.
*/
public static void deleteThing(final ThingDTO thingDTO) throws CouldNotPerformException {
public static void deleteThing(final EnrichedThingDTO thingDTO) throws CouldNotPerformException {
final List<ItemChannelLinkDTO> itemChannelLinks = OpenHABRestCommunicator.getInstance().getItemChannelLinks();
for (final ChannelDTO channel : thingDTO.channels) {
for (final ItemChannelLinkDTO itemChannelLink : itemChannelLinks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.openbase.type.domotic.unit.device.DeviceClassType.DeviceClass;
import org.openbase.type.domotic.unit.gateway.GatewayClassType.GatewayClass;
import org.openhab.core.io.rest.core.thing.EnrichedThingDTO;
import org.openhab.core.thing.dto.AbstractThingDTO;
import org.openhab.core.thing.dto.ThingDTO;

import java.util.ArrayList;
Expand Down Expand Up @@ -97,7 +98,7 @@ public void update(IdentifiableEnrichedThingDTO identifiableEnrichedThingDTO) th
@Override
public void register(IdentifiableEnrichedThingDTO identifiableEnrichedThingDTO) throws CouldNotPerformException, InterruptedException {
logger.debug("Synchronize {} ...", identifiableEnrichedThingDTO.getDTO().UID);
final ThingDTO thingDTO = identifiableEnrichedThingDTO.getDTO();
final EnrichedThingDTO thingDTO = identifiableEnrichedThingDTO.getDTO();

try {
final UnitConfig deviceUnitConfig = SynchronizationProcessor.getDeviceForThing(thingDTO);
Expand All @@ -111,7 +112,7 @@ public void register(IdentifiableEnrichedThingDTO identifiableEnrichedThingDTO)
}
}

private void registerDevice(ThingDTO thingDTO) throws CouldNotPerformException, InterruptedException {
private void registerDevice(EnrichedThingDTO thingDTO) throws CouldNotPerformException, InterruptedException {
//TODO: should this entire action be rolled back if one part fails?
// get device class for thing
DeviceClass deviceClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public boolean isSupported(IdentifiableEnrichedThingDTO identifiableEnrichedThin
return identifiableEnrichedThingDTO.getId().startsWith(BCO_BINDING_ID);
}

private String getUnitId(ThingDTO thingDTO) {
private String getUnitId(EnrichedThingDTO thingDTO) {
String[] split = thingDTO.UID.split(":");
return split[split.length - 1];
}

private void registerAndValidateItems(final ThingDTO thingDTO) throws CouldNotPerformException {
private void registerAndValidateItems(final EnrichedThingDTO thingDTO) throws CouldNotPerformException {
// save current item channel links to compute if some already exist
final List<ItemChannelLinkDTO> itemChannelLinks = OpenHABRestCommunicator.getInstance().getItemChannelLinks();
// retrieve the unit belonging to the thing
Expand Down
5 changes: 2 additions & 3 deletions versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ version.com.google.guava..guava=28.0-jre
## # available=31.0-jre
## # available=31.0.1-android
## # available=31.0.1-jre

version.org.openbase..jul.communication.mqtt.test=3.3-SNAPSHOT
version.org.openbase..jul.transformation=3.3-SNAPSHOT
version.org.testcontainers..junit-jupiter=1.18.3
Expand All @@ -55,9 +56,7 @@ version.org.springframework.boot..spring-boot-starter-webflux=3.1.2
version.org.springframework.boot..spring-boot-starter-jetty=3.1.2
version.org.springframework.boot..spring-boot-starter-websocket=3.1.2
version.org.springframework..spring-webmvc=6.0.11
version.org.openhab.core.bundles..org.openhab.core.io.rest.core=3.1.0
## # available=3.1.1
## # available=3.2.0
version.org.openhab.core.bundles..org.openhab.core.io.rest.core=4.0.4
plugin.org.springframework.boot=3.1.2
plugin.io.spring.dependency-management=1.1.2
version.kotlin=1.9.0
Expand Down

0 comments on commit 7109649

Please sign in to comment.