Search in sources :

Example 1 with Circuit

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.

the class DeviceStatusManagerImpl method unregisterDeviceListener.

@Override
public void unregisterDeviceListener(DeviceStatusListener deviceListener) {
    if (deviceListener != null) {
        String id = deviceListener.getDeviceStatusListenerID();
        logger.debug("unregister DeviceListener with id: {}", id);
        if (id.equals(DeviceStatusListener.DEVICE_DISCOVERY)) {
            this.deviceDiscovery = null;
        } else {
            Device intDevice = strucMan.getDeviceByDSID(deviceListener.getDeviceStatusListenerID());
            if (intDevice != null) {
                intDevice.unregisterDeviceStatusListener();
            } else {
                Circuit intCircuit = strucMan.getCircuitByDSID(new DSID(deviceListener.getDeviceStatusListenerID()));
                if (intCircuit != null) {
                    intCircuit.unregisterDeviceStatusListener();
                    if (deviceDiscovery != null) {
                        deviceDiscovery.onDeviceAdded(intCircuit);
                    }
                }
            }
        }
    }
}
Also used : Device(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device) Circuit(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit) DSID(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSID)

Example 2 with Circuit

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.

the class DeviceStatusManagerImpl method registerDeviceListener.

@Override
public void registerDeviceListener(DeviceStatusListener deviceListener) {
    if (deviceListener != null) {
        String id = deviceListener.getDeviceStatusListenerID();
        if (id.equals(DeviceStatusListener.DEVICE_DISCOVERY)) {
            this.deviceDiscovery = deviceListener;
            logger.debug("register Device-Discovery ");
            for (Device device : strucMan.getDeviceMap().values()) {
                deviceDiscovery.onDeviceAdded(device);
            }
            for (Circuit circuit : strucMan.getCircuitMap().values()) {
                deviceDiscovery.onDeviceAdded(circuit);
            }
        } else {
            Device intDevice = strucMan.getDeviceByDSID(deviceListener.getDeviceStatusListenerID());
            if (intDevice != null) {
                logger.debug("register DeviceListener with id: {} to Device ", id);
                intDevice.registerDeviceStatusListener(deviceListener);
            } else {
                Circuit intCircuit = strucMan.getCircuitByDSID(new DSID(deviceListener.getDeviceStatusListenerID()));
                if (intCircuit != null) {
                    logger.debug("register DeviceListener with id: {} to Circuit ", id);
                    intCircuit.registerDeviceStatusListener(deviceListener);
                } else {
                    deviceListener.onDeviceRemoved(null);
                }
            }
        }
    }
}
Also used : Device(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device) Circuit(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit) DSID(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSID)

Example 3 with Circuit

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.

the class CircuitHandler method onDeviceAdded.

@Override
public void onDeviceAdded(GeneralDeviceInformation device) {
    if (device instanceof Circuit) {
        this.circuit = (Circuit) device;
        if (this.circuit.isPresent()) {
            ThingStatusInfo statusInfo = this.dssBridgeHandler.getThing().getStatusInfo();
            updateStatus(statusInfo.getStatus(), statusInfo.getStatusDetail(), statusInfo.getDescription());
            logger.debug("Set status to {}", getThing().getStatus());
            checkCircuitInfoProperties(this.circuit);
            // load first channel values
            onCircuitStateInitial(this.circuit);
            return;
        }
    }
    onDeviceRemoved(device);
}
Also used : Circuit(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo)

Example 4 with Circuit

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.

the class DeviceDiscoveryService method onDeviceAddedInternal.

private void onDeviceAddedInternal(GeneralDeviceInformation device) {
    boolean isSupported = false;
    if (device instanceof Device) {
        Device tempDevice = (Device) device;
        if ((tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) || (deviceType.equals(tempDevice.getHWinfo().substring(0, 2)) && (tempDevice.isDeviceWithOutput() || tempDevice.isBinaryInputDevice()) && tempDevice.isPresent())) {
            isSupported = true;
        }
    } else if (device instanceof Circuit && DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString().equals(deviceType)) {
        isSupported = true;
    }
    if (isSupported) {
        ThingUID thingUID = getThingUID(device);
        if (thingUID != null) {
            Map<String, Object> properties = new HashMap<>(1);
            properties.put(DigitalSTROMBindingConstants.DEVICE_DSID, device.getDSID().getValue());
            String deviceName = null;
            if (StringUtils.isNotBlank(device.getName())) {
                deviceName = device.getName();
            } else {
                // if no name is set, the dSID will be used as name
                deviceName = device.getDSID().getValue();
            }
            DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withBridge(bridgeUID).withLabel(deviceName).build();
            thingDiscovered(discoveryResult);
        } else {
            if (device instanceof Device) {
                logger.debug("Discovered unsupported device hardware type '{}' with uid {}", ((Device) device).getHWinfo(), device.getDSUID());
            }
        }
    } else {
        if (device instanceof Device) {
            logger.debug("Discovered device with disabled or no output mode. Device was not added to inbox. " + "Device information: hardware info: {}, dSUID: {}, device-name: {}, output value: {}", ((Device) device).getHWinfo(), device.getDSUID(), device.getName(), ((Device) device).getOutputMode());
        }
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) Device(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Circuit(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit)

Example 5 with Circuit

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit in project smarthome by eclipse.

the class DsAPIImpl method getApartmentCircuits.

@Override
public List<Circuit> getApartmentCircuits(String sessionToken) {
    String response = transport.execute(SimpleRequestBuilder.buildNewJsonRequest(ClassKeys.APARTMENT).addFunction(FunctionKeys.GET_CIRCUITS).addParameter(ParameterKeys.TOKEN, sessionToken).buildRequestString());
    JsonObject responseObj = JSONResponseHandler.toJsonObject(response);
    if (JSONResponseHandler.checkResponse(responseObj)) {
        responseObj = JSONResponseHandler.getResultJsonObject(responseObj);
        if (responseObj.get(JSONApiResponseKeysEnum.CIRCUITS.getKey()).isJsonArray()) {
            JsonArray array = responseObj.get(JSONApiResponseKeysEnum.CIRCUITS.getKey()).getAsJsonArray();
            List<Circuit> circuitList = new LinkedList<Circuit>();
            for (int i = 0; i < array.size(); i++) {
                if (array.get(i).isJsonObject()) {
                    circuitList.add(new CircuitImpl(array.get(i).getAsJsonObject()));
                }
            }
            return circuitList;
        }
    }
    return new LinkedList<Circuit>();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Circuit(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit) CircuitImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.impl.CircuitImpl) LinkedList(java.util.LinkedList)

Aggregations

Circuit (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit)5 Device (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device)3 DSID (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSID)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 CircuitImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.impl.CircuitImpl)1 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)1 ThingStatusInfo (org.eclipse.smarthome.core.thing.ThingStatusInfo)1 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)1