[openwebnet] Reset zones' alarm state channel when system is armed (#14566)
* [openwebnet] reset zones alarm channel when system is armed and added NONE state * [openwebnet] added Technical reset alarm. Changes after 1st review --------- Signed-off-by: Massimo Valla <mvcode00@gmail.com>
This commit is contained in:
parent
6757a84b6b
commit
cbb72ed72e
|
@ -526,5 +526,6 @@ Special thanks for helping on testing this binding go to:
|
||||||
[@feodor](https://community.openhab.org/u/feodor),
|
[@feodor](https://community.openhab.org/u/feodor),
|
||||||
[@aconte80](https://community.openhab.org/u/aconte80),
|
[@aconte80](https://community.openhab.org/u/aconte80),
|
||||||
[@rubenfuser](https://community.openhab.org/u/rubenfuser),
|
[@rubenfuser](https://community.openhab.org/u/rubenfuser),
|
||||||
[@stamate_viorel](https://community.openhab.org/u/stamate_viorel)
|
[@stamate_viorel](https://community.openhab.org/u/stamate_viorel),
|
||||||
|
[@marchino](https://community.openhab.org/u/marchino)
|
||||||
and many others at the fantastic openHAB community!
|
and many others at the fantastic openHAB community!
|
||||||
|
|
|
@ -172,7 +172,7 @@ public class OpenWebNetBindingConstants {
|
||||||
public static final String CHANNEL_ALARM_SYSTEM_NETWORK = "network";
|
public static final String CHANNEL_ALARM_SYSTEM_NETWORK = "network";
|
||||||
public static final String CHANNEL_ALARM_SYSTEM_BATTERY = "battery";
|
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_STATE = "state";
|
||||||
public static final String CHANNEL_ALARM_ZONE_ALARM_STATE = "alarm";
|
public static final String CHANNEL_ALARM_ZONE_ALARM = "alarm";
|
||||||
|
|
||||||
// devices config properties
|
// devices config properties
|
||||||
public static final String CONFIG_PROPERTY_WHERE = "where";
|
public static final String CONFIG_PROPERTY_WHERE = "where";
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.openhab.binding.openwebnet.internal.handler;
|
||||||
|
|
||||||
import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.*;
|
import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.*;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
@ -52,19 +53,35 @@ public class OpenWebNetAlarmHandler extends OpenWebNetThingHandler {
|
||||||
|
|
||||||
private static long lastAllDevicesRefreshTS = 0; // ts when last all device refresh was sent for this handler
|
private static long lastAllDevicesRefreshTS = 0; // ts when last all device refresh was sent for this handler
|
||||||
|
|
||||||
|
private static Set<OpenWebNetAlarmHandler> zoneHandlers = new HashSet<OpenWebNetAlarmHandler>();
|
||||||
|
|
||||||
private static final String BATTERY_OK = "OK";
|
private static final String BATTERY_OK = "OK";
|
||||||
private static final String BATTERY_FAULT = "FAULT";
|
private static final String BATTERY_FAULT = "FAULT";
|
||||||
private static final String BATTERY_UNLOADED = "UNLOADED";
|
private static final String BATTERY_UNLOADED = "UNLOADED";
|
||||||
|
|
||||||
private static final String SILENT = "SILENT";
|
private static final String ALARM_INTRUSION = "INTRUSION";
|
||||||
private static final String INTRUSION = "INTRUSION";
|
private static final String ALARM_TAMPERING = "TAMPERING";
|
||||||
private static final String ANTI_PANIC = "ANTI_PANIC";
|
private static final String ALARM_ANTI_PANIC = "ANTI_PANIC";
|
||||||
private static final String TAMPERING = "TAMPERING";
|
private static final String ALARM_SILENT = "SILENT";
|
||||||
|
private static final String ALARM_TECHNICAL = "TECHNICAL";
|
||||||
|
private static final String ALARM_TECHNICAL_RESET = "TECHNICAL_RESET";
|
||||||
|
private static final String ALARM_NONE = "NONE";
|
||||||
|
|
||||||
public OpenWebNetAlarmHandler(Thing thing) {
|
public OpenWebNetAlarmHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
super.initialize();
|
||||||
|
if (OpenWebNetBindingConstants.THING_TYPE_BUS_ALARM_ZONE.equals(thing.getThingTypeUID())) {
|
||||||
|
zoneHandlers.add(this);
|
||||||
|
// initially set zone alarm to NONE (it will be set if specific alarm message is
|
||||||
|
// received)
|
||||||
|
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_NONE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleChannelCommand(ChannelUID channel, Command command) {
|
protected void handleChannelCommand(ChannelUID channel, Command command) {
|
||||||
logger.warn("Alarm.handleChannelCommand() Read only channel, unsupported command {}", command);
|
logger.warn("Alarm.handleChannelCommand() Read only channel, unsupported command {}", command);
|
||||||
|
@ -115,7 +132,7 @@ public class OpenWebNetAlarmHandler extends OpenWebNetThingHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMessage(BaseOpenMessage msg) {
|
protected void handleMessage(BaseOpenMessage msg) {
|
||||||
logger.debug("handleMessage({}) for thing: {}", msg, thing.getUID());
|
logger.debug("handleMessage({}) for: {} {}", msg, thing.getUID(), msg.getWhat());
|
||||||
super.handleMessage(msg);
|
super.handleMessage(msg);
|
||||||
ThingTypeUID thingType = thing.getThingTypeUID();
|
ThingTypeUID thingType = thing.getThingTypeUID();
|
||||||
if (THING_TYPE_BUS_ALARM_SYSTEM.equals(thingType)) {
|
if (THING_TYPE_BUS_ALARM_SYSTEM.equals(thingType)) {
|
||||||
|
@ -141,18 +158,20 @@ public class OpenWebNetAlarmHandler extends OpenWebNetThingHandler {
|
||||||
case SYSTEM_ENGAGED:
|
case SYSTEM_ENGAGED:
|
||||||
updateAlarmSystemArmed(w);
|
updateAlarmSystemArmed(w);
|
||||||
break;
|
break;
|
||||||
case SYSTEM_BATTERY_FAULT:
|
|
||||||
case SYSTEM_BATTERY_OK:
|
case SYSTEM_BATTERY_OK:
|
||||||
case SYSTEM_BATTERY_UNLOADED:
|
case SYSTEM_BATTERY_UNLOADED:
|
||||||
|
case SYSTEM_BATTERY_FAULT:
|
||||||
updateBatteryState(w);
|
updateBatteryState(w);
|
||||||
break;
|
break;
|
||||||
case SYSTEM_NETWORK_ERROR:
|
case SYSTEM_NETWORK_ERROR:
|
||||||
case SYSTEM_NETWORK_OK:
|
case SYSTEM_NETWORK_OK:
|
||||||
updateNetworkState(w);
|
updateNetworkState(w);
|
||||||
break;
|
break;
|
||||||
|
case DELAY_END:
|
||||||
|
resetAllZonesAlarmState();
|
||||||
|
break;
|
||||||
case START_PROGRAMMING:
|
case START_PROGRAMMING:
|
||||||
case STOP_PROGRAMMING:
|
case STOP_PROGRAMMING:
|
||||||
case DELAY_END:
|
|
||||||
case NO_CONNECTION_TO_DEVICE:
|
case NO_CONNECTION_TO_DEVICE:
|
||||||
default:
|
default:
|
||||||
logger.debug("Alarm.updateSystem() Ignoring unsupported WHAT {}. Frame={}", msg.getWhat(), msg);
|
logger.debug("Alarm.updateSystem() Ignoring unsupported WHAT {}. Frame={}", msg.getWhat(), msg);
|
||||||
|
@ -196,10 +215,10 @@ public class OpenWebNetAlarmHandler extends OpenWebNetThingHandler {
|
||||||
case ZONE_ALARM_TAMPERING:
|
case ZONE_ALARM_TAMPERING:
|
||||||
case ZONE_ALARM_ANTI_PANIC:
|
case ZONE_ALARM_ANTI_PANIC:
|
||||||
case ZONE_ALARM_SILENT:
|
case ZONE_ALARM_SILENT:
|
||||||
updateZoneAlarmState(w);
|
case ZONE_ALARM_TECHNICAL:
|
||||||
break;
|
|
||||||
case ZONE_ALARM_TECHNICAL:// not handled for now
|
|
||||||
case ZONE_ALARM_TECHNICAL_RESET:
|
case ZONE_ALARM_TECHNICAL_RESET:
|
||||||
|
updateZoneAlarm(w);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
logger.debug("Alarm.updateZone() Ignoring unsupported WHAT {}. Frame={}", msg.getWhat(), msg);
|
logger.debug("Alarm.updateZone() Ignoring unsupported WHAT {}. Frame={}", msg.getWhat(), msg);
|
||||||
}
|
}
|
||||||
|
@ -209,15 +228,35 @@ public class OpenWebNetAlarmHandler extends OpenWebNetThingHandler {
|
||||||
updateState(CHANNEL_ALARM_ZONE_STATE, OnOffType.from(w == Alarm.WhatAlarm.ZONE_ENGAGED));
|
updateState(CHANNEL_ALARM_ZONE_STATE, OnOffType.from(w == Alarm.WhatAlarm.ZONE_ENGAGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateZoneAlarmState(WhatAlarm w) {
|
private void updateZoneAlarm(WhatAlarm w) {
|
||||||
if (w == Alarm.WhatAlarm.ZONE_ALARM_SILENT) {
|
switch (w) {
|
||||||
updateState(CHANNEL_ALARM_ZONE_ALARM_STATE, new StringType(SILENT));
|
case ZONE_ALARM_INTRUSION:
|
||||||
} else if (w == Alarm.WhatAlarm.ZONE_ALARM_INTRUSION) {
|
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_INTRUSION));
|
||||||
updateState(CHANNEL_ALARM_ZONE_ALARM_STATE, new StringType(INTRUSION));
|
break;
|
||||||
} else if (w == Alarm.WhatAlarm.ZONE_ALARM_ANTI_PANIC) {
|
case ZONE_ALARM_TAMPERING:
|
||||||
updateState(CHANNEL_ALARM_ZONE_ALARM_STATE, new StringType(ANTI_PANIC));
|
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TAMPERING));
|
||||||
} else {
|
break;
|
||||||
updateState(CHANNEL_ALARM_ZONE_ALARM_STATE, new StringType(TAMPERING));
|
case ZONE_ALARM_ANTI_PANIC:
|
||||||
|
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_ANTI_PANIC));
|
||||||
|
break;
|
||||||
|
case ZONE_ALARM_SILENT:
|
||||||
|
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_SILENT));
|
||||||
|
break;
|
||||||
|
case ZONE_ALARM_TECHNICAL:
|
||||||
|
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TECHNICAL));
|
||||||
|
break;
|
||||||
|
case ZONE_ALARM_TECHNICAL_RESET:
|
||||||
|
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TECHNICAL_RESET));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_NONE));
|
||||||
|
logger.warn("Alarm.updateZoneAlarm() Ignoring unsupported WHAT {} for zone {}", w, this.deviceWhere);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetAllZonesAlarmState() {
|
||||||
|
for (OpenWebNetAlarmHandler h : zoneHandlers) {
|
||||||
|
h.updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_NONE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,4 +269,13 @@ public class OpenWebNetAlarmHandler extends OpenWebNetThingHandler {
|
||||||
protected String ownIdPrefix() {
|
protected String ownIdPrefix() {
|
||||||
return Who.BURGLAR_ALARM.value().toString();
|
return Who.BURGLAR_ALARM.value().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
if (OpenWebNetBindingConstants.THING_TYPE_BUS_ALARM_ZONE.equals(thing.getThingTypeUID())) {
|
||||||
|
zoneHandlers.remove(this);
|
||||||
|
logger.debug("Alarm.dispose() - removed zone {}", this.deviceWhere);
|
||||||
|
}
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,6 +282,9 @@ channel-type.openwebnet.zoneAlarm.state.option.INTRUSION = Intrusion
|
||||||
channel-type.openwebnet.zoneAlarm.state.option.TAMPERING = Tampering
|
channel-type.openwebnet.zoneAlarm.state.option.TAMPERING = Tampering
|
||||||
channel-type.openwebnet.zoneAlarm.state.option.ANTI_PANIC = Anti Panic
|
channel-type.openwebnet.zoneAlarm.state.option.ANTI_PANIC = Anti Panic
|
||||||
channel-type.openwebnet.zoneAlarm.state.option.SILENT = Silent
|
channel-type.openwebnet.zoneAlarm.state.option.SILENT = Silent
|
||||||
|
channel-type.openwebnet.zoneAlarm.state.option.TECHNICAL = Technical
|
||||||
|
channel-type.openwebnet.zoneAlarm.state.option.TECHNICAL_RESET = Technical Reset
|
||||||
|
channel-type.openwebnet.zoneAlarm.state.option.NONE = None
|
||||||
|
|
||||||
# thing status descriptions
|
# thing status descriptions
|
||||||
|
|
||||||
|
|
|
@ -454,6 +454,9 @@
|
||||||
<option value="TAMPERING">Tampering</option>
|
<option value="TAMPERING">Tampering</option>
|
||||||
<option value="ANTI_PANIC">Anti Panic</option>
|
<option value="ANTI_PANIC">Anti Panic</option>
|
||||||
<option value="SILENT">Silent</option>
|
<option value="SILENT">Silent</option>
|
||||||
|
<option value="TECHNICAL">Technical</option>
|
||||||
|
<option value="TECHNICAL_RESET">Technical Reset</option>
|
||||||
|
<option value="NONE">None</option>
|
||||||
</options>
|
</options>
|
||||||
</state>
|
</state>
|
||||||
</channel-type>
|
</channel-type>
|
||||||
|
|
Loading…
Reference in New Issue