-
-
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
12 changed files
with
178 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
9 changes: 9 additions & 0 deletions
9
...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,9 @@ | ||
package org.openhab.binding.zigbee.action; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public interface ZigBeeThingActionParameter<T> { | ||
String getName(); | ||
Optional<T> getFromMap(Map<String, Object> params); | ||
} |
9 changes: 9 additions & 0 deletions
9
...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,9 @@ | ||
package org.openhab.binding.zigbee.action; | ||
|
||
import org.openhab.binding.zigbee.action.internal.ZigBeeThingActionParameterImpl; | ||
|
||
public final class ZigBeeThingActionParameters { | ||
private ZigBeeThingActionParameters() { } | ||
public static final ZigBeeThingActionParameter<Integer> TRANSITION_TIME = | ||
new ZigBeeThingActionParameterImpl<>(Integer.class, "transitionTime"); | ||
} |
76 changes: 76 additions & 0 deletions
76
...ab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/action/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.action; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
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 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", required = true) String channelId, | ||
@ActionInput(name = "command", required = true) Command command, | ||
@ActionInput(name = "params", required = true) 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", required = true) String channelId, | ||
@ActionInput(name = "command", required = true) 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); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
.../main/java/org/openhab/binding/zigbee/action/internal/ZigBeeThingActionParameterImpl.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,40 @@ | ||
package org.openhab.binding.zigbee.action.internal; | ||
|
||
import org.openhab.binding.zigbee.action.ZigBeeThingActionParameter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public final class ZigBeeThingActionParameterImpl<T> implements ZigBeeThingActionParameter<T> { | ||
private final Logger logger = LoggerFactory.getLogger(ZigBeeThingActionParameterImpl.class); | ||
|
||
private final String name; | ||
private final Class<T> klazz; | ||
|
||
public ZigBeeThingActionParameterImpl(Class<T> klazz, String 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
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