예제 #1
0
  private void readOutputValue(Device device) {
    short outputIndex = DeviceConstants.DEVICE_SENSOR_OUTPUT;
    if (device.isShade()) {
      outputIndex = DeviceConstants.DEVICE_SENSOR_SLAT_POSITION_OUTPUT;
    }

    int outputValue =
        this.digitalSTROMClient.getDeviceOutputValue(
            connMan.getSessionToken(), device.getDSID(), null, outputIndex);
    if (outputValue != -1) {
      if (!device.isShade()) {
        device.updateInternalDeviceState(
            new DeviceStateUpdateImpl(DeviceStateUpdate.UPDATE_BRIGHTNESS, outputValue));
      } else {
        device.updateInternalDeviceState(
            new DeviceStateUpdateImpl(DeviceStateUpdate.UPDATE_SLATPOSITION, outputValue));
        if (device.isBlind()) {
          outputValue =
              this.digitalSTROMClient.getDeviceOutputValue(
                  connMan.getSessionToken(),
                  device.getDSID(),
                  null,
                  DeviceConstants.DEVICE_SENSOR_SLAT_ANGLE_OUTPUT);
          device.updateInternalDeviceState(
              new DeviceStateUpdateImpl(DeviceStateUpdate.UPDATE_SLAT_ANGLE, outputValue));
        }
      }
    }
  }
예제 #2
0
 private void init(
     ConnectionManager connMan,
     StructureManager strucMan,
     SceneManager sceneMan,
     ManagerStatusListener statusListener) {
   this.connMan = connMan;
   this.digitalSTROMClient = connMan.getDigitalSTROMAPI();
   this.config = connMan.getConfig();
   if (strucMan != null) {
     this.strucMan = strucMan;
   } else {
     this.strucMan = new StructureManagerImpl();
   }
   if (sceneMan != null) {
     this.sceneMan = sceneMan;
   } else {
     this.sceneMan = new SceneManagerImpl(connMan, strucMan, statusListener);
   }
   this.statusListener = statusListener;
 }
예제 #3
0
 @Override
 public int getTotalEnergyMeterValue() {
   List<CachedMeteringValue> cachedEnergyMeteringValues =
       digitalSTROMClient.getLatest(
           connMan.getSessionToken(), MeteringTypeEnum.energy, meters, MeteringUnitsEnum.Wh);
   if (cachedEnergyMeteringValues != null) {
     tempEnergyMeter = 0;
     for (CachedMeteringValue value : cachedEnergyMeteringValues) {
       tempEnergyMeter += value.getValue();
     }
     if (tempEnergyMeter != totalEnergyMeter) {
       totalEnergyMeter = tempEnergyMeter;
     }
   }
   return totalEnergyMeter;
 }
예제 #4
0
 @Override
 public int getTotalPowerConsumption() {
   List<CachedMeteringValue> cachedConsumptionMeteringValues =
       digitalSTROMClient.getLatest(
           connMan.getSessionToken(), MeteringTypeEnum.consumption, meters, MeteringUnitsEnum.W);
   if (cachedConsumptionMeteringValues != null) {
     tempConsumption = 0;
     for (CachedMeteringValue value : cachedConsumptionMeteringValues) {
       tempConsumption += value.getValue();
     }
     if (tempConsumption != totalPowerConsumption) {
       totalPowerConsumption = tempConsumption;
     }
   }
   return totalPowerConsumption;
 }
