Search in sources :

Example 1 with HueBridgeHandler

use of org.openhab.binding.hue.internal.handler.HueBridgeHandler in project openhab-addons by openhab.

the class HueCommandExtension method execute.

@Override
public void execute(String[] args, Console console) {
    if (args.length == 2) {
        Thing thing = null;
        try {
            ThingUID thingUID = new ThingUID(args[0]);
            thing = thingRegistry.get(thingUID);
        } catch (IllegalArgumentException e) {
            thing = null;
        }
        ThingHandler thingHandler = null;
        HueBridgeHandler bridgeHandler = null;
        HueGroupHandler groupHandler = null;
        if (thing != null) {
            thingHandler = thing.getHandler();
            if (thingHandler instanceof HueBridgeHandler) {
                bridgeHandler = (HueBridgeHandler) thingHandler;
            } else if (thingHandler instanceof HueGroupHandler) {
                groupHandler = (HueGroupHandler) thingHandler;
            }
        }
        if (thing == null) {
            console.println("Bad thing id '" + args[0] + "'");
            printUsage(console);
        } else if (thingHandler == null) {
            console.println("No handler initialized for the thingUID '" + args[0] + "'");
            printUsage(console);
        } else if (bridgeHandler == null && groupHandler == null) {
            console.println("'" + args[0] + "' is neither a Hue bridgeUID nor a Hue groupThingUID");
            printUsage(console);
        } else {
            switch(args[1]) {
                case USER_NAME:
                    if (bridgeHandler != null) {
                        String userName = bridgeHandler.getUserName();
                        console.println("Your user name is " + (userName != null ? userName : "undefined"));
                    } else {
                        console.println("'" + args[0] + "' is not a Hue bridgeUID");
                        printUsage(console);
                    }
                    break;
                case SCENES:
                    if (bridgeHandler != null) {
                        bridgeHandler.listScenesForConsole().forEach(console::println);
                    } else if (groupHandler != null) {
                        groupHandler.listScenesForConsole().forEach(console::println);
                    }
                    break;
                default:
                    printUsage(console);
                    break;
            }
        }
    } else {
        printUsage(console);
    }
}
Also used : HueGroupHandler(org.openhab.binding.hue.internal.handler.HueGroupHandler) ThingUID(org.openhab.core.thing.ThingUID) ThingHandler(org.openhab.core.thing.binding.ThingHandler) HueBridgeHandler(org.openhab.binding.hue.internal.handler.HueBridgeHandler) Thing(org.openhab.core.thing.Thing)

Example 2 with HueBridgeHandler

use of org.openhab.binding.hue.internal.handler.HueBridgeHandler in project openhab-addons by openhab.

the class HueDeviceDiscoveryService method setThingHandler.

@Override
public void setThingHandler(@Nullable ThingHandler handler) {
    if (handler instanceof HueBridgeHandler) {
        HueBridgeHandler localHandler = (HueBridgeHandler) handler;
        hueBridgeHandler = localHandler;
        bridgeUID = handler.getThing().getUID();
        i18nProvider = localHandler.getI18nProvider();
        localeProvider = localHandler.getLocaleProvider();
    }
}
Also used : HueBridgeHandler(org.openhab.binding.hue.internal.handler.HueBridgeHandler)

Example 3 with HueBridgeHandler

use of org.openhab.binding.hue.internal.handler.HueBridgeHandler in project openhab-addons by openhab.

the class HueDeviceDiscoveryService method deactivate.

@Override
public void deactivate() {
    removeOlderResults(new Date().getTime(), bridgeUID);
    final HueBridgeHandler handler = hueBridgeHandler;
    if (handler != null) {
        handler.unregisterDiscoveryListener();
    }
}
Also used : HueBridgeHandler(org.openhab.binding.hue.internal.handler.HueBridgeHandler) Date(java.util.Date)

Example 4 with HueBridgeHandler

use of org.openhab.binding.hue.internal.handler.HueBridgeHandler in project openhab-addons by openhab.

the class HueDeviceDiscoveryService method stopScan.

@Override
protected synchronized void stopScan() {
    super.stopScan();
    final HueBridgeHandler handler = hueBridgeHandler;
    if (handler != null) {
        removeOlderResults(getTimestampOfLastScan(), handler.getThing().getUID());
    }
}
Also used : HueBridgeHandler(org.openhab.binding.hue.internal.handler.HueBridgeHandler)

Example 5 with HueBridgeHandler

use of org.openhab.binding.hue.internal.handler.HueBridgeHandler in project openhab-addons by openhab.

the class HueDeviceDiscoveryService method startScan.

@Override
public void startScan() {
    final HueBridgeHandler handler = hueBridgeHandler;
    if (handler != null) {
        List<FullLight> lights = handler.getFullLights();
        for (FullLight l : lights) {
            addLightDiscovery(l);
        }
        List<FullSensor> sensors = handler.getFullSensors();
        for (FullSensor s : sensors) {
            addSensorDiscovery(s);
        }
        List<FullGroup> groups = handler.getFullGroups();
        for (FullGroup g : groups) {
            addGroupDiscovery(g);
        }
        // search for unpaired lights
        handler.startSearch();
    }
}
Also used : FullSensor(org.openhab.binding.hue.internal.FullSensor) FullGroup(org.openhab.binding.hue.internal.FullGroup) HueBridgeHandler(org.openhab.binding.hue.internal.handler.HueBridgeHandler) FullLight(org.openhab.binding.hue.internal.FullLight)

Aggregations

HueBridgeHandler (org.openhab.binding.hue.internal.handler.HueBridgeHandler)6 Date (java.util.Date)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 FullGroup (org.openhab.binding.hue.internal.FullGroup)1 FullLight (org.openhab.binding.hue.internal.FullLight)1 FullSensor (org.openhab.binding.hue.internal.FullSensor)1 HueDeviceDiscoveryService (org.openhab.binding.hue.internal.discovery.HueDeviceDiscoveryService)1 HueGroupHandler (org.openhab.binding.hue.internal.handler.HueGroupHandler)1 Configuration (org.openhab.core.config.core.Configuration)1 DiscoveryService (org.openhab.core.config.discovery.DiscoveryService)1 Thing (org.openhab.core.thing.Thing)1 ThingRegistry (org.openhab.core.thing.ThingRegistry)1 ThingUID (org.openhab.core.thing.ThingUID)1 ThingHandler (org.openhab.core.thing.binding.ThingHandler)1