[openwebnet] Add support for sending Auxiliary (AUX) commands/messages to the bus (WHO=9) (#12468)
Signed-off-by: Giovanni Fabiani <fabiani.giovanni@gmail.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import org.openhab.core.thing.ThingTypeUID;
|
||||
* @author Massimo Valla - Initial contribution
|
||||
* @author Gilberto Cocchi - Thermoregulation
|
||||
* @author Andrea Conte - Energy management, Thermoregulation
|
||||
* @author Giovanni Fabiani - Aux support
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
@@ -70,6 +71,8 @@ public class OpenWebNetBindingConstants {
|
||||
"bus_cenplus_scenario_control");
|
||||
public static final String THING_LABEL_BUS_CENPLUS_SCENARIO_CONTROL = "CEN+ Control";
|
||||
|
||||
public static final ThingTypeUID THING_TYPE_BUS_AUX = new ThingTypeUID(BINDING_ID, "bus_aux");
|
||||
public static final String THING_LABEL_BUS_AUX = "Auxiliary";
|
||||
// ZIGBEE
|
||||
public static final ThingTypeUID THING_TYPE_ZB_ON_OFF_SWITCH = new ThingTypeUID(BINDING_ID, "zb_on_off_switch");
|
||||
public static final String THING_LABEL_ZB_ON_OFF_SWITCH = "ZigBee Switch";
|
||||
@@ -99,11 +102,14 @@ public class OpenWebNetBindingConstants {
|
||||
// ## CEN/CEN+ Scenario
|
||||
public static final Set<ThingTypeUID> SCENARIO_SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BUS_CEN_SCENARIO_CONTROL,
|
||||
THING_TYPE_BUS_CENPLUS_SCENARIO_CONTROL, THING_TYPE_BUS_DRY_CONTACT_IR);
|
||||
|
||||
// ## Aux
|
||||
public static final Set<ThingTypeUID> AUX_SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BUS_AUX);
|
||||
// ## 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, GENERIC_SUPPORTED_THING_TYPES)
|
||||
SCENARIO_SUPPORTED_THING_TYPES, GENERIC_SUPPORTED_THING_TYPES, AUX_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);
|
||||
@@ -146,6 +152,9 @@ public class OpenWebNetBindingConstants {
|
||||
public static final String CHANNEL_TYPE_CEN_PLUS_BUTTON_EVENT = "cenPlusButtonEvent";
|
||||
public static final String CHANNEL_DRY_CONTACT_IR = "sensor";
|
||||
|
||||
// Aux
|
||||
public static final String CHANNEL_AUX = "aux";
|
||||
|
||||
// devices config properties
|
||||
public static final String CONFIG_PROPERTY_WHERE = "where";
|
||||
public static final String CONFIG_PROPERTY_SHUTTER_RUN = "shutterRun";
|
||||
|
||||
@@ -17,6 +17,7 @@ import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetAutomationHandler;
|
||||
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetAuxiliaryHandler;
|
||||
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetBridgeHandler;
|
||||
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetEnergyHandler;
|
||||
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetGenericHandler;
|
||||
@@ -39,6 +40,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Massimo Valla - Initial contribution
|
||||
* @author Andrea Conte - Energy management, Thermoregulation
|
||||
* @author Gilberto Cocchi - Thermoregulation
|
||||
* @author Giovanni Fabiani - Auxiliary support
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(configurationPid = "binding.openwebnet", service = ThingHandlerFactory.class)
|
||||
@@ -74,6 +76,9 @@ public class OpenWebNetHandlerFactory extends BaseThingHandlerFactory {
|
||||
} else if (OpenWebNetScenarioHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
|
||||
logger.debug("creating NEW SCENARIO Handler --- {}", thing.getUID());
|
||||
return new OpenWebNetScenarioHandler(thing);
|
||||
} else if (OpenWebNetAuxiliaryHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
|
||||
logger.debug("Creating NEW AUXILIARY Handler");
|
||||
return new OpenWebNetAuxiliaryHandler(thing);
|
||||
}
|
||||
logger.warn("ThingType {} is not supported by this binding", thing.getThingTypeUID());
|
||||
return null;
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Massimo Valla - Initial contribution
|
||||
* @author Andrea Conte - Energy management, Thermoregulation
|
||||
* @author Gilberto Cocchi - Thermoregulation
|
||||
* @author Giovanni Fabiani - Aux support
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class OpenWebNetDeviceDiscoveryService extends AbstractDiscoveryService
|
||||
@@ -173,6 +174,12 @@ public class OpenWebNetDeviceDiscoveryService extends AbstractDiscoveryService
|
||||
deviceWho = Who.CEN_PLUS_SCENARIO_SCHEDULER;
|
||||
break;
|
||||
}
|
||||
case SCS_AUXILIARY_TOGGLE_CONTROL: {
|
||||
thingTypeUID = OpenWebNetBindingConstants.THING_TYPE_BUS_AUX;
|
||||
thingLabel = OpenWebNetBindingConstants.THING_LABEL_BUS_AUX;
|
||||
deviceWho = Who.AUX;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
logger.warn("Device type {} is not supported, default to GENERIC device (WHERE={})", deviceType, where);
|
||||
if (where instanceof WhereZigBee) {
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2022 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.openwebnet.internal.handler;
|
||||
|
||||
import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_AUX;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
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.ThingTypeUID;
|
||||
import org.openhab.core.types.Command;
|
||||
import org.openwebnet4j.communication.OWNException;
|
||||
import org.openwebnet4j.message.Auxiliary;
|
||||
import org.openwebnet4j.message.BaseOpenMessage;
|
||||
import org.openwebnet4j.message.MalformedFrameException;
|
||||
import org.openwebnet4j.message.OpenMessage;
|
||||
import org.openwebnet4j.message.UnsupportedFrameException;
|
||||
import org.openwebnet4j.message.Where;
|
||||
import org.openwebnet4j.message.WhereAuxiliary;
|
||||
import org.openwebnet4j.message.Who;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The {@link OpenWebNetAuxiliaryHandler} is responsible for sending Auxiliary (AUX) commands/messages to the bus
|
||||
* It extends the abstract {@link OpenWebNetThingHandler}.
|
||||
*
|
||||
* NOTICE: Support for handling messages from the bus regarding alarm control has to be implemented
|
||||
*
|
||||
* @author Giovanni Fabiani - Initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class OpenWebNetAuxiliaryHandler extends OpenWebNetThingHandler {
|
||||
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.AUX_SUPPORTED_THING_TYPES;
|
||||
private final Logger logger = LoggerFactory.getLogger(OpenWebNetAuxiliaryHandler.class);
|
||||
|
||||
public OpenWebNetAuxiliaryHandler(Thing thing) {
|
||||
super(thing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles Auxiliary command for a channel
|
||||
*
|
||||
* @param channel the channel
|
||||
* @param command the Command
|
||||
*/
|
||||
@Override
|
||||
protected void handleChannelCommand(ChannelUID channel, Command command) {
|
||||
logger.debug("handleAuxiliaryCommand() (command={} - channel={})", command, channel);
|
||||
Where w = deviceWhere;
|
||||
if (w != null) {
|
||||
if (channel.getId().equals(CHANNEL_AUX)) {
|
||||
if (command instanceof StringType) {
|
||||
try {
|
||||
if (command.toString().equals(Auxiliary.WhatAuxiliary.ON.name())) {
|
||||
send(Auxiliary.requestTurnOn(w.value()));
|
||||
} else if (command.toString().equals(Auxiliary.WhatAuxiliary.OFF.name())) {
|
||||
send(Auxiliary.requestTurnOff(w.value()));
|
||||
}
|
||||
} catch (OWNException e) {
|
||||
logger.debug("Exception while processing command {}: {}", command, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
logger.debug("Unsupported command {} for channel {}", command, channel);
|
||||
}
|
||||
} else {
|
||||
logger.debug("Unsupported ChannelUID {}", channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void requestChannelState(ChannelUID channel) {
|
||||
/*
|
||||
* NOTICE: It is not possible to get the state of a
|
||||
* WHO=9 command. To get state of the Alarm system use WHO=5 instead
|
||||
*/
|
||||
|
||||
super.requestChannelState(channel);
|
||||
Where w = deviceWhere;
|
||||
if (w != null) {
|
||||
try {
|
||||
OpenMessage msg = BaseOpenMessage.parse("*#9##");
|
||||
// initializing
|
||||
send(msg);
|
||||
} catch (MalformedFrameException | UnsupportedFrameException | OWNException e) {
|
||||
logger.debug("Exception while processing command: {}", e.getMessage());
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshDevice(boolean refreshAll) {
|
||||
/*
|
||||
* NOTICE: It is not possible to refresh the state of a
|
||||
* WHO=9 command. To refresh the state of the Alarm system use WHO=5 instead
|
||||
*/
|
||||
|
||||
logger.debug("--- refreshDevice() : refreshing SINGLE... ({})", thing.getUID());
|
||||
requestChannelState(new ChannelUID(thing.getUID(), CHANNEL_AUX));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Where buildBusWhere(String wStr) throws IllegalArgumentException {
|
||||
return new WhereAuxiliary(wStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String ownIdPrefix() {
|
||||
return Who.AUX.value().toString();
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ import org.openwebnet4j.USBGateway;
|
||||
import org.openwebnet4j.communication.OWNAuthException;
|
||||
import org.openwebnet4j.communication.OWNException;
|
||||
import org.openwebnet4j.message.Automation;
|
||||
import org.openwebnet4j.message.Auxiliary;
|
||||
import org.openwebnet4j.message.BaseOpenMessage;
|
||||
import org.openwebnet4j.message.CEN;
|
||||
import org.openwebnet4j.message.EnergyManagement;
|
||||
@@ -497,7 +498,7 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
|
||||
BaseOpenMessage baseMsg = (BaseOpenMessage) msg;
|
||||
// let's try to get the Thing associated with this message...
|
||||
if (baseMsg instanceof Lighting || baseMsg instanceof Automation || baseMsg instanceof EnergyManagement
|
||||
|| baseMsg instanceof Thermoregulation || baseMsg instanceof CEN) {
|
||||
|| baseMsg instanceof Thermoregulation || baseMsg instanceof CEN || baseMsg instanceof Auxiliary) {
|
||||
String ownId = ownIdFromMessage(baseMsg);
|
||||
logger.debug("ownIdFromMessage({}) --> {}", baseMsg, ownId);
|
||||
OpenWebNetThingHandler deviceHandler = registeredDevices.get(ownId);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<thing:thing-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0" bindingId="openwebnet"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
|
||||
|
||||
<!-- Thing for BUS Auxiliary commands -->
|
||||
<thing-type id="bus_aux">
|
||||
<supported-bridge-type-refs>
|
||||
<bridge-type-ref id="bus_gateway"/>
|
||||
</supported-bridge-type-refs>
|
||||
|
||||
<label>Auxiliary</label>
|
||||
<description>A OpenWebNet BUS/SCS Auxiliary command</description>
|
||||
|
||||
<channels>
|
||||
<channel id="aux" typeId="aux"/>
|
||||
</channels>
|
||||
|
||||
<properties>
|
||||
<property name="vendor">BTicino/Legrand</property>
|
||||
<property name="ownDeviceType">272</property>
|
||||
</properties>
|
||||
|
||||
<representation-property>ownId</representation-property>
|
||||
|
||||
<config-description>
|
||||
<parameter name="where" type="text" required="true">
|
||||
<label>OpenWebNet Address (where)</label>
|
||||
<description>Example: Where=1</description>
|
||||
</parameter>
|
||||
</config-description>
|
||||
|
||||
</thing-type>
|
||||
</thing:thing-descriptions>
|
||||
@@ -16,6 +16,29 @@
|
||||
</tags>
|
||||
</channel-type>
|
||||
|
||||
<!-- Aux channel -->
|
||||
<!--Only ON and OFF options are supported -->
|
||||
<channel-type id="aux">
|
||||
<item-type>String</item-type>
|
||||
<label>Auxiliary</label>
|
||||
<description>Controls an Auxiliary command (read/write)</description>
|
||||
<state>
|
||||
<options>
|
||||
<option value="OFF">Off</option>
|
||||
<option value="ON">On</option>
|
||||
<option value="TOGGLE">Toggle</option>
|
||||
<option value="STOP">Stop</option>
|
||||
<option value="UP">Up</option>
|
||||
<option value="DOWN">Down</option>
|
||||
<option value="ENABLED">Enabled</option>
|
||||
<option value="DISABLED">Disabled</option>
|
||||
<option value="RESET_GEN">Reset gen</option>
|
||||
<option value="RESET_BI">Reset bi</option>
|
||||
<option value="RESET_TRI">Reset tri</option>
|
||||
</options>
|
||||
</state>
|
||||
</channel-type>
|
||||
|
||||
<!-- Brightness Channel -->
|
||||
<channel-type id="brightness">
|
||||
<item-type>Dimmer</item-type>
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.openhab.core.thing.Bridge;
|
||||
import org.openwebnet4j.message.BaseOpenMessage;
|
||||
import org.openwebnet4j.message.FrameException;
|
||||
import org.openwebnet4j.message.Where;
|
||||
import org.openwebnet4j.message.WhereAuxiliary;
|
||||
import org.openwebnet4j.message.WhereCEN;
|
||||
import org.openwebnet4j.message.WhereEnergyManagement;
|
||||
import org.openwebnet4j.message.WhereLightAutom;
|
||||
@@ -38,6 +39,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Massimo Valla - Initial contribution
|
||||
* @author Andrea Conte - Energy management
|
||||
* @author Giovanni Fabiani - AAuxiliary message support
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class OwnIdTest {
|
||||
@@ -64,7 +66,7 @@ public class OwnIdTest {
|
||||
* BUS CEN 51 51 15.51 51
|
||||
* BUS CEN+ 212 212 25.212 212
|
||||
* BUS DryContact 399 399 25.399 399
|
||||
*
|
||||
* BUS AUX 4 4 9.4 4
|
||||
*/
|
||||
// @formatter:on
|
||||
|
||||
@@ -83,7 +85,9 @@ public class OwnIdTest {
|
||||
bus_energy(new WhereEnergyManagement("51"), Who.fromValue(18), "*#18*51*113##", "51", "18.51", "51"),
|
||||
bus_cen(new WhereCEN("51"), Who.fromValue(15), "*15*31*51##", "51", "15.51", "51"),
|
||||
bus_cen_plus(new WhereCEN("212"), Who.fromValue(25), "*25*21#31*212##", "212", "25.212", "212"),
|
||||
bus_drycontact(new WhereCEN("399"), Who.fromValue(25), "*25*32#1*399##", "399", "25.399", "399");
|
||||
bus_drycontact(new WhereCEN("399"), Who.fromValue(25), "*25*32#1*399##", "399", "25.399", "399"),
|
||||
bus_aux(new WhereAuxiliary("4"), Who.fromValue(9), "*9*1*4##","4","9.4","4");
|
||||
|
||||
|
||||
// @formatter:on
|
||||
|
||||
|
||||
Reference in New Issue
Block a user