예제 #5
0
 @Override
 public synchronized void sendComandsToDSS(Device device, DeviceStateUpdate deviceStateUpdate) {
   if (connMan.checkConnection()) {
     boolean requestSuccsessful = false;
     boolean commandHaveNoEffect = false;
     if (deviceStateUpdate != null) {
       switch (deviceStateUpdate.getType()) {
         case DeviceStateUpdate.UPDATE_BRIGHTNESS_DECREASE:
         case DeviceStateUpdate.UPDATE_SLAT_DECREASE:
           if (checkIsAllreadyMinMax(device) != 0) {
             requestSuccsessful =
                 digitalSTROMClient.decreaseValue(connMan.getSessionToken(), device.getDSID());
             if (requestSuccsessful) {
               sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.DECREMENT.getSceneNumber());
             }
           } else {
             commandHaveNoEffect = true;
           }
           break;
         case DeviceStateUpdate.UPDATE_BRIGHTNESS_INCREASE:
         case DeviceStateUpdate.UPDATE_SLAT_INCREASE:
           if (checkIsAllreadyMinMax(device) != 1) {
             requestSuccsessful =
                 digitalSTROMClient.increaseValue(connMan.getSessionToken(), device.getDSID());
             if (requestSuccsessful) {
               sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.INCREMENT.getSceneNumber());
             }
           } else {
             commandHaveNoEffect = true;
           }
           break;
         case DeviceStateUpdate.UPDATE_BRIGHTNESS:
           if (device.getOutputValue() != deviceStateUpdate.getValue()) {
             requestSuccsessful =
                 digitalSTROMClient.setDeviceValue(
                     connMan.getSessionToken(),
                     device.getDSID(),
                     null,
                     deviceStateUpdate.getValue());
           } else {
             commandHaveNoEffect = true;
           }
           break;
         case DeviceStateUpdate.UPDATE_OPEN_CLOSE:
         case DeviceStateUpdate.UPDATE_ON_OFF:
           if (deviceStateUpdate.getValue() > 0) {
             if (checkIsAllreadyMinMax(device) != 1) {
               requestSuccsessful =
                   digitalSTROMClient.turnDeviceOn(
                       connMan.getSessionToken(), device.getDSID(), null);
               if (requestSuccsessful) {
                 sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.MAXIMUM.getSceneNumber());
               }
             } else {
               commandHaveNoEffect = true;
             }
           } else {
             if (checkIsAllreadyMinMax(device) != 0) {
               requestSuccsessful =
                   digitalSTROMClient.turnDeviceOff(
                       connMan.getSessionToken(), device.getDSID(), null);
               if (requestSuccsessful) {
                 sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.MINIMUM.getSceneNumber());
               }
               if (sensorJobExecutor != null) {
                 sensorJobExecutor.removeSensorJobs(device);
               }
             } else {
               commandHaveNoEffect = true;
             }
           }
           break;
         case DeviceStateUpdate.UPDATE_SLATPOSITION:
           if (device.getSlatPosition() != deviceStateUpdate.getValue()) {
             requestSuccsessful =
                 digitalSTROMClient.setDeviceOutputValue(
                     connMan.getSessionToken(),
                     device.getDSID(),
                     null,
                     DeviceConstants.DEVICE_SENSOR_SLAT_POSITION_OUTPUT,
                     deviceStateUpdate.getValue());
           } else {
             commandHaveNoEffect = true;
           }
           break;
         case DeviceStateUpdate.UPDATE_SLAT_STOP:
           this.sendStopComandsToDSS(device);
           break;
         case DeviceStateUpdate.UPDATE_SLAT_MOVE:
           if (deviceStateUpdate.getValue() > 0) {
             requestSuccsessful =
                 digitalSTROMClient.turnDeviceOn(
                     connMan.getSessionToken(), device.getDSID(), null);
             if (requestSuccsessful) {
               sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.MAXIMUM.getSceneNumber());
             }
           } else {
             requestSuccsessful =
                 digitalSTROMClient.turnDeviceOff(
                     connMan.getSessionToken(), device.getDSID(), null);
             if (requestSuccsessful) {
               sceneMan.addEcho(device.getDSID().getValue(), SceneEnum.MINIMUM.getSceneNumber());
             }
             if (sensorJobExecutor != null) {
               sensorJobExecutor.removeSensorJobs(device);
             }
           }
           break;
         case DeviceStateUpdate.UPDATE_CALL_SCENE:
           if (SceneEnum.getScene((short) deviceStateUpdate.getValue()) != null) {
             requestSuccsessful =
                 digitalSTROMClient.callDeviceScene(
                     connMan.getSessionToken(),
                     device.getDSID(),
                     null,
                     SceneEnum.getScene((short) deviceStateUpdate.getValue()),
                     true);
           }
           break;
         case DeviceStateUpdate.UPDATE_UNDO_SCENE:
           if (SceneEnum.getScene((short) deviceStateUpdate.getValue()) != null) {
             requestSuccsessful =
                 digitalSTROMClient.undoDeviceScene(
                     connMan.getSessionToken(),
                     device.getDSID(),
                     SceneEnum.getScene((short) deviceStateUpdate.getValue()));
           }
           break;
         case DeviceStateUpdate.UPDATE_ACTIVE_POWER:
           if (deviceStateUpdate.getValue() == 0) {
             logger.debug("Device need active power SensorData update");
             updateSensorData(
                 new DeviceConsumptionSensorJob(device, SensorEnum.ACTIVE_POWER),
                 device.getActivePowerRefreshPriority());
             return;
           } else {
             int consumption =
                 this.digitalSTROMClient.getDeviceSensorValue(
                     connMan.getSessionToken(), device.getDSID(), null, SensorEnum.ACTIVE_POWER);
             if (consumption >= 0) {
               device.updateInternalDeviceState(
                   new DeviceStateUpdateImpl(DeviceStateUpdate.UPDATE_ACTIVE_POWER, consumption));
               requestSuccsessful = true;
             }
           }
         case DeviceStateUpdate.UPDATE_OUTPUT_CURRENT:
           if (deviceStateUpdate.getValue() == 0) {
             logger.debug("Device need output current SensorData update");
             updateSensorData(
                 new DeviceConsumptionSensorJob(device, SensorEnum.OUTPUT_CURRENT),
                 device.getOutputCurrentRefreshPriority());
             return;
           } else {
             int consumption =
                 this.digitalSTROMClient.getDeviceSensorValue(
                     connMan.getSessionToken(), device.getDSID(), null, SensorEnum.OUTPUT_CURRENT);
             if (consumption >= 0) {
               device.updateInternalDeviceState(
                   new DeviceStateUpdateImpl(
                       DeviceStateUpdate.UPDATE_OUTPUT_CURRENT, consumption));
               requestSuccsessful = true;
             }
           }
         case DeviceStateUpdate.UPDATE_ELECTRIC_METER:
           if (deviceStateUpdate.getValue() == 0) {
             logger.debug("Device need electric meter SensorData update");
             updateSensorData(
                 new DeviceConsumptionSensorJob(device, SensorEnum.ELECTRIC_METER),
                 device.getElectricMeterRefreshPriority());
             return;
           } else {
             int consumption =
                 this.digitalSTROMClient.getDeviceSensorValue(
                     connMan.getSessionToken(), device.getDSID(), null, SensorEnum.ELECTRIC_METER);
             if (consumption >= 0) {
               device.updateInternalDeviceState(
                   new DeviceStateUpdateImpl(
                       DeviceStateUpdate.UPDATE_ELECTRIC_METER, consumption));
               requestSuccsessful = true;
             }
           }
         case DeviceStateUpdate.UPDATE_SLAT_ANGLE_DECREASE:
           // By UPDATE_SLAT_ANGLE_DECREASE, UPDATE_SLAT_ANGLE_INCREASE with value unequal 1 which
           // will
           // handle in the pollingRunnable and UPDATE_OPEN_CLOSE_ANGLE the value will be set
           // without
           // checking, because it was triggered by setting the slat position.
           requestSuccsessful = true;
           break;
         case DeviceStateUpdate.UPDATE_SLAT_ANGLE_INCREASE:
           requestSuccsessful = true;
           break;
         case DeviceStateUpdate.UPDATE_OPEN_CLOSE_ANGLE:
           requestSuccsessful = true;
           break;
         case DeviceStateUpdate.UPDATE_SLAT_ANGLE:
           if (device.getAnglePosition() != deviceStateUpdate.getValue()) {
             requestSuccsessful =
                 digitalSTROMClient.setDeviceOutputValue(
                     connMan.getSessionToken(),
                     device.getDSID(),
                     null,
                     DeviceConstants.DEVICE_SENSOR_SLAT_ANGLE_OUTPUT,
                     deviceStateUpdate.getValue());
           } else {
             commandHaveNoEffect = true;
           }
           break;
         case DeviceStateUpdate.REFRESH_OUTPUT:
           readOutputValue(device);
           logger.debug(
               "Inizalize output value reading for device with dSID {}.",
               device.getDSID().getValue());
           return;
         default:
           return;
       }
       if (commandHaveNoEffect) {
         logger.debug(
             "Command {} for device with dSID {} not send to dSS, because it has no effect!",
             deviceStateUpdate.getType(),
             device.getDSID().getValue());
         return;
       }
       if (requestSuccsessful) {
         logger.debug(
             "Send {} command to dSS and updateInternalDeviceState for device with dSID {}.",
             deviceStateUpdate.getType(),
             device.getDSID().getValue());
         device.updateInternalDeviceState(deviceStateUpdate);
       } else {
         logger.debug(
             "Can't send {} command for device with dSID {} to dSS!",
             deviceStateUpdate.getType(),
             device.getDSID().getValue());
       }
     }
   }
 }
