-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hue] Add console commands to list devices and groups set up on the h…
…ue bridge Signed-off-by: Laurent Garnier <[email protected]>
- Loading branch information
Showing
3 changed files
with
144 additions
and
0 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
96 changes: 96 additions & 0 deletions
96
...nding.hue/src/main/java/org/openhab/binding/hue/internal/console/HueCommandExtension.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,96 @@ | ||
/** | ||
* Copyright (c) 2010-2020 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.hue.internal.console; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.smarthome.core.thing.Thing; | ||
import org.eclipse.smarthome.core.thing.ThingRegistry; | ||
import org.eclipse.smarthome.core.thing.ThingUID; | ||
import org.eclipse.smarthome.io.console.Console; | ||
import org.eclipse.smarthome.io.console.extensions.AbstractConsoleCommandExtension; | ||
import org.eclipse.smarthome.io.console.extensions.ConsoleCommandExtension; | ||
import org.openhab.binding.hue.internal.handler.HueBridgeHandler; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
/** | ||
* The {@link HueCommandExtension} is responsible for handling console commands | ||
* | ||
* @author Laurent Garnier - Initial contribution | ||
*/ | ||
|
||
@NonNullByDefault | ||
@Component(service = ConsoleCommandExtension.class) | ||
public class HueCommandExtension extends AbstractConsoleCommandExtension { | ||
|
||
private static final String LIGHTS = "lights"; | ||
private static final String SENSORS = "sensors"; | ||
private static final String GROUPS = "groups"; | ||
|
||
private final ThingRegistry thingRegistry; | ||
|
||
@Activate | ||
public HueCommandExtension(final @Reference ThingRegistry thingRegistry) { | ||
super("hue", "Interact with the hue binding."); | ||
this.thingRegistry = thingRegistry; | ||
} | ||
|
||
@Override | ||
public void execute(String[] args, Console console) { | ||
if (args.length == 2) { | ||
HueBridgeHandler bridgeHandler = null; | ||
try { | ||
ThingUID thingUID = new ThingUID(args[0]); | ||
Thing thing = thingRegistry.get(thingUID); | ||
if ((thing != null) && (thing.getHandler() != null) | ||
&& (thing.getHandler() instanceof HueBridgeHandler)) { | ||
bridgeHandler = (HueBridgeHandler) thing.getHandler(); | ||
} | ||
} catch (IllegalArgumentException e) { | ||
bridgeHandler = null; | ||
} | ||
if (bridgeHandler == null) { | ||
console.println("Bad bridge id '" + args[0] + "'"); | ||
printUsage(console); | ||
} else { | ||
switch (args[1]) { | ||
case LIGHTS: | ||
bridgeHandler.reportLights().forEach(console::println); | ||
break; | ||
case SENSORS: | ||
bridgeHandler.reportSensors().forEach(console::println); | ||
break; | ||
case GROUPS: | ||
bridgeHandler.reportGroups().forEach(console::println); | ||
break; | ||
default: | ||
printUsage(console); | ||
break; | ||
} | ||
} | ||
} else { | ||
printUsage(console); | ||
} | ||
} | ||
|
||
@Override | ||
public List<String> getUsages() { | ||
return Arrays.asList(new String[] { buildCommandUsage("<bridgeUID> " + LIGHTS, "list lights"), | ||
buildCommandUsage("<bridgeUID> " + SENSORS, "list sensors"), | ||
buildCommandUsage("<bridgeUID> " + GROUPS, "list groups") }); | ||
} | ||
} |
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