Search in sources :

Example 1 with FritzahaWebInterface

use of org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface in project openhab1-addons by openhab.

the class FritzahaBinding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    logger.debug("internalReceiveCommand() is called!");
    FritzahaBindingProvider commandProvider = null;
    FritzahaSwitchedOutlet switchDevice = null;
    for (FritzahaBindingProvider currentProvider : providers) {
        if (!currentProvider.getItemNames().contains(itemName)) {
            continue;
        }
        FritzahaDevice device = currentProvider.getDeviceConfig(itemName);
        if (!(device instanceof FritzahaSwitchedOutlet)) {
            continue;
        }
        switchDevice = (FritzahaSwitchedOutlet) device;
        commandProvider = currentProvider;
        break;
    }
    if (commandProvider == null || switchDevice == null) {
        logger.error("No provider found for item " + itemName);
        return;
    }
    if (command instanceof OnOffType) {
        String deviceHostID = switchDevice.getHost();
        Host host = hostCache.get(deviceHostID);
        if (host != null) {
            FritzahaWebInterface deviceHost = host.getConnection();
            boolean valueToSet = (command == OnOffType.ON);
            switchDevice.setSwitchState(valueToSet, itemName, deviceHost);
        }
    } else {
        logger.debug("Unsupported command type for item " + itemName);
    }
}
Also used : FritzahaBindingProvider(org.openhab.binding.fritzaha.FritzahaBindingProvider) OnOffType(org.openhab.core.library.types.OnOffType) FritzahaDevice(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice) FritzahaSwitchedOutlet(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaSwitchedOutlet) FritzahaWebInterface(org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface)

Example 2 with FritzahaWebInterface

use of org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface in project openhab1-addons by openhab.

the class FritzahaBinding method unsetEventPublisher.

@Override
public void unsetEventPublisher(EventPublisher eventPublisher) {
    super.unsetEventPublisher(eventPublisher);
    for (Host currentHostData : hostCache.values()) {
        currentHostData.eventPublisher = null;
        FritzahaWebInterface currentHost = currentHostData.getConnection();
        currentHost.unsetEventPublisher(eventPublisher);
    }
}
Also used : FritzahaWebInterface(org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface)

Example 3 with FritzahaWebInterface

use of org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface in project openhab1-addons by openhab.

the class FritzahaBinding method setEventPublisher.

@Override
public void setEventPublisher(EventPublisher eventPublisher) {
    super.setEventPublisher(eventPublisher);
    for (Host currentHostData : hostCache.values()) {
        currentHostData.eventPublisher = eventPublisher;
        FritzahaWebInterface currentHost = currentHostData.getConnection();
        currentHost.setEventPublisher(eventPublisher);
    }
}
Also used : FritzahaWebInterface(org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface)

Example 4 with FritzahaWebInterface

use of org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface in project openhab1-addons by openhab.

the class FritzahaBinding method execute.

/**
     * @{inheritDoc
     */
@Override
protected void execute() {
    logger.debug("execute() method is called!");
    for (FritzahaBindingProvider currentProvider : providers) {
        for (String currentItem : currentProvider.getItemNames()) {
            FritzahaDevice currentDevice = currentProvider.getDeviceConfig(currentItem);
            String currentHostId = currentDevice.getHost();
            if (!hostCache.containsKey(currentHostId)) {
                continue;
            }
            FritzahaWebInterface currentHost = hostCache.get(currentHostId).getConnection();
            if (currentDevice instanceof FritzahaSwitchedOutlet) {
                FritzahaSwitchedOutlet currentSwitch = (FritzahaSwitchedOutlet) currentDevice;
                currentSwitch.updateSwitchState(currentItem, currentHost);
            } else if (currentDevice instanceof FritzahaOutletMeter) {
                FritzahaOutletMeter currentMeter = (FritzahaOutletMeter) currentDevice;
                currentMeter.updateMeterValue(currentItem, currentHost);
            }
        }
    }
}
Also used : FritzahaBindingProvider(org.openhab.binding.fritzaha.FritzahaBindingProvider) FritzahaOutletMeter(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaOutletMeter) FritzahaDevice(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice) FritzahaSwitchedOutlet(org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaSwitchedOutlet) FritzahaWebInterface(org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface)

Aggregations

FritzahaWebInterface (org.openhab.binding.fritzaha.internal.hardware.FritzahaWebInterface)4 FritzahaBindingProvider (org.openhab.binding.fritzaha.FritzahaBindingProvider)2 FritzahaDevice (org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice)2 FritzahaSwitchedOutlet (org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaSwitchedOutlet)2 FritzahaOutletMeter (org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaOutletMeter)1 OnOffType (org.openhab.core.library.types.OnOffType)1