Search in sources :

Example 1 with JSONDeviceSceneSpecImpl

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.JSONDeviceSceneSpecImpl in project smarthome by eclipse.

the class DeviceImpl method saveConfigSceneSpecificationIntoDevice.

@SuppressWarnings("null")
@Override
public void saveConfigSceneSpecificationIntoDevice(String propertries) {
    String[] scenes = propertries.split("\n");
    for (int i = 0; i < scenes.length; i++) {
        logger.debug("Find saved scene configuration for device with dSID {} and sceneID {}", dsid, i);
        String[] sceneIdToConfig = scenes[i].replaceAll(" ", "").split("=");
        String[] sceneParm = sceneIdToConfig[1].split(",");
        JSONDeviceSceneSpecImpl sceneSpecNew = null;
        int sceneValue = -1;
        int sceneAngle = -1;
        for (int j = 0; j < sceneParm.length; j++) {
            String[] sceneParmSplit = sceneParm[j].split(":");
            switch(sceneParmSplit[0]) {
                case "Scene":
                    sceneSpecNew = new JSONDeviceSceneSpecImpl(sceneParmSplit[1]);
                    break;
                case "dontcare":
                    sceneSpecNew.setDontcare(Boolean.parseBoolean(sceneParmSplit[1]));
                    break;
                case "localPrio":
                    sceneSpecNew.setLocalPrio(Boolean.parseBoolean(sceneParmSplit[1]));
                    break;
                case "specialMode":
                    sceneSpecNew.setSpecialMode(Boolean.parseBoolean(sceneParmSplit[1]));
                    break;
                case "sceneValue":
                    sceneValue = Integer.parseInt(sceneParmSplit[1]);
                    break;
                case "sceneAngle":
                    sceneAngle = Integer.parseInt(sceneParmSplit[1]);
                    break;
            }
        }
        if (sceneValue > -1) {
            logger.debug("Saved sceneValue {}, sceneAngle {} for scene id {} into device with dsid {}", sceneValue, sceneAngle, i, getDSID().getValue());
            synchronized (sceneOutputMap) {
                sceneOutputMap.put(sceneSpecNew.getScene().getSceneNumber(), new Integer[] { sceneValue, sceneAngle });
            }
        }
        if (sceneSpecNew != null) {
            logger.debug("Saved sceneConfig: [{}] for scene id {} into device with dsid {}", sceneSpecNew.toString(), i, getDSID().getValue());
            synchronized (sceneConfigMap) {
                sceneConfigMap.put(sceneSpecNew.getScene().getSceneNumber(), sceneSpecNew);
            }
        }
    }
}
Also used : JSONDeviceSceneSpecImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.JSONDeviceSceneSpecImpl)

Example 2 with JSONDeviceSceneSpecImpl

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.JSONDeviceSceneSpecImpl in project smarthome by eclipse.

the class DsAPIImpl method getDeviceSceneMode.

@Override
public DeviceSceneSpec getDeviceSceneMode(String token, DSID dSID, String dSUID, String name, Short sceneID) {
    if (checkRequiredDevice(dSID, dSUID, name) && SimpleRequestBuilder.objectToString(sceneID) != null) {
        String response = transport.execute(SimpleRequestBuilder.buildNewRequest(InterfaceKeys.JSON).addRequestClass(ClassKeys.DEVICE).addFunction(FunctionKeys.GET_SCENE_MODE).addDefaultDeviceParameter(token, dSID, dSUID, name).addParameter(ParameterKeys.SCENE_ID, SimpleRequestBuilder.objectToString(sceneID)).buildRequestString());
        JsonObject responseObj = JSONResponseHandler.toJsonObject(response);
        if (JSONResponseHandler.checkResponse(responseObj)) {
            JsonObject sceneSpec = JSONResponseHandler.getResultJsonObject(responseObj);
            if (sceneSpec != null) {
                return new JSONDeviceSceneSpecImpl(sceneSpec);
            }
        }
    }
    return null;
}
Also used : JSONDeviceSceneSpecImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.JSONDeviceSceneSpecImpl) JsonObject(com.google.gson.JsonObject)

Example 3 with JSONDeviceSceneSpecImpl

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.JSONDeviceSceneSpecImpl in project smarthome by eclipse.

the class DeviceImpl method saveConfigSceneSpecificationIntoDevice.

@SuppressWarnings("null")
@Override
public void saveConfigSceneSpecificationIntoDevice(Map<String, String> propertries) {
    if (propertries != null) {
        String sceneSave;
        for (String key : propertries.keySet()) {
            if (key.startsWith(DigitalSTROMBindingConstants.DEVICE_SCENE)) {
                try {
                    short sceneID = Short.parseShort((String) key.subSequence(DigitalSTROMBindingConstants.DEVICE_SCENE.length(), key.length()));
                    sceneSave = propertries.get(key);
                    if (StringUtils.isNotBlank(sceneSave)) {
                        logger.debug("Find saved scene configuration for device with dSID {} and sceneID {}", dsid, key);
                        String[] sceneParm = sceneSave.replace(" ", "").split(",");
                        JSONDeviceSceneSpecImpl sceneSpecNew = null;
                        int sceneValue = -1;
                        int sceneAngle = -1;
                        for (int j = 0; j < sceneParm.length; j++) {
                            String[] sceneParmSplit = sceneParm[j].split(":");
                            switch(sceneParmSplit[0]) {
                                case "Scene":
                                    sceneSpecNew = new JSONDeviceSceneSpecImpl(sceneParmSplit[1]);
                                    break;
                                case "dontcare":
                                    sceneSpecNew.setDontcare(Boolean.parseBoolean(sceneParmSplit[1]));
                                    break;
                                case "localPrio":
                                    sceneSpecNew.setLocalPrio(Boolean.parseBoolean(sceneParmSplit[1]));
                                    break;
                                case "specialMode":
                                    sceneSpecNew.setSpecialMode(Boolean.parseBoolean(sceneParmSplit[1]));
                                    break;
                                case "sceneValue":
                                    sceneValue = Integer.parseInt(sceneParmSplit[1]);
                                    break;
                                case "sceneAngle":
                                    sceneAngle = Integer.parseInt(sceneParmSplit[1]);
                                    break;
                            }
                        }
                        if (sceneValue > -1) {
                            logger.debug("Saved sceneValue {}, sceneAngle {} for scene id {} into device with dsid {}", sceneValue, sceneAngle, sceneID, getDSID().getValue());
                            internalSetSceneOutputValue(sceneID, sceneValue, sceneAngle);
                            deviceStateUpdates.add(new DeviceStateUpdateImpl(DeviceStateUpdate.UPDATE_SCENE_OUTPUT, new Short[] { sceneID, (short) -1 }));
                        }
                        if (sceneSpecNew != null) {
                            logger.debug("Saved sceneConfig: [{}] for scene id {} into device with dsid {}", sceneSpecNew.toString(), sceneID, getDSID().getValue());
                            synchronized (sceneConfigMap) {
                                sceneConfigMap.put(sceneID, sceneSpecNew);
                            }
                            deviceStateUpdates.add(new DeviceStateUpdateImpl(DeviceStateUpdate.UPDATE_SCENE_CONFIG, new Short[] { sceneID, (short) -1 }));
                        }
                    }
                } catch (NumberFormatException e) {
                // ignore
                }
            }
        }
    }
}
Also used : DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl) JSONDeviceSceneSpecImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.JSONDeviceSceneSpecImpl)

Aggregations

JSONDeviceSceneSpecImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.JSONDeviceSceneSpecImpl)3 JsonObject (com.google.gson.JsonObject)1 DeviceStateUpdateImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)1