-
-
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
20 changed files
with
302 additions
and
87 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...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,9 @@ | ||
package org.openhab.binding.zigbee; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
@NonNullByDefault | ||
public interface ZigBeeCommandParameter<T> { | ||
String getName(); | ||
Class<T> getType(); | ||
} |
22 changes: 22 additions & 0 deletions
22
...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,22 @@ | ||
package org.openhab.binding.zigbee; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.zigbee.internal.ZigBeeCommandParameterImpl; | ||
import org.openhab.binding.zigbee.internal.ZigBeeCommandParametersImpl; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
@NonNullByDefault | ||
public interface ZigBeeCommandParameters { | ||
static ZigBeeCommandParameters empty() { | ||
return new ZigBeeCommandParametersImpl(); | ||
} | ||
|
||
<T> ZigBeeCommandParameters add(final ZigBeeCommandParameter<T> param, final T value); | ||
<T> Optional<T> get(final ZigBeeCommandParameter<T> param); | ||
Collection<ZigBeeCommandParameter<?>> setParameters(); | ||
|
||
ZigBeeCommandParameter<Integer> TRANSITION_TIME = | ||
new ZigBeeCommandParameterImpl<>(Integer.class, "transitionTime"); | ||
} |
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
package org.openhab.binding.zigbee; | ||
|
||
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 static org.eclipse.jdt.annotation.Checks.requireNonNull; | ||
|
||
@SuppressWarnings("unused") | ||
@ThingActionsScope(name="zigbee") | ||
@NonNullByDefault | ||
public final class ZigBeeThingActions implements ThingActions { | ||
private @Nullable ZigBeeThingHandler handler; | ||
|
||
@Override | ||
public void setThingHandler(@Nullable final ThingHandler handler) { | ||
this.handler = (ZigBeeThingHandler) handler; | ||
} | ||
|
||
@Override | ||
public @Nullable ThingHandler getThingHandler() { | ||
return handler; | ||
} | ||
|
||
@RuleAction(label = "sendCommand") | ||
public void sendCommand( | ||
@ActionInput(name = "channelId", required = true) final String channelId, | ||
@ActionInput(name = "command", required = true) final Command command, | ||
@ActionInput(name = "params") @Nullable final ZigBeeCommandParameters params | ||
) { | ||
handleCommand(getChannel(channelId), command, params != null ? params : ZigBeeCommandParameters.empty()); | ||
} | ||
|
||
private void handleCommand(final ChannelUID channel, final Command command, final ZigBeeCommandParameters params) { | ||
requireNonNull(handler).handleCommand(channel, command, params); | ||
} | ||
|
||
private ChannelUID getChannel(final String channelId) { | ||
return new ChannelUID(requireNonNull(handler).getThing().getUID(), channelId); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
....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,31 @@ | ||
package org.openhab.binding.zigbee.internal; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.zigbee.ZigBeeCommandParameter; | ||
|
||
@NonNullByDefault | ||
public final class ZigBeeCommandParameterImpl<T> implements ZigBeeCommandParameter<T> { | ||
|
||
private final String name; | ||
private final Class<T> klazz; | ||
|
||
public ZigBeeCommandParameterImpl(final Class<T> klazz, final String name) { | ||
this.klazz = klazz; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Class<T> getType() { | ||
return klazz; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...zigbee/src/main/java/org/openhab/binding/zigbee/internal/ZigBeeCommandParametersImpl.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,73 @@ | ||
package org.openhab.binding.zigbee.internal; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.zigbee.ZigBeeCommandParameter; | ||
import org.openhab.binding.zigbee.ZigBeeCommandParameters; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.*; | ||
|
||
@NonNullByDefault | ||
public class ZigBeeCommandParametersImpl implements ZigBeeCommandParameters { | ||
private static final Logger logger = LoggerFactory.getLogger(ZigBeeCommandParametersImpl.class); | ||
|
||
private final Map<ZigBeeCommandParameter<?>, Object> params = new HashMap<>(); | ||
|
||
@Override | ||
public <T> ZigBeeCommandParameters add(final ZigBeeCommandParameter<T> param, final T value) { | ||
params.put(param, value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> Optional<T> get(final ZigBeeCommandParameter<T> param) { | ||
Object v = params.get(param); | ||
if (v == null) { | ||
return Optional.empty(); | ||
} else if (!param.getType().isInstance(param)) { | ||
logger.debug("Can not retrieve param {}: object of type {} ({}) can not be casted to {}", | ||
param.getName(), param.getClass(), param, param.getType().getName() | ||
); | ||
return Optional.empty(); | ||
} else { | ||
return Optional.of(param.getType().cast(param)); | ||
} | ||
} | ||
|
||
@Override | ||
public Collection<ZigBeeCommandParameter<?>> setParameters() { | ||
return Collections.unmodifiableSet(params.keySet()); | ||
} | ||
|
||
public static class UsageTracker implements ZigBeeCommandParameters { | ||
private final Set<ZigBeeCommandParameter<?>> usedParams = new HashSet<>(); | ||
private final ZigBeeCommandParameters delegate; | ||
|
||
public UsageTracker(ZigBeeCommandParameters delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
public Set<ZigBeeCommandParameter<?>> unusedParams() { | ||
Set<ZigBeeCommandParameter<?>> unusedParams = new HashSet<>(setParameters()); | ||
unusedParams.removeAll(usedParams); | ||
return Collections.unmodifiableSet(unusedParams); | ||
} | ||
|
||
@Override | ||
public <T> ZigBeeCommandParameters add(ZigBeeCommandParameter<T> param, T value) { | ||
return delegate.add(param, value); | ||
} | ||
|
||
@Override | ||
public <T> Optional<T> get(ZigBeeCommandParameter<T> param) { | ||
usedParams.add(param); | ||
return delegate.get(param); | ||
} | ||
|
||
@Override | ||
public Collection<ZigBeeCommandParameter<?>> setParameters() { | ||
return delegate.setParameters(); | ||
} | ||
} | ||
} |
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.