forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[somfytahoma] added support for the Shutter thing (openhab#12495)
Signed-off-by: Ondrej Pecta <opecta@gmail.com> Signed-off-by: Nick Waterton <n.waterton@outlook.com>
- Loading branch information
1 parent
2083161
commit 0fb1130
Showing
7 changed files
with
228 additions
and
113 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaShutterHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/shutter.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |