Package org.openhab.binding.digitalstrom.internal.client.entity

Examples of org.openhab.binding.digitalstrom.internal.client.entity.Device


        if (needsUpdate) {
          logger.debug("item '{}' is about to be refreshed now",
              itemName);

          Device device = getDsidToDeviceMap().get(
              itemConf.dsid.getValue());
          if (device != null) {
            SensorIndexEnum sensorIndex = null;
            try {
              sensorIndex = SensorIndexEnum
View Full Code Here


        DigitalSTROMBindingConfig confItem = getConfigForItemName(itemName);
        if (confItem != null && confItem.dsid != null) {
          if (rawDsidToDeviceMap.size() == 0 && serverIsFound()) {
            rawDsidToDeviceMap = getAllDigitalSTROMDevicesMap();
          }
          Device device = rawDsidToDeviceMap.get(confItem.dsid.getValue());
          if (device != null) {
            addDevice(itemName, device);
            updateItemState(confItem.item);
            handleStructure(digitalSTROM
                .getApartmentStructure(getSessionToken()));
View Full Code Here

    }
    return null;
  }

  private void deviceCall(String itemName, Command cm) {
    Device device = deviceMap.get(itemName);

    if (device != null) {
      if (cm instanceof org.openhab.core.library.types.OnOffType) {

        if (((org.openhab.core.library.types.OnOffType) cm)
            .equals(OnOffType.ON)) {

          boolean transmitted = digitalSTROM.turnDeviceOn(
              getSessionToken(), device.getDSID(), null);
          if (transmitted) {
            device.setOutputValue(device.getMaxOutPutValue());
            addEcho(device.getDSID().getValue(),
                (short) ZoneSceneEnum.MAXIMUM.getSceneNumber());
          }

        } else if (((org.openhab.core.library.types.OnOffType) cm)
            .equals(OnOffType.OFF)) {

          boolean transmitted = digitalSTROM.turnDeviceOff(
              getSessionToken(), device.getDSID(), null);
          if (transmitted) {
            device.setOutputValue(0);
            addEcho(device.getDSID().getValue(),
                (short) ZoneSceneEnum.MINIMUM.getSceneNumber());
          }

        }

      } else if (cm instanceof org.openhab.core.library.types.IncreaseDecreaseType) {

        if (!device.isDimmable()) {
          logger.warn("device is not in dimm mode: " + itemName
              + " outputMode: "
              + device.getOutputMode().getMode());
          return;
        }

        if (((org.openhab.core.library.types.IncreaseDecreaseType) cm)
            .equals(IncreaseDecreaseType.INCREASE)) {

          boolean transmitted = digitalSTROM.callDeviceScene(
              getSessionToken(), device.getDSID(), null,
              ZoneSceneEnum.INCREMENT, false);
          if (transmitted) {
            addEcho(device.getDSID().getValue(),
                (short) ZoneSceneEnum.INCREMENT
                    .getSceneNumber());

            if (device.getOutputValue() == 0) {
              initDeviceOutputValue(device,
                  DeviceConstants.DEVICE_SENSOR_OUTPUT);
            } else {
              device.increase();
            }
          } else {
            logger.error("transmitting increase command FAILED "
                + itemName);
          }

        } else if (((org.openhab.core.library.types.IncreaseDecreaseType) cm)
            .equals(IncreaseDecreaseType.DECREASE)) {

          boolean transmitted = digitalSTROM.callDeviceScene(
              getSessionToken(), device.getDSID(), null,
              ZoneSceneEnum.DECREMENT, false);
          if (transmitted) {
            addEcho(device.getDSID().getValue(),
                (short) ZoneSceneEnum.DECREMENT
                    .getSceneNumber());
            device.decrease();
          } else {
            logger.error("transmitting decrease command FAILED "
                + itemName);
          }
        }

      } else if (cm instanceof org.openhab.core.library.types.PercentType) {
        int percent = -1;
        try {
          percent = (int) Float.parseFloat(cm.toString());
        } catch (java.lang.NumberFormatException e) {
          logger.error("NumberFormatException on a PercentType with command: "
              + cm.toString());
        }
        if (percent != -1) {
          if (percent > -1 && percent < 101) {

            if (device.getOutputMode().equals(OutputModeEnum.SLAT)) {

              DigitalSTROMBindingConfig confItem = getConfigForItemName(itemName);
              if (confItem != null) {

                if (confItem.context != null
                    && confItem.context
                        .equals(ContextConfig.slat)) {

                  int old = device.getSlatPosition();
                  device.setSlatPosition(fromPercentToValue(
                      percent,
                      device.getMaxSlatPosition()));

                  boolean transmitted = digitalSTROM
                      .setDeviceOutputValue(
                          getSessionToken(),
                          device.getDSID(),
                          null,
                          DeviceConstants.DEVICE_SENSOR_SLAT_OUTPUT,
                          fromPercentToValue(
                              percent,
                              device.getMaxSlatPosition()));
                  if (!transmitted) {
                    device.setSlatPosition(old);
                    logger.error("could NOT successfully set new value for slats ..."
                        + cm.toString());
                  }
                } else {

                  int old = device.getOutputValue();

                  device.setOutputValue(fromPercentToValue(
                      percent, device.getMaxOutPutValue()));

                  boolean transmitted = digitalSTROM
                      .setDeviceValue(
                          getSessionToken(),
                          device.getDSID(),
                          null,
                          fromPercentToValue(
                              percent,
                              device.getMaxOutPutValue()));
                  if (!transmitted) {
                    device.setOutputValue(old);
                    logger.error("could NOT successfully set new value ..."
                        + cm.toString());
                  }

                }
              }

            } else {

              int old = device.getOutputValue();

              device.setOutputValue(fromPercentToValue(percent,
                  device.getMaxOutPutValue()));

              boolean transmitted = digitalSTROM.setDeviceValue(
                  getSessionToken(),
                  device.getDSID(),
                  null,
                  fromPercentToValue(percent,
                      device.getMaxOutPutValue()));
              if (!transmitted) {
                device.setOutputValue(old);
                logger.error("could NOT successfully set new value ..."
                    + cm.toString());
              }

            }
          }
        }
      } else if (cm instanceof org.openhab.core.library.types.StopMoveType) {

        if (device.getOutputMode().equals(OutputModeEnum.SLAT)) {

          DigitalSTROMBindingConfig confItem = getConfigForItemName(itemName);
          if (confItem != null) {
            if (confItem.context != null
                && confItem.context.equals(ContextConfig.slat)) {
              logger.warn("stop and move command NOT possible for slats, use PercentType command or up and down please");
            } else {
              handleStopMoveForRollershutter(device, cm);
            }
          }
        } else if (device.getOutputMode()
            .equals(OutputModeEnum.UP_DOWN)) {
          handleStopMoveForRollershutter(device, cm);
        }
      } else if (cm instanceof org.openhab.core.library.types.UpDownType) {

        if (device.getOutputMode().equals(OutputModeEnum.SLAT)) {

          // 255 is max open, 0 is closed
          DigitalSTROMBindingConfig confItem = getConfigForItemName(itemName);
          if (confItem != null) {

            if (confItem.context != null
                && confItem.context.equals(ContextConfig.slat)) {

              if (((org.openhab.core.library.types.UpDownType) cm)
                  .equals(UpDownType.UP)) {

                int slatPosition = device.getSlatPosition();
                int newPosition = slatPosition
                    + DeviceConstants.MOVE_STEP_SLAT;
                if (newPosition > device.getMaxSlatPosition()) {
                  newPosition = device.getMaxSlatPosition();
                }

                boolean transmitted = digitalSTROM
                    .setDeviceOutputValue(
                        getSessionToken(),
                        device.getDSID(),
                        null,
                        DeviceConstants.DEVICE_SENSOR_SLAT_OUTPUT,
                        newPosition);
                if (transmitted) {
                  device.setSlatPosition(newPosition);
                }

              } else if (((org.openhab.core.library.types.UpDownType) cm)
                  .equals(UpDownType.DOWN)) {

                int slatPosition = device.getSlatPosition();
                int newPosition = slatPosition
                    - DeviceConstants.MOVE_STEP_SLAT;
                if (newPosition < device.getMinSlatPosition()) {
                  newPosition = device.getMinSlatPosition();
                }
                boolean transmitted = digitalSTROM
                    .setDeviceOutputValue(
                        getSessionToken(),
                        device.getDSID(),
                        null,
                        DeviceConstants.DEVICE_SENSOR_SLAT_OUTPUT,
                        newPosition);

                if (transmitted) {
                  device.setSlatPosition(newPosition);
                }
              }
            } else {
              handleUpDownForRollershutter(device, cm);
            }
          }

        } else if (device.getOutputMode()
            .equals(OutputModeEnum.UP_DOWN)) {
          handleUpDownForRollershutter(device, cm);
        } else {
          logger.warn("Wrong item configuration ... this hardware is not a rollershutter: "
              + itemName);
View Full Code Here

    if (groupId == 0) {
      Map<String, Device> clonedDeviceMap = getDsidToDeviceMap();
      Set<String> dsidSet = clonedDeviceMap.keySet();

      for (String dsid : dsidSet) {
        Device device = clonedDeviceMap.get(dsid);

        if (device != null) {

          if (!device.containsSceneConfig(sceneId)) {
            getSceneSpec(device, sceneId);
          }

          if (!device.doIgnoreScene(sceneId)) {
            short output = device.getSceneOutputValue(sceneId);
            if (output != -1) {
              device.setOutputValue(output);
            } else {
              initDeviceOutputValue(device,
                  DeviceConstants.DEVICE_SENSOR_OUTPUT);
              initSceneOutputValue(device, sceneId);
            }
          }
        }
      }
    } else if (groupId != -1) {

      Map<String, Device> clonedDeviceMap = getDsidToDeviceMap();
      Map<Short, List<String>> map = getDigitalSTROMZoneGroupMap().get(0);
      List<String> dsidList = map.get(groupId);

      if (dsidList != null) {
        for (String dsid : dsidList) {
          Device device = clonedDeviceMap.get(dsid);

          if (device != null) {

            if (!device.containsSceneConfig(sceneId)) {
              getSceneSpec(device, sceneId);
            }

            if (!device.doIgnoreScene(sceneId)) {
              short output = device.getSceneOutputValue(sceneId);
              if (output != -1) {
                device.setOutputValue(output);
              } else {
                initDeviceOutputValue(device,
                    DeviceConstants.DEVICE_SENSOR_OUTPUT);
                initSceneOutputValue(device, sceneId);
              }
View Full Code Here

        if (!isEcho(dsidStr, sceneId)) {

          if (isDeviceCall) {

            if (dsidStr != null) {
              Device device = getDsidToDeviceMap().get(dsidStr);

              if (device != null) {
                if (!device.containsSceneConfig(sceneId)) {
                  getSceneSpec(device, sceneId);
                }

                if (isDimmScene(sceneId)) {
                  if (!device.doIgnoreScene(sceneId)) {
                    handleDimmScene(device, sceneId,
                        (short) -1, true);
                  }
                } else if (stateMapper.isMappable(sceneId)) {
                  boolean shouldBeOn = stateMapper
                      .getMapping(sceneId);

                  if (!device.doIgnoreScene(sceneId)) {
                    if (shouldBeOn) {
                      device.setOutputValue(device
                          .getMaxOutPutValue());
                    } else {
                      device.setOutputValue(0);
                    }
                  }
                } else {
                  if (!device.doIgnoreScene(sceneId)) {
                    short value = device
                        .getSceneOutputValue(sceneId);
                    if (value != -1) {
                      device.setOutputValue(value);
                    } else {
                      initDeviceOutputValue(
                          device,
                          DeviceConstants.DEVICE_SENSOR_OUTPUT);
                      initSceneOutputValue(device,
                          sceneId);
                    }
                  }
                }
              }
            }
          } else {

            if (isApartmentScene(sceneId)) {
              handleApartmentScene(sceneId, groupId);
            } else {

              if (zoneId == 0) {
                if (isDimmScene(sceneId)) {

                  Map<String, Device> deviceMap = getDsidToDeviceMap();

                  if (groupId == 0) {

                    Set<String> dsidSet = deviceMap
                        .keySet();

                    if (dsidSet != null) {
                      for (String dsid : dsidSet) {
                        Device device = deviceMap
                            .get(dsid);

                        if (device != null) {

                          if (!device
                              .containsSceneConfig(sceneId)) {
                            getSceneSpec(device,
                                sceneId);
                          }

                          if (!device
                              .doIgnoreScene(sceneId)) {
                            handleDimmScene(
                                deviceMap
                                    .get(dsid),
                                sceneId,
                                groupId, false);
                          }

                        }
                      }
                    }
                  } else if (groupId != -1) {

                    Map<Short, List<String>> map = getDigitalSTROMZoneGroupMap()
                        .get(zoneId);

                    if (map != null) {
                      List<String> dsidList = map
                          .get(groupId);
                      if (dsidList != null) {
                        for (String dsid : dsidList) {
                          Device device = deviceMap
                              .get(dsid);

                          if (device != null) {

                            if (!device
                                .containsSceneConfig(sceneId)) {
                              getSceneSpec(
                                  device,
                                  sceneId);
                            }

                            if (!device
                                .doIgnoreScene(sceneId)) {
                              handleDimmScene(
                                  deviceMap
                                      .get(dsid),
                                  sceneId,
                                  groupId,
                                  false);
                            }
                          }
                        }
                      }
                    }
                  }
                } else if (stateMapper.isMappable(sceneId)) {

                  boolean shouldBeOn = stateMapper
                      .getMapping(sceneId);

                  if (groupId == 0) {

                    Map<String, Device> deviceMap = getDsidToDeviceMap();
                    Set<String> dsidSet = deviceMap
                        .keySet();
                    if (dsidSet != null) {
                      for (String dsid : dsidSet) {
                        Device device = deviceMap
                            .get(dsid);
                        if (device != null) {

                          if (!device
                              .containsSceneConfig(sceneId)) {
                            getSceneSpec(device,
                                sceneId);
                          }

                          if (!device
                              .doIgnoreScene(sceneId)) {

                            if (shouldBeOn) {
                              device.setOutputValue(device
                                  .getMaxOutPutValue());
                            } else {
                              device.setOutputValue(0);
                            }

                          }
                        }
                      }
                    }
                  } else if (groupId != -1) {

                    Map<Short, List<String>> map = getDigitalSTROMZoneGroupMap()
                        .get(zoneId);
                    Map<String, Device> deviceMap = getDsidToDeviceMap();
                    if (map != null) {
                      List<String> dsidList = map
                          .get(groupId);
                      if (dsidList != null) {
                        for (String dsid : dsidList) {
                          Device device = deviceMap
                              .get(dsid);
                          if (device != null) {

                            if (!device
                                .containsSceneConfig(sceneId)) {
                              getSceneSpec(
                                  device,
                                  sceneId);
                            }

                            if (!device
                                .doIgnoreScene(sceneId)) {

                              if (shouldBeOn) {
                                device.setOutputValue(device
                                    .getMaxOutPutValue());
                              } else {
                                device.setOutputValue(0);
                              }

                            }
                          }
                        }
                      }
                    }
                  }
                } else {

                  Map<String, Device> deviceMap = getDsidToDeviceMap();

                  if (groupId != -1) {
                    Map<Short, List<String>> map = getDigitalSTROMZoneGroupMap()
                        .get(zoneId);
                    if (map != null) {
                      List<String> dsidList = map
                          .get(groupId);
                      if (dsidList != null) {
                        for (String dsid : dsidList) {
                          Device device = deviceMap
                              .get(dsid);

                          if (device != null) {

                            if (!device
                                .containsSceneConfig(sceneId)) {
                              getSceneSpec(
                                  device,
                                  sceneId);
                            }

                            if (!device
                                .doIgnoreScene(sceneId)) {
                              short sceneValue = device
                                  .getSceneOutputValue(sceneId);
                              if (sceneValue == -1) {
                                initDeviceOutputValue(
                                    device,
                                    DeviceConstants.DEVICE_SENSOR_OUTPUT);
                                initSceneOutputValue(
                                    device,
                                    sceneId);
                              } else {
                                device.setOutputValue(sceneValue);
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }

              else {

                if (isDimmScene(sceneId)) {

                  if (groupId != -1) {
                    Map<Short, List<String>> map = getDigitalSTROMZoneGroupMap()
                        .get(zoneId);
                    if (map != null) {
                      List<String> devicesInGroup = map
                          .get(groupId);
                      if (devicesInGroup != null) {
                        Map<String, Device> deviceMap = getDsidToDeviceMap();

                        for (String dsid : devicesInGroup) {
                          Device device = deviceMap
                              .get(dsid);

                          if (device != null) {

                            if (!device
                                .containsSceneConfig(sceneId)) {
                              getSceneSpec(
                                  device,
                                  sceneId);
                            }

                            if (!device
                                .doIgnoreScene(sceneId)) {
                              handleDimmScene(
                                  deviceMap
                                      .get(dsid),
                                  sceneId,
                                  groupId,
                                  false);
                            }

                          }
                        }
                      }
                    }
                  }
                } else if (stateMapper.isMappable(sceneId)) {

                  boolean shouldBeOn = stateMapper
                      .getMapping(sceneId);
                  Map<Short, List<String>> map = getDigitalSTROMZoneGroupMap()
                      .get(zoneId);
                  Map<String, Device> deviceMap = getDsidToDeviceMap();

                  if (map != null) {

                    if (groupId != -1) {
                      List<String> devicesInGroup = map
                          .get(groupId);
                      if (devicesInGroup != null) {
                        for (String dsid : devicesInGroup) {
                          Device device = deviceMap
                              .get(dsid);

                          if (device != null) {
                            if (!device
                                .containsSceneConfig(sceneId)) {
                              getSceneSpec(
                                  device,
                                  sceneId);
                            }

                            if (!device
                                .doIgnoreScene(sceneId)) {
                              if (shouldBeOn) {
                                device.setOutputValue(device
                                    .getMaxOutPutValue());
                              } else {
                                device.setOutputValue(0);
                              }
                            }

                          }
                        }
                      }
                    }
                  }
                } else {

                  Map<Short, List<String>> map = getDigitalSTROMZoneGroupMap()
                      .get(zoneId);
                  Map<String, Device> deviceMap = getDsidToDeviceMap();
                  if (map != null) {

                    if (groupId != -1) {
                      List<String> devicesInGroup = map
                          .get(groupId);
                      if (devicesInGroup != null) {
                        for (String dsid : devicesInGroup) {
                          Device device = deviceMap
                              .get(dsid);
                          if (device != null) {

                            if (!device
                                .containsSceneConfig(sceneId)) {
                              getSceneSpec(
                                  device,
                                  sceneId);
                            }

                            if (!device
                                .doIgnoreScene(sceneId)) {
                              short outputValue = device
                                  .getSceneOutputValue(sceneId);
                              if (outputValue == -1) {
                                initDeviceOutputValue(
                                    device,
                                    DeviceConstants.DEVICE_SENSOR_OUTPUT);
                                initSceneOutputValue(
                                    device,
                                    sceneId);
                              } else {
                                device.setOutputValue(outputValue);
                              }
                            }

                          }
                        }
View Full Code Here

    }
  }

  private void updateItemState(Item item) {
    if (item != null) {
      Device device = deviceMap.get(item.getName());

      if (device != null) {

        State state = null;
        if (item instanceof DimmerItem) {
          state = new PercentType(
              getPercent(device.getMaxOutPutValue(),
                  device.getOutputValue()));

        } else if (item instanceof SwitchItem
            && !(item instanceof DimmerItem)) {

          state = device.getOutputValue() > 0 ? OnOffType.ON
              : OnOffType.OFF;
        } else if (item instanceof NumberItem) {

          DigitalSTROMBindingConfig confItem = getConfigForItemName(item
              .getName());
          if (confItem != null) {
            if (confItem.consumption != null) {

              int value = -1;
              switch (confItem.consumption) {

              case ACTIVE_POWER:
                value = device.getPowerConsumption();

                if (value != -1) {
                  state = new DecimalType(value);
                }
                break;
              case OUTPUT_CURRENT:
                value = device.getEnergyMeterValue();

                if (value != -1) {
                  state = new DecimalType(value);
                }
                break;
              default:
                break;

              }
            }
          }
        } else if (item instanceof RollershutterItem) {

          DigitalSTROMBindingConfig confItem = getConfigForItemName(item
              .getName());
          if (confItem != null) {

            if (confItem.context != null
                && confItem.context.equals(ContextConfig.slat)) {

              int output = getPercent(
                  device.getMaxSlatPosition(),
                  device.getSlatPosition());

              state = new PercentType(100 - output);
            } else if (confItem.context != null
                && confItem.context
                    .equals(ContextConfig.awning)) {

              int output = getPercent(device.getMaxOutPutValue(),
                  device.getOutputValue());

              state = new PercentType(output);
            } else {
              int output = getPercent(device.getMaxOutPutValue(),
                  device.getOutputValue());

              state = new PercentType(100 - output);
            }
          }
        } else if (item instanceof StringItem) {
          DigitalSTROMBindingConfig confItem = getConfigForItemName(item
              .getName());
          if (confItem != null) {

            if (confItem.consumption != null) {
              int value = -1;

              switch (confItem.consumption) {

              case ACTIVE_POWER:
                value = device.getPowerConsumption();

                if (value != -1) {
                  state = new DecimalType(value);
                }
                break;
              case OUTPUT_CURRENT:
                value = device.getEnergyMeterValue();

                if (value != -1) {
                  state = new DecimalType(value);
                }
                break;
View Full Code Here

  @Override
  public void bindingChanged(BindingProvider provider, String itemName) {
    if(provider instanceof DigitalSTROMBindingProvider){
      //remove device associated with the item
      Device device = deviceMap.get(itemName);
      if (device != null) {
        List<String> itemNamesForDsid = getItemNamesForDsid(device
            .getDSID().getValue());
        if (itemNamesForDsid.size() == 1) {
          device.removeDeviceListener(this);
          removeSensorJobs(device.getDSID());
        }
      }
      deviceMap.remove(itemName);
     
      //initialize the device
View Full Code Here

  }
 
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof Device) {
      Device device = (Device)obj;
      return device.getDSID().equals(this.getDSID());
    }
    return false;
  }
View Full Code Here

TOP

Related Classes of org.openhab.binding.digitalstrom.internal.client.entity.Device

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.