Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[openwebnet] add support for Basic Scenarios (WHO=0) #12847

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 48 additions & 34 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.8.1</version>
<version>0.9.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public class OpenWebNetBindingConstants {
public static final ThingTypeUID THING_TYPE_BUS_CENPLUS_SCENARIO_CONTROL = new ThingTypeUID(BINDING_ID,
"bus_cenplus_scenario_control");
public static final String THING_LABEL_BUS_CENPLUS_SCENARIO_CONTROL = "CEN+ Control";

public static final ThingTypeUID THING_TYPE_BUS_SCENARIO_PANEL = new ThingTypeUID(BINDING_ID, "bus_scenario_panel");
public static final String THING_LABEL_BUS_SCENARIO_PANEL = "Scenario Control Panel";
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 @@ -102,14 +103,16 @@ 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);

// ## Basic Scenario
public static final Set<ThingTypeUID> SCENARIO_BASIC_SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BUS_SCENARIO_PANEL);
// ## 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, AUX_SUPPORTED_THING_TYPES)
SCENARIO_SUPPORTED_THING_TYPES, SCENARIO_BASIC_SUPPORTED_THING_TYPES, AUX_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 @@ -143,16 +146,16 @@ public class OpenWebNetBindingConstants {
public static final String CHANNEL_CU_AT_LEAST_ONE_PROBE_OFF = "atLeastOneProbeOff";
public static final String CHANNEL_CU_AT_LEAST_ONE_PROBE_PROTECTION = "atLeastOneProbeProtection";
public static final String CHANNEL_CU_AT_LEAST_ONE_PROBE_MANUAL = "atLeastOneProbeManual";

// energy management
public static final String CHANNEL_POWER = "power";
// scenario button channels
public static final String CHANNEL_SCENARIO_BUTTON = "button#";
public static final String CHANNEL_TYPE_CEN_BUTTON_EVENT = "cenButtonEvent";
public static final String CHANNEL_TYPE_CEN_PLUS_BUTTON_EVENT = "cenPlusButtonEvent";
public static final String CHANNEL_DRY_CONTACT_IR = "sensor";

// Aux
// basic scenario
public static final String CHANNEL_SCENARIO = "scenario";
// aux
public static final String CHANNEL_AUX = "aux";

// devices config properties
Expand All @@ -170,4 +173,5 @@ public class OpenWebNetBindingConstants {
public static final String PROPERTY_FIRMWARE_VERSION = "firmwareVersion";
public static final String PROPERTY_MODEL = "model";
public static final String PROPERTY_SERIAL_NO = "serialNumber";

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetEnergyHandler;
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetGenericHandler;
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetLightingHandler;
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetScenarioBasicHandler;
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetScenarioHandler;
import org.openhab.binding.openwebnet.internal.handler.OpenWebNetThermoregulationHandler;
import org.openhab.core.thing.Bridge;
Expand Down Expand Up @@ -79,6 +80,9 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
} else if (OpenWebNetAuxiliaryHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
logger.debug("Creating NEW AUXILIARY Handler");
return new OpenWebNetAuxiliaryHandler(thing);
} else if (OpenWebNetScenarioBasicHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
logger.debug("Creating NEW SCENARIO BASIC Handler");
return new OpenWebNetScenarioBasicHandler(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 @@ -156,6 +156,12 @@ public void newDiscoveryResult(Where where, OpenDeviceType deviceType, @Nullable
deviceWho = Who.ENERGY_MANAGEMENT;
break;
}
case BASIC_SCENARIO: {
thingTypeUID = OpenWebNetBindingConstants.THING_TYPE_BUS_SCENARIO_PANEL;
thingLabel = OpenWebNetBindingConstants.THING_LABEL_BUS_SCENARIO_PANEL;
deviceWho = Who.SCENARIO;
break;
}
case SCENARIO_CONTROL: {
thingTypeUID = OpenWebNetBindingConstants.THING_TYPE_BUS_CEN_SCENARIO_CONTROL;
thingLabel = OpenWebNetBindingConstants.THING_LABEL_BUS_CEN_SCENARIO_CONTROL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.openwebnet4j.message.GatewayMgmt;
import org.openwebnet4j.message.Lighting;
import org.openwebnet4j.message.OpenMessage;
import org.openwebnet4j.message.Scenario;
import org.openwebnet4j.message.Thermoregulation;
import org.openwebnet4j.message.What;
import org.openwebnet4j.message.Where;
Expand All @@ -68,9 +69,10 @@
/**
* The {@link OpenWebNetBridgeHandler} is responsible for handling communication with gateways and handling events.
*
* @author Massimo Valla - Initial contribution
* @author Massimo Valla - Initial contribution, Lighting, Automation, Scenario
* @author Andrea Conte - Energy management, Thermoregulation
* @author Gilberto Cocchi - Thermoregulation
* @author Giovanni Fabiani - Aux
*/
@NonNullByDefault
public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implements GatewayListener {
Expand Down Expand Up @@ -326,7 +328,7 @@ private void discoverByActivation(BaseOpenMessage baseMsg) {
}
// we support these types only
if (baseMsg instanceof Lighting || baseMsg instanceof Automation || baseMsg instanceof EnergyManagement
|| baseMsg instanceof Thermoregulation || baseMsg instanceof CEN) {
|| baseMsg instanceof Thermoregulation || baseMsg instanceof CEN || baseMsg instanceof Scenario) {
BaseOpenMessage bmsg = baseMsg;
if (baseMsg instanceof Lighting) {
What what = baseMsg.getWhat();
Expand Down Expand Up @@ -498,7 +500,8 @@ public void onEventMessage(@Nullable OpenMessage msg) {
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 Auxiliary) {
|| baseMsg instanceof Thermoregulation || baseMsg instanceof CEN || baseMsg instanceof Auxiliary
|| baseMsg instanceof Scenario) {
String ownId = ownIdFromMessage(baseMsg);
logger.debug("ownIdFromMessage({}) --> {}", baseMsg, ownId);
OpenWebNetThingHandler deviceHandler = registeredDevices.get(ownId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* 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 java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.types.Command;
import org.openwebnet4j.message.BaseOpenMessage;
import org.openwebnet4j.message.Scenario.WhatScenario;
import org.openwebnet4j.message.Where;
import org.openwebnet4j.message.WhereLightAutom;
import org.openwebnet4j.message.Who;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link OpenWebNetScenarioBasicHandler} is responsible for handling Basic Scenario (WHO=0) messages.
* It extends the abstract {@link OpenWebNetThingHandler}.
*
* @author Massimo Valla - Initial contribution
*/
@NonNullByDefault
public class OpenWebNetScenarioBasicHandler extends OpenWebNetThingHandler {

private final Logger logger = LoggerFactory.getLogger(OpenWebNetScenarioBasicHandler.class);

public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.SCENARIO_BASIC_SUPPORTED_THING_TYPES;

public OpenWebNetScenarioBasicHandler(Thing thing) {
super(thing);
logger.debug("created Scenario Panel device for thing: {}", getThing().getUID());
}

@Override
protected String ownIdPrefix() {
return Who.SCENARIO.value().toString();
}

@Override
protected void handleMessage(BaseOpenMessage msg) {
super.handleMessage(msg);
if (msg.isCommand()) {
WhatScenario scenario = (WhatScenario) msg.getWhat();
if (scenario == null) {
logger.warn("Invalid Basic Scenario: {}. Ignoring message {}", scenario, msg);
return;
}
logger.info("Basic Scenario {} has been activated", scenario);
triggerChannel(OpenWebNetBindingConstants.CHANNEL_SCENARIO, scenario.toString());
} else {
logger.debug("handleMessage() Ignoring unsupported DIM for thing {}. Frame={}", getThing().getUID(), msg);
}
}

@Override
protected void handleChannelCommand(ChannelUID channel, Command command) {
// TODO not supported yet
logger.info("Activation of Basic Scenario (WHO=0) is not supported yet. Ignoring command {} for channel {}",
command, channel);
}

@Override
protected void requestChannelState(ChannelUID channel) {
logger.debug("requestChannelState() Basic Scenario channels are trigger channels and do not have state.");
}

@Override
protected void refreshDevice(boolean refreshAll) {
logger.debug("Basic Scenario channels are trigger channels and do not have state.");
}

@Override
protected Where buildBusWhere(String wStr) throws IllegalArgumentException {
return new WhereLightAutom(wStr);
}
}
Original file line number Diff line number Diff line change
@@ -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 Basic Scenario Panels -->
<thing-type id="bus_scenario_panel">
<supported-bridge-type-refs>
<bridge-type-ref id="bus_gateway"/>
</supported-bridge-type-refs>

<label>Basic Scenario Panel</label>
<description>A OpenWebNet BUS/SCS Basic Scenario Panel</description>

<channels>
<channel id="scenario" typeId="scenarioEvent"/>
</channels>

<properties>
<property name="vendor">BTicino/Legrand</property>
<property name="ownDeviceType">3</property>
</properties>

<representation-property>ownId</representation-property>

<config-description>
<parameter name="where" type="text" required="true">
<label>OpenWebNet Address (where)</label>
<description>Example: Control Panel 02 --> where=02. On local bus: where=02#4#01</description>
</parameter>
</config-description>

</thing-type>
</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,36 @@
<state readOnly="true" pattern="%.0f %unit%"></state>
</channel-type>

<!-- Basic Scenario trigger channels -->
<channel-type id="scenarioEvent">
<kind>trigger</kind>
<label>Basic Scenario Event</label>
<event>
<options>
<option value="SCENARIO_01">Scenario 1</option>
<option value="SCENARIO_02">Scenario 2</option>
<option value="SCENARIO_03">Scenario 3</option>
<option value="SCENARIO_04">Scenario 4</option>
<option value="SCENARIO_05">Scenario 5</option>
<option value="SCENARIO_06">Scenario 6</option>
<option value="SCENARIO_07">Scenario 7</option>
<option value="SCENARIO_08">Scenario 8</option>
<option value="SCENARIO_09">Scenario 9</option>
<option value="SCENARIO_10">Scenario 10</option>
<option value="SCENARIO_11">Scenario 11</option>
<option value="SCENARIO_12">Scenario 12</option>
<option value="SCENARIO_13">Scenario 13</option>
<option value="SCENARIO_14">Scenario 14</option>
<option value="SCENARIO_15">Scenario 15</option>
<option value="SCENARIO_16">Scenario 16</option>
<option value="SCENARIO_17">Scenario 17</option>
<option value="SCENARIO_18">Scenario 18</option>
<option value="SCENARIO_19">Scenario 19</option>
<option value="SCENARIO_20">Scenario 20</option>
</options>
</event>
</channel-type>

<!-- CEN/CEN+ trigger channels -->
<channel-type id="cenButtonEvent">
<kind>trigger</kind>
Expand Down Expand Up @@ -368,6 +398,7 @@
</event>
</channel-type>

<!-- Dry Contact / IR channel -->
<channel-type id="dryContactIR">
<item-type>Switch</item-type>
<label>Sensor</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* @author Massimo Valla - Initial contribution
* @author Andrea Conte - Energy management
* @author Giovanni Fabiani - AAuxiliary message support
* @author Giovanni Fabiani - Auxiliary message support
*/
@NonNullByDefault
public class OwnIdTest {
Expand All @@ -66,7 +66,8 @@ 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
* BUS AUX 4 4 9.4 4
* BUS Scenario 05 05 0.05 05
*/
// @formatter:on

Expand All @@ -86,7 +87,9 @@ public enum TEST {
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_aux(new WhereAuxiliary("4"), Who.fromValue(9), "*9*1*4##","4","9.4","4");
bus_aux(new WhereAuxiliary("4"), Who.fromValue(9), "*9*1*4##","4","9.4","4"),
bus_scenario(new WhereLightAutom("05"), Who.fromValue(0), "*0*2*05##","05","0.05","05");



// @formatter:on
Expand Down