From 3c4e650547ab3703386ca9b65d1584f7096e33c6 Mon Sep 17 00:00:00 2001 From: Ondrej Pecta Date: Fri, 16 Apr 2021 21:53:24 +0200 Subject: [PATCH] [somfytahoma] added support for the Bioclimatic Pergola thing (#10498) * [somfytahoma] added support for the Bioclimatic Pergola thing Signed-off-by: Ondrej Pecta * Update bundles/org.openhab.binding.somfytahoma/README.md Signed-off-by: Fabian Wolter Co-authored-by: Fabian Wolter --- .../org.openhab.binding.somfytahoma/README.md | 4 +- .../internal/SomfyTahomaBindingConstants.java | 17 +++- .../internal/SomfyTahomaHandlerFactory.java | 3 + .../SomfyTahomaItemDiscoveryService.java | 7 +- .../SomfyTahomaBioclimaticPergolaHandler.java | 77 +++++++++++++++++++ .../OH-INF/thing/bioclimaticpergola.xml | 21 +++++ .../main/resources/OH-INF/thing/channels.xml | 20 +++++ 7 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBioclimaticPergolaHandler.java create mode 100644 bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/bioclimaticpergola.xml diff --git a/bundles/org.openhab.binding.somfytahoma/README.md b/bundles/org.openhab.binding.somfytahoma/README.md index 1613c6e9e..bb2536fec 100644 --- a/bundles/org.openhab.binding.somfytahoma/README.md +++ b/bundles/org.openhab.binding.somfytahoma/README.md @@ -69,9 +69,11 @@ Please see the example below. | roller shutter, screen, venetian blind, garage door, awning, pergola, curtain | control | device controller which reacts to commands UP/DOWN/ON/OFF/OPEN/CLOSE/MY/STOP + closure 0-100 | | window | control | device controller which reacts to commands UP/DOWN/ON/OFF/OPEN/CLOSE/STOP + closure 0-100 | | silent roller shutter | silent_control | similar to control channel but in silent mode | -| venetian blind, adjustable slats roller shutter | orientation | percentual orientation of the blind's slats, it can have value 0-100. For IO Homecontrol devices only (non RTS) | +| venetian blind, adjustable slats roller shutter, bioclimatic pergola | orientation | percentual orientation of the blind's slats, it can have value 0-100. For IO Homecontrol devices only (non RTS) | | venetian blind, adjustable slats roller shutter | closure_orientation | percentual closure and orientation of the blind's slats, it can have value 0-100. For IO Homecontrol devices only (non RTS) | | adjustable slats roller shutter | rocker | used for setting the rocker position of the roller shutter, the only position allowing the slats control | +| bioclimatic pergola | slats | slats state (open/closed) | +| bioclimatic pergola | pergola_command | used for controlling biclimatic pergola (closeSlats, openSlats, stop) | | action group | execute_action | switch which reacts to ON command and triggers the predefined Tahoma action | | onoff, light | switch | reacts to standard ON/OFF commands | | dimmer light | light_intensity | sets/gets intensity of the dimmer light or ON/OFF | diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaBindingConstants.java b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaBindingConstants.java index 87345342c..5e5fe9561 100644 --- a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaBindingConstants.java +++ b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaBindingConstants.java @@ -124,6 +124,10 @@ public class SomfyTahomaBindingConstants { // Pergola public static final ThingTypeUID THING_TYPE_PERGOLA = new ThingTypeUID(BINDING_ID, "pergola"); + // Bioclimatic Pergola + public static final ThingTypeUID THING_TYPE_BIOCLIMATIC_PERGOLA = new ThingTypeUID(BINDING_ID, + "bioclimaticpergola"); + // Window handle public static final ThingTypeUID THING_TYPE_WINDOW_HANDLE = new ThingTypeUID(BINDING_ID, "windowhandle"); @@ -171,8 +175,14 @@ public class SomfyTahomaBindingConstants { // Silent roller shutter public static final String CONTROL_SILENT = "control_silent"; - // Blind + // Bioclimatic Pergola + public static final String SLATS = "slats"; + public static final String PERGOLA_COMMAND = "pergola_command"; + + // Blind, Bioclimatic Pergola public static final String ORIENTATION = "orientation"; + + // Blind public static final String CLOSURE_AND_ORIENTATION = "closure_orientation"; // Action group @@ -306,6 +316,8 @@ public class SomfyTahomaBindingConstants { public static final String COMMAND_DOWN = "down"; public static final String COMMAND_OPEN = "open"; public static final String COMMAND_CLOSE = "close"; + public static final String COMMAND_OPEN_SLATS = "openSlats"; + public static final String COMMAND_CLOSE_SLATS = "closeSlats"; public static final String COMMAND_STOP = "stop"; public static final String COMMAND_OFF = "off"; public static final String COMMAND_CHECK_TRIGGER = "checkEventTrigger"; @@ -385,7 +397,8 @@ public class SomfyTahomaBindingConstants { THING_TYPE_GATE, THING_TYPE_CURTAIN, THING_TYPE_ELECTRICITYSENSOR, THING_TYPE_DOCK, THING_TYPE_SIREN, THING_TYPE_ADJUSTABLE_SLATS_ROLLERSHUTTER, THING_TYPE_MYFOX_CAMERA, THING_TYPE_ROLLERSHUTTER_UNO, THING_TYPE_WATERSENSOR, THING_TYPE_HUMIDITYSENSOR, THING_TYPE_MYFOX_ALARM, THING_TYPE_THERMOSTAT, - THING_TYPE_DIMMER_LIGHT, THING_TYPE_EXTERIOR_HEATING_SYSTEM, THING_TYPE_VALVE_HEATING_SYSTEM)); + THING_TYPE_DIMMER_LIGHT, THING_TYPE_EXTERIOR_HEATING_SYSTEM, THING_TYPE_VALVE_HEATING_SYSTEM, + THING_TYPE_BIOCLIMATIC_PERGOLA)); // somfy gateways public static Map gatewayTypes = new HashMap() { diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaHandlerFactory.java b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaHandlerFactory.java index bf6c40bbd..85e2a80df 100644 --- a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaHandlerFactory.java +++ b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaHandlerFactory.java @@ -19,6 +19,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaActionGroupHandler; import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaAdjustableSlatsRollerShutterHandler; import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaAwningHandler; +import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaBioclimaticPergolaHandler; import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaBridgeHandler; import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaContactSensorHandler; import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaCurtainHandler; @@ -159,6 +160,8 @@ public class SomfyTahomaHandlerFactory extends BaseThingHandlerFactory { return new SomfyTahomaDoorLockHandler(thing); } else if (thingTypeUID.equals(THING_TYPE_PERGOLA)) { return new SomfyTahomaPergolaHandler(thing); + } else if (thingTypeUID.equals(THING_TYPE_BIOCLIMATIC_PERGOLA)) { + return new SomfyTahomaBioclimaticPergolaHandler(thing); } else if (thingTypeUID.equals(THING_TYPE_WINDOW_HANDLE)) { return new SomfyTahomaWindowHandleHandler(thing); } else if (thingTypeUID.equals(THING_TYPE_TEMPERATURESENSOR)) { diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/discovery/SomfyTahomaItemDiscoveryService.java b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/discovery/SomfyTahomaItemDiscoveryService.java index 29b3b66c6..41d03fc40 100644 --- a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/discovery/SomfyTahomaItemDiscoveryService.java +++ b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/discovery/SomfyTahomaItemDiscoveryService.java @@ -275,7 +275,12 @@ public class SomfyTahomaItemDiscoveryService extends AbstractDiscoveryService deviceDiscovered(device, THING_TYPE_DOOR_LOCK, place); break; case CLASS_PERGOLA: - deviceDiscovered(device, THING_TYPE_PERGOLA, place); + if ("BioclimaticPergola".equals(device.getWidget())) { + // widget: BioclimaticPergola + deviceDiscovered(device, THING_TYPE_BIOCLIMATIC_PERGOLA, place); + } else { + deviceDiscovered(device, THING_TYPE_PERGOLA, place); + } break; case CLASS_WINDOW_HANDLE: // widget: ThreeWayWindowHandle diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBioclimaticPergolaHandler.java b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBioclimaticPergolaHandler.java new file mode 100644 index 000000000..2bb4a35b2 --- /dev/null +++ b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBioclimaticPergolaHandler.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2010-2021 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.somfytahoma.internal.handler; + +import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.Thing; +import org.openhab.core.types.Command; +import org.openhab.core.types.RefreshType; + +/** + * The {@link SomfyTahomaBioclimaticPergolaHandler} is responsible for handling commands, + * which are sent to one of the channels of the bioclimatic pergola thing. + * + * @author Ondrej Pecta - Initial contribution + */ +@NonNullByDefault +public class SomfyTahomaBioclimaticPergolaHandler extends SomfyTahomaBaseThingHandler { + + public SomfyTahomaBioclimaticPergolaHandler(Thing thing) { + super(thing); + stateNames.put(SLATS, "core:SlatsOpenClosedState"); + stateNames.put(ORIENTATION, "core:SlatsOrientationState"); + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + super.handleCommand(channelUID, command); + + if (command instanceof RefreshType) { + return; + } + + switch (channelUID.getId()) { + case PERGOLA_COMMAND: + String cmd = getTahomaCommand(command.toString().toUpperCase()); + sendCommand(cmd); + break; + case ORIENTATION: + // Bioclimatic pergola can control only orientation and full closure, not partial closure + String param = "[" + toInteger(command) + "]"; + sendCommand(COMMAND_SET_ORIENTATION, param); + break; + default: + return; + } + } + + private String getTahomaCommand(String command) { + switch (command) { + case "OFF": + case "DOWN": + case "CLOSE": + case "CLOSESLATS": + return COMMAND_CLOSE_SLATS; + case "ON": + case "UP": + case "OPEN": + case "OPENSLATS": + return COMMAND_OPEN_SLATS; + default: + return COMMAND_STOP; + } + } +} diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/bioclimaticpergola.xml b/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/bioclimaticpergola.xml new file mode 100644 index 000000000..cf94ba547 --- /dev/null +++ b/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/bioclimaticpergola.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + url + + + + diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/channels.xml index 4f20b1c23..44fee7caf 100644 --- a/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/channels.xml @@ -396,4 +396,24 @@ The scenarios defined in the cloud portal recommend + + + Contact + + Slats having OPEN/CLOSED state + + + + + String + + A channel used for sending commands to Somfy Bioclimatic Pergola device + + + + + + + +