Skip to content

Commit

Permalink
[openwebnet] Add support for Alarm (WHO=5) (openhab#13694)
Browse files Browse the repository at this point in the history
* [openwebnet] first changes for Alarm support
* [openwebnet] added first version Alarm handler
* [openwebnet] added ownIdTest for Alarm
* [openwebnet] added things def for Alarm and discovery for alarm zone
* [openwebnet] refreshDevice
* [openwebnet] fix text formatting
* [openwebnet] fixes
* [openwebnet] added other alarm channels
* [openwebnet] Alarm: codestyle and null checks
* [openwebnet] updated Alarm examples in README and some cleanup
* [openwebnet] changed zone channel from armed to state, cleaned README

Signed-off-by: Massimo Valla <mvcode00@gmail.com>
  • Loading branch information
mvalla authored and psmedley committed Feb 23, 2023
1 parent 87ad3a7 commit 5697754
Show file tree
Hide file tree
Showing 12 changed files with 630 additions and 171 deletions.
215 changes: 124 additions & 91 deletions bundles/org.openhab.binding.openwebnet/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.openwebnet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>io.github.openwebnet4j</groupId>
<artifactId>openwebnet4j</artifactId>
<version>0.9.0</version>
<version>0.9.1</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import org.openhab.core.thing.ThingTypeUID;

/**
* The {@link OpenWebNetBindingConstants} class defines common constants, which are used across the whole binding.
* The {@link OpenWebNetBindingConstants} class defines common constants, which
* are used across the whole binding.
*
* @author Massimo Valla - Initial contribution, updates
* @author Gilberto Cocchi - Thermoregulation
Expand Down Expand Up @@ -72,6 +73,10 @@ public class OpenWebNetBindingConstants {
public static final String THING_LABEL_BUS_CENPLUS_SCENARIO_CONTROL = "CEN+ Scenario Control";
public static final ThingTypeUID THING_TYPE_BUS_SCENARIO = new ThingTypeUID(BINDING_ID, "bus_scenario_control");
public static final String THING_LABEL_BUS_SCENARIO = "Scenario Control";
public static final ThingTypeUID THING_TYPE_BUS_ALARM_SYSTEM = new ThingTypeUID(BINDING_ID, "bus_alarm_system");
public static final String THING_LABEL_BUS_ALARM_SYSTEM = "Alarm System";
public static final ThingTypeUID THING_TYPE_BUS_ALARM_ZONE = new ThingTypeUID(BINDING_ID, "bus_alarm_zone");
public static final String THING_LABEL_BUS_ALARM_ZONE = "Alarm Zone";
public static final ThingTypeUID THING_TYPE_BUS_AUX = new ThingTypeUID(BINDING_ID, "bus_aux");
public static final String THING_LABEL_BUS_AUX = "Auxiliary";
// ZIGBEE
Expand Down Expand Up @@ -107,12 +112,16 @@ public class OpenWebNetBindingConstants {
public static final Set<ThingTypeUID> SCENARIO_BASIC_SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BUS_SCENARIO);
// ## Aux
public static final Set<ThingTypeUID> AUX_SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BUS_AUX);
// ## Alarm
public static final Set<ThingTypeUID> ALARM_SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BUS_ALARM_SYSTEM,
THING_TYPE_BUS_ALARM_ZONE);

// ## Groups
public static final Set<ThingTypeUID> DEVICE_SUPPORTED_THING_TYPES = Stream
.of(LIGHTING_SUPPORTED_THING_TYPES, AUTOMATION_SUPPORTED_THING_TYPES,
THERMOREGULATION_SUPPORTED_THING_TYPES, ENERGY_MANAGEMENT_SUPPORTED_THING_TYPES,
SCENARIO_SUPPORTED_THING_TYPES, SCENARIO_BASIC_SUPPORTED_THING_TYPES, AUX_SUPPORTED_THING_TYPES,
GENERIC_SUPPORTED_THING_TYPES)
ALARM_SUPPORTED_THING_TYPES, GENERIC_SUPPORTED_THING_TYPES)
.flatMap(Collection::stream).collect(Collectors.toCollection(HashSet::new));
public static final Set<ThingTypeUID> BRIDGE_SUPPORTED_THING_TYPES = Set.of(THING_TYPE_ZB_GATEWAY,
THING_TYPE_BUS_GATEWAY);
Expand Down Expand Up @@ -157,6 +166,13 @@ public class OpenWebNetBindingConstants {
public static final String CHANNEL_SCENARIO = "scenario";
// aux
public static final String CHANNEL_AUX = "aux";
// alarm
public static final String CHANNEL_ALARM_SYSTEM_STATE = "state";
public static final String CHANNEL_ALARM_SYSTEM_ARMED = "armed";
public static final String CHANNEL_ALARM_SYSTEM_NETWORK = "network";
public static final String CHANNEL_ALARM_SYSTEM_BATTERY = "battery";
public static final String CHANNEL_ALARM_ZONE_STATE = "state";
public static final String CHANNEL_ALARM_ZONE_ALARM_STATE = "alarm";

// devices config properties
public static final String CONFIG_PROPERTY_WHERE = "where";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetAlarmHandler;
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetAutomationHandler;
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetAuxiliaryHandler;
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetBridgeHandler;
Expand Down Expand Up @@ -83,6 +84,9 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
} else if (OpenWebNetScenarioBasicHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
logger.debug("Creating NEW BASIC SCENARIO Handler");
return new OpenWebNetScenarioBasicHandler(thing);
} else if (OpenWebNetAlarmHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
logger.debug("creating NEW ALARM Handler");
return new OpenWebNetAlarmHandler(thing);
}
logger.warn("ThingType {} is not supported by this binding", thing.getThingTypeUID());
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openwebnet4j.OpenDeviceType;
import org.openwebnet4j.message.BaseOpenMessage;
import org.openwebnet4j.message.Where;
import org.openwebnet4j.message.WhereAlarm;
import org.openwebnet4j.message.WhereThermo;
import org.openwebnet4j.message.WhereZigBee;
import org.openwebnet4j.message.Who;
Expand Down Expand Up @@ -95,7 +96,8 @@ public void abortScan() {
* @param message the OWN message received that identified the device
* (optional)
*/
public void newDiscoveryResult(Where where, OpenDeviceType deviceType, @Nullable BaseOpenMessage baseMsg) {
public void newDiscoveryResult(@Nullable Where where, OpenDeviceType deviceType,
@Nullable BaseOpenMessage baseMsg) {
logger.debug("newDiscoveryResult() WHERE={}, deviceType={}", where, deviceType);
ThingTypeUID thingTypeUID = OpenWebNetBindingConstants.THING_TYPE_GENERIC_DEVICE; // generic device
String thingLabel = OpenWebNetBindingConstants.THING_LABEL_GENERIC_DEVICE;
Expand Down Expand Up @@ -189,6 +191,18 @@ public void newDiscoveryResult(Where where, OpenDeviceType deviceType, @Nullable
deviceWho = Who.AUX;
break;
}
case SCS_ALARM_CENTRAL_UNIT: {
thingTypeUID = OpenWebNetBindingConstants.THING_TYPE_BUS_ALARM_SYSTEM;
thingLabel = OpenWebNetBindingConstants.THING_LABEL_BUS_ALARM_SYSTEM;
deviceWho = Who.BURGLAR_ALARM;
break;
}
case SCS_ALARM_ZONE: {
thingTypeUID = OpenWebNetBindingConstants.THING_TYPE_BUS_ALARM_ZONE;
thingLabel = OpenWebNetBindingConstants.THING_LABEL_BUS_ALARM_ZONE;
deviceWho = Who.BURGLAR_ALARM;
break;
}
default:
logger.warn("Device type {} is not supported, default to GENERIC device (WHERE={})", deviceType, where);
if (where instanceof WhereZigBee) {
Expand All @@ -198,35 +212,46 @@ public void newDiscoveryResult(Where where, OpenDeviceType deviceType, @Nullable
deviceWho = baseMsg.getWho();
}
}
Where w;
if (where != null) {
w = where;
} else if (OpenWebNetBindingConstants.THING_TYPE_BUS_ALARM_SYSTEM.equals(thingTypeUID)) {
w = new WhereAlarm("0");
} else {
logger.debug("ignoring newDiscoveryResult with null where: {}", baseMsg);
return;
}

String ownId = bridgeHandler.ownIdFromWhoWhere(deviceWho, where);
String ownId = bridgeHandler.ownIdFromWhoWhere(deviceWho, w);
if (OpenWebNetBindingConstants.THING_TYPE_BUS_ON_OFF_SWITCH.equals(thingTypeUID)) {
if (bridgeHandler.getRegisteredDevice(ownId) != null) {
logger.debug("dimmer/switch with WHERE={} already registered, skipping this discovery result", where);
logger.debug("dimmer/switch with WHERE={} already registered, skipping this discovery result", w);
return;
}
}

String tId = bridgeHandler.thingIdFromWhere(where);
String tId = bridgeHandler.thingIdFromWhere(w);
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, tId);

DiscoveryResult discoveryResult = null;

String whereConfig = where.value();
String whereConfig = w.value();

// remove # from discovered thermo zone or central unit
// remove # from discovered thermo zone/central unit or alarm zone
if (OpenWebNetBindingConstants.THING_TYPE_BUS_THERMO_ZONE.equals(thingTypeUID)
|| OpenWebNetBindingConstants.THING_TYPE_BUS_THERMO_CU.equals(thingTypeUID)) {
whereConfig = "" + ((WhereThermo) where).getZone();
} else if (OpenWebNetBindingConstants.THING_TYPE_BUS_ALARM_ZONE.equals(thingTypeUID)) {
whereConfig = "" + ((WhereAlarm) where).getZone();
}
if (where instanceof WhereZigBee && WhereZigBee.UNIT_02.equals(((WhereZigBee) where).getUnit())) {
if (w instanceof WhereZigBee && WhereZigBee.UNIT_02.equals(((WhereZigBee) where).getUnit())) {
logger.debug("UNIT=02 found (WHERE={}) -> will remove previous result if exists", where);
thingRemoved(thingUID); // remove previously discovered thing
// re-create thingUID with new type
thingTypeUID = OpenWebNetBindingConstants.THING_TYPE_ZB_ON_OFF_SWITCH_2UNITS;
thingLabel = OpenWebNetBindingConstants.THING_LABEL_ZB_ON_OFF_SWITCH_2UNITS;
thingUID = new ThingUID(thingTypeUID, bridgeUID, tId);
whereConfig = ((WhereZigBee) where).valueWithUnit(WhereZigBee.UNIT_ALL); // replace unit '02' with '00'
whereConfig = ((WhereZigBee) w).valueWithUnit(WhereZigBee.UNIT_ALL); // replace unit '02' with '00'
logger.debug("UNIT=02, switching type from {} to {}",
OpenWebNetBindingConstants.THING_TYPE_ZB_ON_OFF_SWITCH,
OpenWebNetBindingConstants.THING_TYPE_ZB_ON_OFF_SWITCH_2UNITS);
Expand Down
Loading

0 comments on commit 5697754

Please sign in to comment.