Skip to content

Commit

Permalink
4.0.x (#48)
Browse files Browse the repository at this point in the history
* Bump to openHAB 4.0

* Internationalization

* Simplify bridge channels id

* Descriptions update

* Remove project setting files

* Remove IDE setting

* FL

* Description update

* Bridge channels to property

* Get device information

* Dead code removed

* Added device information properties

* Added device information properties

* oh4 shield

* Update README.md

* OH4 final
  • Loading branch information
docbender authored Aug 14, 2023
1 parent e1bf806 commit c0c6dcc
Show file tree
Hide file tree
Showing 25 changed files with 985 additions and 650 deletions.
1 change: 1 addition & 0 deletions .github/openHAB40.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This binding for openHAB has ability to connect Simatic PLC over Ethernet with isoTCP. So it should be possible to connect to the Simatic PLC S7-300, S7-400, S7-1200 and S7-1500 series.

[![openHAB](/.github/openHAB30.svg)](https://github.com/openhab)
[![openHAB](/.github/openHAB40.svg)](https://github.com/openhab)
[![Version](https://img.shields.io/github/v/release/docbender/openHAB-Simatic?include_prereleases)](https://github.com/docbender/openHAB-Simatic/releases)
[![Download](https://img.shields.io/github/downloads/docbender/openHAB-Simatic/total.svg)](https://github.com/docbender/openHAB-Simatic/releases)
[![Issues](https://img.shields.io/github/issues/docbender/openHAB-Simatic)](https://github.com/docbender/openHAB-Simatic/issues)
Expand Down
45 changes: 0 additions & 45 deletions org.openhab.binding.simatic/.classpath

This file was deleted.

194 changes: 0 additions & 194 deletions org.openhab.binding.simatic/.factorypath

This file was deleted.

34 changes: 0 additions & 34 deletions org.openhab.binding.simatic/.project

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

34 changes: 17 additions & 17 deletions org.openhab.binding.simatic/pom.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>3.3.0</version>
</parent>

<artifactId>org.openhab.binding.simatic</artifactId>

<name>openHAB Add-ons :: Bundles :: Simatic Binding</name>

</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>4.0.1</version>
</parent>

<artifactId>org.openhab.binding.simatic</artifactId>

<name>openHAB Add-ons :: Bundles :: Simatic Binding</name>

</project>
4 changes: 2 additions & 2 deletions org.openhab.binding.simatic/src/main/history/dependencies.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.6.0" name="org.openhab.binding.simatic-3.3.0">
<features xmlns="http://karaf.apache.org/xmlns/features/v1.6.0" name="org.openhab.binding.simatic-4.0.1">
<feature version="0.0.0">
<feature>openhab-runtime-base</feature>
<feature>wrap</feature>
<bundle>mvn:org.openhab.addons.bundles/org.openhab.binding.simatic/3.3.0</bundle>
<bundle>mvn:org.openhab.addons.bundles/org.openhab.binding.simatic/4.0.1</bundle>
<bundle>wrap:mvn:org.lastnpe.eea/eea-all/2.2.1</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.simatic.internal.SimaticBindingConstants;
Expand All @@ -27,9 +26,6 @@
import org.openhab.binding.simatic.internal.simatic.SimaticTCP200;
import org.openhab.binding.simatic.internal.simatic.SimaticUpdateMode;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
Expand Down Expand Up @@ -57,7 +53,7 @@ public class SimaticBridgeHandler extends BaseBridgeHandler {
public @Nullable SimaticGenericDevice connection = null;

// bridge channels
private @Nullable ChannelUID chVersion, chPduSize, chAreasCount, chAreas, chTagCount, chRequests, chBytes;
private @Nullable ChannelUID chTagCount, chRequests, chBytes;

private int channelCount = 0;
/** Initial scheduler delay */
Expand All @@ -74,15 +70,7 @@ public SimaticBridgeHandler(Bridge bridge) {

// retrieve bridge channels
getThing().getChannels().forEach((channel) -> {
if (channel.getChannelTypeUID().equals(SimaticBindingConstants.CHANNEL_TYPE_VERSION)) {
chVersion = channel.getUID();
} else if (channel.getChannelTypeUID().equals(SimaticBindingConstants.CHANNEL_TYPE_PDU_SIZE)) {
chPduSize = channel.getUID();
} else if (channel.getChannelTypeUID().equals(SimaticBindingConstants.CHANNEL_TYPE_AREAS_COUNT)) {
chAreasCount = channel.getUID();
} else if (channel.getChannelTypeUID().equals(SimaticBindingConstants.CHANNEL_TYPE_AREAS)) {
chAreas = channel.getUID();
} else if (channel.getChannelTypeUID().equals(SimaticBindingConstants.CHANNEL_TYPE_TAG_COUNT)) {
if (channel.getChannelTypeUID().equals(SimaticBindingConstants.CHANNEL_TYPE_TAG_COUNT)) {
chTagCount = channel.getUID();
} else if (channel.getChannelTypeUID().equals(SimaticBindingConstants.CHANNEL_TYPE_REQUESTS)) {
chRequests = channel.getUID();
Expand All @@ -95,7 +83,7 @@ public SimaticBridgeHandler(Bridge bridge) {
@SuppressWarnings("null")
@Override
public void initialize() {
updateState(chVersion, new StringType(SimaticBindingConstants.VERSION));
updateProperty(SimaticBindingConstants.PROPERTY_BINDING_VERSION, SimaticBindingConstants.VERSION);

config = getConfigAs(SimaticBridgeConfiguration.class);

Expand Down Expand Up @@ -174,10 +162,39 @@ public void initialize() {
// react on connection changes
connection.onConnectionChanged((connected) -> {
if (connected) {
updateState(chPduSize, new DecimalType((Number) connection.getPduSize()));
updateState(chAreasCount, new DecimalType((Number) connection.getReadAreas().size()));
updateState(chAreas, new StringType(
(connection.getReadAreas().size() == 0) ? "none" : connection.getReadAreas().toString()));
updateProperty(SimaticBindingConstants.PROPERTY_PDU, String.valueOf(connection.getPduSize()));
updateProperty(SimaticBindingConstants.PROPERTY_AREAS_COUNT,
String.valueOf(connection.getReadAreas().size()));
updateProperty(SimaticBindingConstants.PROPERTY_AREAS,
(connection.getReadAreas().size() == 0) ? "none" : connection.getReadAreas().toString());
if (connection.info.getPlcName() != null) {
updateProperty(SimaticBindingConstants.PROPERTY_PLC_NAME, connection.info.getPlcName());
}
if (connection.info.getModuleName() != null) {
updateProperty(SimaticBindingConstants.PROPERTY_MODULE_NAME, connection.info.getModuleName());
}
if (connection.info.getModuleTypeName() != null) {
updateProperty(SimaticBindingConstants.PROPERTY_MODULE_NAME_TYPE,
connection.info.getModuleTypeName());
}
if (connection.info.getCopyright() != null) {
updateProperty(SimaticBindingConstants.PROPERTY_COPYRIGHT, connection.info.getCopyright());
}
if (connection.info.getSerialNumber() != null) {
updateProperty(SimaticBindingConstants.PROPERTY_SERIAL, connection.info.getSerialNumber());
}
if (connection.info.getOrderNr() != null) {
updateProperty(SimaticBindingConstants.PROPERTY_ORDER_NUMBER, connection.info.getOrderNr());
}
if (connection.info.getHwVersion() != null) {
updateProperty(SimaticBindingConstants.PROPERTY_HW_VERSION, connection.info.getHwVersion());
}
if (connection.info.getFwVersion() != null) {
updateProperty(SimaticBindingConstants.PROPERTY_FW_VERSION, connection.info.getFwVersion());
}
if (connection.info.getMemorySize() != null) {
updateProperty(SimaticBindingConstants.PROPERTY_MEMORY_SIZE, connection.info.getMemorySize());
}

updateStatus(ThingStatus.ONLINE);
} else {
Expand All @@ -186,8 +203,8 @@ public void initialize() {
});

connection.onMetricsUpdated((requests, bytes) -> {
updateState(chRequests, new DecimalType((Number) requests));
updateState(chBytes, new DecimalType((Number) bytes));
updateState(chRequests, new DecimalType(requests));
updateState(chBytes, new DecimalType(bytes));
});

// temporarily status
Expand Down Expand Up @@ -221,30 +238,14 @@ public void dispose() {
logger.debug("{} - bridge has been stopped", getThing().getLabel());
}

@SuppressWarnings("null")
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("{} - Command {} for channel {}", thing.getLabel(), command, channelUID);

// get cached values
if (command instanceof RefreshType) {
if (channelUID.equals(chVersion)) {
updateState(channelUID, new StringType(SimaticBindingConstants.VERSION));
} else if (channelUID.equals(chPduSize)) {
if (connection != null && connection.isConnected()) {
updateState(chPduSize, new QuantityType<>(connection.getPduSize(), Units.BYTE));
}
} else if (channelUID.equals(chAreas)) {
if (connection != null && connection.isConnected()) {
updateState(chAreas, new StringType(
(connection.getReadAreas().size() == 0) ? "none" : connection.getReadAreas().toString()));
}
} else if (channelUID.equals(chAreasCount)) {
if (connection != null && connection.isConnected()) {
updateState(chAreasCount, new DecimalType((Number) connection.getReadAreas().size()));
}
} else if (channelUID.equals(chTagCount)) {
updateState(channelUID, new DecimalType((Number) channelCount));
if (channelUID.equals(chTagCount)) {
updateState(channelUID, new DecimalType(channelCount));
}
}
}
Expand Down Expand Up @@ -274,7 +275,7 @@ public void updateConfig() {
}
}

var stateItems = new ArrayList<@NonNull SimaticChannel>(stateChannelCount);
var stateItems = new ArrayList<SimaticChannel>(stateChannelCount);

for (Thing th : getThing().getThings()) {
var h = ((SimaticGenericHandler) th.getHandler());
Expand All @@ -291,15 +292,9 @@ public void updateConfig() {
if (connection != null) {
var c = connection;
c.setDataAreas(stateItems);

if (c.isConnected()) {
updateState(chAreasCount, new DecimalType((Number) c.getReadAreas().size()));
updateState(chAreas,
new StringType((c.getReadAreas().size() == 0) ? "none" : c.getReadAreas().toString()));
}
}

updateState(chTagCount, new DecimalType((Number) channelCount));
updateState(chTagCount, new DecimalType(channelCount));

logger.debug("{} - updating {} channels({} read)", getThing().getLabel(), channelCount, stateChannelCount);
}
Expand Down
Loading

0 comments on commit c0c6dcc

Please sign in to comment.