-
-
Notifications
You must be signed in to change notification settings - Fork 111
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 <[email protected]>
- Loading branch information
Showing
11 changed files
with
151 additions
and
24 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
...ng.zigbee/src/main/java/org/openhab/binding/zigbee/action/ZigBeeThingActionParameter.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,25 @@ | ||
package org.openhab.binding.zigbee.action; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class ZigBeeThingActionParameter<T> { | ||
private final String name; | ||
private final Class<T> klazz; | ||
|
||
public ZigBeeThingActionParameter(Class<T> klazz, String name) { | ||
this.klazz = klazz; | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Optional<T> getFromMap(Map<String, Object> params) { | ||
if (!params.containsKey(name)) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(klazz.cast(params.get(name))); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...g.zigbee/src/main/java/org/openhab/binding/zigbee/action/ZigBeeThingActionParameters.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,6 @@ | ||
package org.openhab.binding.zigbee.action; | ||
|
||
public class ZigBeeThingActionParameters { | ||
public static final ZigBeeThingActionParameter<Integer> TRANSITION_TIME = | ||
new ZigBeeThingActionParameter<>(Integer.class, "transitionTime"); | ||
} |
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
76 changes: 76 additions & 0 deletions
76
....binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/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,76 @@ | ||
package org.openhab.binding.zigbee.internal; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.smarthome.automation.annotation.ActionInput; | ||
import org.eclipse.smarthome.automation.annotation.RuleAction; | ||
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.action.ZigBeeThingActionParameter; | ||
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@ThingActionsScope(name="zigbee") | ||
@NonNullByDefault | ||
public class ZigbeeThingActions implements ThingActions { | ||
private ZigBeeThingHandler handler; | ||
|
||
@Override | ||
public void setThingHandler(ThingHandler handler) { | ||
this.handler = (ZigBeeThingHandler) handler; | ||
} | ||
|
||
@Override | ||
public ThingHandler getThingHandler() { | ||
return handler; | ||
} | ||
|
||
@RuleAction(label = "sendCommand") | ||
public void sendCommand( | ||
@ActionInput(name = "channelId") String channelId, | ||
@ActionInput(name = "command") Command command, | ||
@ActionInput(name = "params") Map<String, Object> params | ||
) { | ||
ChannelUID channel = new ChannelUID(handler.getThing().getUID(), channelId); | ||
handleCommand(channel, command, params); | ||
} | ||
|
||
private void handleCommand(ChannelUID channel, Command command, Map<String, Object> params) { | ||
handler.handleCommand(channel, command, params); | ||
} | ||
|
||
@RuleAction(label = "buildCommand") | ||
public CommandBuilder buildCommand( | ||
@ActionInput(name = "channelId") String channelId, | ||
@ActionInput(name = "command") Command command | ||
) { | ||
ChannelUID channel = new ChannelUID(handler.getThing().getUID(), channelId); | ||
return new CommandBuilder(this, channel, 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 <T> CommandBuilder with(ZigBeeThingActionParameter<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
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