예제 #6
0
  @Override
  public synchronized void sendSceneComandsToDSS(InternalScene scene, boolean call_undo) {
    if (scene != null) {
      if (lastSceneCall + 1000 > System.currentTimeMillis()) {
        sleepTime = System.currentTimeMillis() - lastSceneCall;
        try {
          Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
          logger.error("An exception occurred", e);
        }
      }
      if (this.connMan.checkConnection()) {
        lastSceneCall = System.currentTimeMillis();
        boolean requestSuccsessfull = false;
        if (scene.getZoneID() == 0) {
          if (call_undo) {
            logger.debug(
                scene.getGroupID()
                    + " "
                    + scene.getSceneID()
                    + " "
                    + ApartmentSceneEnum.getApartmentScene(scene.getSceneID()));
            requestSuccsessfull =
                this.digitalSTROMClient.callApartmentScene(
                    connMan.getSessionToken(),
                    scene.getGroupID(),
                    null,
                    ApartmentSceneEnum.getApartmentScene(scene.getSceneID()),
                    false);
          } else {
            requestSuccsessfull =
                this.digitalSTROMClient.undoApartmentScene(
                    connMan.getSessionToken(),
                    scene.getGroupID(),
                    null,
                    ApartmentSceneEnum.getApartmentScene(scene.getSceneID()));
          }
        } else {
          if (call_undo) {
            requestSuccsessfull =
                this.digitalSTROMClient.callZoneScene(
                    connMan.getSessionToken(),
                    scene.getZoneID(),
                    null,
                    scene.getGroupID(),
                    null,
                    SceneEnum.getScene(scene.getSceneID()),
                    false);
          } else {
            requestSuccsessfull =
                this.digitalSTROMClient.undoZoneScene(
                    connMan.getSessionToken(),
                    scene.getZoneID(),
                    null,
                    scene.getGroupID(),
                    null,
                    SceneEnum.getScene(scene.getSceneID()));
          }
        }

        logger.debug("Was the scene call succsessful?: " + requestSuccsessfull);
        if (requestSuccsessfull) {
          this.sceneMan.addEcho(scene.getID());
          if (call_undo) {
            scene.activateScene();
          } else {
            scene.deactivateScene();
          }
        }
      }
    }
  }