-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
So far only transition time for color channels is supported Signed-off-by: Thomas Weißschuh <thomas@weissschuh.net>
- Loading branch information
Showing
19 changed files
with
203 additions
and
34 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...enhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/ZigBeeCommandParameter.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,12 @@ | ||
package org.openhab.binding.zigbee; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@NonNullByDefault | ||
public interface ZigBeeCommandParameter<T> { | ||
String getName(); | ||
Optional<T> getFromMap(Map<String, Object> params); | ||
} |
9 changes: 9 additions & 0 deletions
9
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/ZigBeeCommandParameters.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,9 @@ | ||
package org.openhab.binding.zigbee; | ||
|
||
import org.openhab.binding.zigbee.internal.ZigBeeCommandParameterImpl; | ||
|
||
public final class ZigBeeCommandParameters { | ||
private ZigBeeCommandParameters() { } | ||
public static final ZigBeeCommandParameter<Integer> TRANSITION_TIME = | ||
new ZigBeeCommandParameterImpl<>(Integer.class, "transitionTime"); | ||
} |
80 changes: 80 additions & 0 deletions
80
org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/ZigBeeThingActions.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,80 @@ | ||
package org.openhab.binding.zigbee; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.smarthome.core.thing.ChannelUID; | ||
import org.eclipse.smarthome.core.thing.binding.ThingActions; | ||
import org.eclipse.smarthome.core.thing.binding.ThingActionsScope; | ||
import org.eclipse.smarthome.core.thing.binding.ThingHandler; | ||
import org.eclipse.smarthome.core.types.Command; | ||
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler; | ||
import org.openhab.core.automation.annotation.ActionInput; | ||
import org.openhab.core.automation.annotation.RuleAction; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@SuppressWarnings("unused") | ||
@ThingActionsScope(name="zigbee") | ||
@NonNullByDefault | ||
public final class ZigBeeThingActions implements ThingActions { | ||
private @Nullable ZigBeeThingHandler handler; | ||
|
||
@Override | ||
public void setThingHandler(@Nullable ThingHandler handler) { | ||
this.handler = (ZigBeeThingHandler) handler; | ||
} | ||
|
||
@Override | ||
public @Nullable ThingHandler getThingHandler() { | ||
return handler; | ||
} | ||
|
||
@RuleAction(label = "sendCommand") | ||
public void sendCommand( | ||
@ActionInput(name = "channelId", required = true) String channelId, | ||
@ActionInput(name = "command", required = true) Command command, | ||
@ActionInput(name = "params", required = true) Map<String, Object> params | ||
) { | ||
handleCommand(getChannel(channelId), command, params); | ||
} | ||
|
||
private void handleCommand(ChannelUID channel, Command command, Map<String, Object> params) { | ||
handler.handleCommand(channel, command, params); | ||
} | ||
|
||
private ChannelUID getChannel(String channelId) { | ||
return new ChannelUID(handler.getThing().getUID(), channelId); | ||
} | ||
|
||
@RuleAction(label = "buildCommand") | ||
public CommandBuilder buildCommand( | ||
@ActionInput(name = "channelId", required = true) String channelId, | ||
@ActionInput(name = "command", required = true) Command command | ||
) { | ||
return new CommandBuilder(this, getChannel(channelId), command); | ||
} | ||
|
||
public static class CommandBuilder { | ||
private final ZigBeeThingActions actions; | ||
private final ChannelUID channel; | ||
private final Command command; | ||
private final Map<String, Object> params = new HashMap<>(); | ||
|
||
private CommandBuilder(ZigBeeThingActions actions, ChannelUID channel, Command command) { | ||
this.actions = actions; | ||
this.channel = channel; | ||
this.command = command; | ||
} | ||
|
||
public <@NonNull T> CommandBuilder with(ZigBeeCommandParameter<T> parameter, T value) { | ||
params.put(parameter.getName(), value); | ||
return this; | ||
} | ||
|
||
public void send() { | ||
actions.handleCommand(channel, command, params); | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
....zigbee/src/main/java/org/openhab/binding/zigbee/internal/ZigBeeCommandParameterImpl.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,42 @@ | ||
package org.openhab.binding.zigbee.internal; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.zigbee.ZigBeeCommandParameter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@NonNullByDefault | ||
public final class ZigBeeCommandParameterImpl<T> implements ZigBeeCommandParameter<T> { | ||
private final Logger logger; | ||
private final String name; | ||
private final Class<T> klazz; | ||
|
||
public ZigBeeCommandParameterImpl(Class<T> klazz, String name) { | ||
this.logger = LoggerFactory.getLogger(ZigBeeCommandParameterImpl.class.getName() + "." + name); | ||
this.klazz = klazz; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Optional<T> getFromMap(Map<String, Object> params) { | ||
Object param = params.get(getName()); | ||
if (param == null) { | ||
return Optional.empty(); | ||
} else if (!klazz.isInstance(param)) { | ||
logger.debug("Can not retrieve param {}: object of type {} ({}) can not be casted to {}", | ||
getName(), param.getClass(), (param), klazz.getName() | ||
); | ||
return Optional.empty(); | ||
} else { | ||
return Optional.of(klazz.cast(param)); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.