Skip to content

Commit

Permalink
[somfytahoma] added support for the Shutter thing (openhab#12495)
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Pecta <opecta@gmail.com>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
  • Loading branch information
octa22 authored and NickWaterton committed Apr 27, 2022
1 parent 2083161 commit 0fb1130
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 113 deletions.
221 changes: 111 additions & 110 deletions bundles/org.openhab.binding.somfytahoma/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class SomfyTahomaBindingConstants {
// Uno Roller Shutter
public static final ThingTypeUID THING_TYPE_ROLLERSHUTTER_UNO = new ThingTypeUID(BINDING_ID, "rollershutter_uno");

// Shutter
public static final ThingTypeUID THING_TYPE_SHUTTER = new ThingTypeUID(BINDING_ID, "shutter");

// Screen
public static final ThingTypeUID THING_TYPE_SCREEN = new ThingTypeUID(BINDING_ID, "screen");

Expand Down Expand Up @@ -182,7 +185,7 @@ public class SomfyTahomaBindingConstants {
public static final String STATUS = "status";
public static final String SCENARIOS = "scenarios";

// Roller shutter, Awning, Screen, Blind, Garage door, Window, Curtain
// Roller shutter, Shutter, Awning, Screen, Blind, Garage door, Window, Curtain
public static final String CONTROL = "control";

// Adjustable slats roller shutter
Expand Down Expand Up @@ -445,6 +448,7 @@ public class SomfyTahomaBindingConstants {

// supported uiClasses
public static final String CLASS_ROLLER_SHUTTER = "RollerShutter";
public static final String CLASS_SHUTTER = "Shutter";
public static final String CLASS_SCREEN = "Screen";
public static final String CLASS_VENETIAN_BLIND = "VenetianBlind";
public static final String CLASS_EXTERIOR_SCREEN = "ExteriorScreen";
Expand Down Expand Up @@ -501,7 +505,7 @@ public class SomfyTahomaBindingConstants {
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_BIOCLIMATIC_PERGOLA, THING_TYPE_WATERHEATINGSYSTEM, THING_TYPE_HITACHI_ATWHZ,
THING_TYPE_HITACHI_DHW, THING_TYPE_HITACHI_ATWMC, THING_TYPE_RAINSENSOR));
THING_TYPE_HITACHI_DHW, THING_TYPE_HITACHI_ATWMC, THING_TYPE_RAINSENSOR, THING_TYPE_SHUTTER));

// somfy gateways
public static Map<Integer, String> gatewayTypes = new HashMap<Integer, String>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaPodHandler;
import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaRainSensorHandler;
import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaRollerShutterHandler;
import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaShutterHandler;
import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaSilentRollerShutterHandler;
import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaSirenHandler;
import org.openhab.binding.somfytahoma.internal.handler.SomfyTahomaSmokeSensorHandler;
Expand Down Expand Up @@ -118,6 +119,8 @@ protected ThingHandler createHandler(Thing thing) {
return new SomfyTahomaUnoRollerShutterHandler(thing);
} else if (thingTypeUID.equals(THING_TYPE_SCREEN) || thingTypeUID.equals(THING_TYPE_EXTERIORSCREEN)) {
return new SomfyTahomaRollerShutterHandler(thing);
} else if (thingTypeUID.equals(THING_TYPE_SHUTTER)) {
return new SomfyTahomaShutterHandler(thing);
} else if (thingTypeUID.equals(THING_TYPE_VENETIANBLIND)
|| thingTypeUID.equals(THING_TYPE_EXTERIORVENETIANBLIND)) {
return new SomfyTahomaVenetianBlindHandler(thing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ private void discoverDevice(SomfyTahomaDevice device, SomfyTahomaSetup setup) {
deviceDiscovered(device, THING_TYPE_ROLLERSHUTTER, place);
}
break;
case CLASS_SHUTTER:
// widget: DynamicShutter
deviceDiscovered(device, THING_TYPE_SHUTTER, place);
break;
case CLASS_SCREEN:
// widget: PositionableTiltedScreen
deviceDiscovered(device, THING_TYPE_SCREEN, place);
Expand All @@ -223,7 +227,12 @@ private void discoverDevice(SomfyTahomaDevice device, SomfyTahomaSetup setup) {
break;
case CLASS_VENETIAN_BLIND:
// widget: DynamicVenetianBlind
deviceDiscovered(device, THING_TYPE_VENETIANBLIND, place);
if (hasCommmand(device, "setOrientation")) {
deviceDiscovered(device, THING_TYPE_VENETIANBLIND, place);
} else {
// simple venetian blind without orientation
deviceDiscovered(device, THING_TYPE_SHUTTER, place);
}
break;
case CLASS_WINDOW:
// widget: PositionableTiltedWindow
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* 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.somfytahoma.internal.handler;

import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.types.DecimalType;
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 SomfyTahomaShutterHandler} is responsible for handling commands,
* which are sent to one of the channels of the shutter thing.
*
* @author Ondrej Pecta - Initial contribution
*/
@NonNullByDefault
public class SomfyTahomaShutterHandler extends SomfyTahomaBaseThingHandler {

public SomfyTahomaShutterHandler(Thing thing) {
super(thing);
}

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
super.handleCommand(channelUID, command);
if (!CONTROL.equals(channelUID.getId())) {
return;
}

if (command instanceof RefreshType) {
return;
} else {
if (command instanceof DecimalType) {
sendCommand(toInteger(command) == 0 ? COMMAND_OPEN : COMMAND_CLOSE);
} else {
// Shutter understands "open", "close" and "stop" commands
String cmd = getTahomaCommand(command.toString());
if (cmd != null) {
sendCommand(cmd);
} else {
getLogger().debug("unsupported command: {}", command);
}
}
}
}

private @Nullable String getTahomaCommand(String command) {
switch (command) {
case "OFF":
case "DOWN":
case "CLOSE":
return COMMAND_CLOSE;
case "ON":
case "UP":
case "OPEN":
return COMMAND_OPEN;
case "STOP":
return COMMAND_STOP;
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ thing-type.somfytahoma.rollershutter.label = Somfy Roller Shutter
thing-type.somfytahoma.rollershutter_silent.label = Somfy Silent Roller Shutter
thing-type.somfytahoma.rollershutter_uno.label = Somfy Roller Shutter Uno
thing-type.somfytahoma.screen.label = Somfy Screen
thing-type.somfytahoma.shutter.label = Somfy Shutter
thing-type.somfytahoma.siren.label = Somfy Siren
thing-type.somfytahoma.smokesensor.label = Somfy Smoke Sensor
thing-type.somfytahoma.temperaturesensor.label = Somfy Temperature Sensor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="somfytahoma"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

<thing-type id="shutter">
<supported-bridge-type-refs>
<bridge-type-ref id="bridge"/>
</supported-bridge-type-refs>
<label>Somfy Shutter</label>
<channels>
<channel id="control" typeId="control"></channel>
</channels>
<representation-property>url</representation-property>
<config-description-ref uri="thing-type:somfytahoma:device"/>
</thing-type>

</thing:thing-descriptions>

0 comments on commit 0fb1130

Please sign in to comment.