Example #1
0
  @Override
  public void handleCommand(ChannelUID channelUID, Command command) {

    super.handleCommand(channelUID, command);

    String channelID = channelUID.getId();
    String uid = (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);

    FridgeChannelSelector selector =
        (FridgeChannelSelector) getValueSelectorFromChannelID(channelID);
    JsonElement result = null;

    try {
      if (selector != null) {
        switch (selector) {
          case SUPERCOOL:
            {
              if (command.equals(OnOffType.ON)) {
                result = bridgeHandler.invokeOperation(uid, modelID, "startSuperCooling");
              } else if (command.equals(OnOffType.OFF)) {
                result = bridgeHandler.invokeOperation(uid, modelID, "stopSuperCooling");
              }
              break;
            }
          case START:
            {
              if (command.equals(OnOffType.ON)) {
                result = bridgeHandler.invokeOperation(uid, modelID, "start");
              }
              break;
            }
          default:
            {
              if (!(command instanceof RefreshType)) {
                logger.debug(
                    "{} is a read-only channel that does not accept commands",
                    selector.getChannelID());
              }
            }
        }
      }
      // process result
      if (result != null) {
        logger.debug("Result of operation is {}", result.getAsString());
      }
    } catch (IllegalArgumentException e) {
      logger.warn(
          "An error occurred while trying to set the read-only variable associated with channel '{}' to '{}'",
          channelID,
          command.toString());
    }
  }
  /** {@inheritDoc} */
  @Override
  public void handleCommand(ChannelUID channelUID, Command command) {
    if (dscAlarmBridgeHandler == null) {
      logger.warn("DSC Alarm bridge handler not available. Cannot handle command without bridge.");
      return;
    }

    int cmd;

    boolean connected = dscAlarmBridgeHandler.isConnected();

    if (connected) {
      switch (channelUID.getId()) {
        case PANEL_COMMAND:
          cmd = Integer.parseInt(command.toString());
          switch (cmd) {
            case 0:
              dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.Poll);
              break;
            case 1:
              dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.StatusReport);
              break;
            case 2:
              dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.LabelsRequest);
              break;
            case 8:
              dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.DumpZoneTimers);
              break;
            case 10:
              dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.SetTimeDate);
              break;
            case 200:
              dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.CodeSend, getUserCode());
              break;
            default:
              break;
          }

          updateState(channelUID, new StringType(String.valueOf(-1)));

          break;
        case PANEL_TIME_STAMP:
          if (command instanceof OnOffType) {
            cmd = command == OnOffType.ON ? 1 : 0;
            dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.TimeStampControl, String.valueOf(cmd));
            updateProperties(channelUID, cmd, "");
            updateState(channelUID, (OnOffType) command);
          }
          break;
        case PANEL_TIME_BROADCAST:
          if (command instanceof OnOffType) {
            cmd = command == OnOffType.ON ? 1 : 0;
            dscAlarmBridgeHandler.sendCommand(
                DSCAlarmCode.TimeDateBroadcastControl, String.valueOf(cmd));
            updateProperties(channelUID, cmd, "");
            updateState(channelUID, (OnOffType) command);
          }
          break;
        default:
          break;
      }
    }
  }
 @Override
 public void handleCommand(ChannelUID channelUID, Command command) {
   if (squeezeBoxServerHandler == null) {
     logger.warn("Player has no server configured, ignoring command");
     return;
   }
   String mac = getConfigAs(SqueezeBoxPlayerConfig.class).mac;
   switch (channelUID.getIdWithoutGroup()) {
     case CHANNEL_POWER:
       if (command.equals(OnOffType.ON)) {
         squeezeBoxServerHandler.powerOn(mac);
       } else {
         squeezeBoxServerHandler.powerOff(mac);
       }
       break;
     case CHANNEL_MUTE:
       if (command.equals(OnOffType.ON)) {
         mute();
       } else {
         squeezeBoxServerHandler.unMute(mac, unmuteVolume);
       }
       break;
     case CHANNEL_STOP:
       if (command.equals(OnOffType.ON)) {
         squeezeBoxServerHandler.stop(mac);
       } else if (command.equals(OnOffType.OFF)) {
         squeezeBoxServerHandler.play(mac);
       }
       break;
     case CHANNEL_PLAY_PAUSE:
       if (command.equals(OnOffType.ON)) {
         squeezeBoxServerHandler.play(mac);
       } else if (command.equals(OnOffType.OFF)) {
         squeezeBoxServerHandler.pause(mac);
       }
       break;
     case CHANNEL_PREV:
       if (command.equals(OnOffType.ON)) {
         squeezeBoxServerHandler.prev(mac);
       }
       break;
     case CHANNEL_NEXT:
       if (command.equals(OnOffType.ON)) {
         squeezeBoxServerHandler.next(mac);
       }
       break;
     case CHANNEL_VOLUME:
       if (command instanceof PercentType) {
         squeezeBoxServerHandler.setVolume(mac, ((PercentType) command).intValue());
       } else if (command.equals(IncreaseDecreaseType.INCREASE)) {
         squeezeBoxServerHandler.volumeUp(mac, currentVolume());
       } else if (command.equals(IncreaseDecreaseType.DECREASE)) {
         squeezeBoxServerHandler.volumeDown(mac, currentVolume());
       } else if (command.equals(OnOffType.OFF)) {
         mute();
       } else if (command.equals(OnOffType.ON)) {
         squeezeBoxServerHandler.unMute(mac, unmuteVolume);
       }
       break;
     case CHANNEL_CONTROL:
       if (command instanceof PlayPauseType) {
         if (command.equals(PlayPauseType.PLAY)) {
           squeezeBoxServerHandler.play(mac);
         } else if (command.equals(PlayPauseType.PAUSE)) {
           squeezeBoxServerHandler.pause(mac);
         }
       }
       if (command instanceof NextPreviousType) {
         if (command.equals(NextPreviousType.NEXT)) {
           squeezeBoxServerHandler.next(mac);
         } else if (command.equals(NextPreviousType.PREVIOUS)) {
           squeezeBoxServerHandler.prev(mac);
         }
       }
       if (command instanceof RewindFastforwardType) {
         if (command.equals(RewindFastforwardType.REWIND)) {
           squeezeBoxServerHandler.setPlayingTime(mac, currentTime() - 5);
         } else if (command.equals(RewindFastforwardType.FASTFORWARD)) {
           squeezeBoxServerHandler.setPlayingTime(mac, currentTime() + 5);
         }
       }
       break;
     case CHANNEL_STREAM:
       squeezeBoxServerHandler.playUrl(mac, command.toString());
       break;
     case CHANNEL_SYNC:
       if (StringUtils.isBlank(command.toString())) {
         squeezeBoxServerHandler.unSyncPlayer(mac);
       } else {
         squeezeBoxServerHandler.syncPlayer(mac, command.toString());
       }
     case CHANNEL_UNSYNC:
       if (command.equals(OnOffType.ON)) {
         squeezeBoxServerHandler.unSyncPlayer(mac);
       }
       break;
     case CHANNEL_PLAYLIST_INDEX:
       squeezeBoxServerHandler.playPlaylistItem(mac, ((DecimalType) command).intValue());
       break;
     case CHANNEL_CURRENT_PLAYING_TIME:
       squeezeBoxServerHandler.setPlayingTime(mac, ((DecimalType) command).intValue());
       break;
     case CHANNEL_CURRENT_PLAYLIST_SHUFFLE:
       squeezeBoxServerHandler.setShuffleMode(mac, ((DecimalType) command).intValue());
       break;
     case CHANNEL_CURRENT_PLAYLIST_REPEAT:
       squeezeBoxServerHandler.setRepeatMode(mac, ((DecimalType) command).intValue());
       break;
     default:
       break;
   }
 }
  @Override
  public void handleCommand(ChannelUID channelUID, Command command) {

    String channelID = channelUID.getId();
    TeslaChannelSelector selector = TeslaChannelSelector.getValueSelectorFromChannelID(channelID);

    if (selector != null) {
      try {
        switch (selector) {
          case CHARGE_LIMIT_SOC:
            {
              if (command instanceof PercentType) {
                setChargeLimit(((PercentType) command).intValue());
              } else if (command instanceof OnOffType && command == OnOffType.ON) {
                setChargeLimit(100);
              } else if (command instanceof OnOffType && command == OnOffType.OFF) {
                setChargeLimit(0);
              } else if (command instanceof IncreaseDecreaseType
                  && command == IncreaseDecreaseType.INCREASE) {
                setChargeLimit(Math.min(chargeState.charge_limit_soc + 1, 100));
              } else if (command instanceof IncreaseDecreaseType
                  && command == IncreaseDecreaseType.DECREASE) {
                setChargeLimit(Math.max(chargeState.charge_limit_soc - 1, 0));
              }
              break;
            }
          case TEMPERATURE:
            {
              if (command instanceof DecimalType) {
                setTemperature(((DecimalType) command).floatValue());
              }
              break;
            }
          case SUN_ROOF_STATE:
            {
              if (command instanceof StringType) {
                setSunroof(command.toString());
              }
              break;
            }
          case SUN_ROOF:
            {
              if (command instanceof PercentType) {
                moveSunroof(((PercentType) command).intValue());
              } else if (command instanceof OnOffType && command == OnOffType.ON) {
                moveSunroof(100);
              } else if (command instanceof OnOffType && command == OnOffType.OFF) {
                moveSunroof(0);
              } else if (command instanceof IncreaseDecreaseType
                  && command == IncreaseDecreaseType.INCREASE) {
                moveSunroof(Math.min(chargeState.charge_limit_soc + 1, 100));
              } else if (command instanceof IncreaseDecreaseType
                  && command == IncreaseDecreaseType.DECREASE) {
                moveSunroof(Math.max(chargeState.charge_limit_soc - 1, 0));
              }
              break;
            }
          case CHARGE_TO_MAX:
            {
              if (command instanceof OnOffType) {
                if (((OnOffType) command) == OnOffType.ON) {
                  setMaxRangeCharging(true);
                } else {
                  setMaxRangeCharging(false);
                }
              }
              break;
            }
          case CHARGE:
            {
              if (command instanceof OnOffType) {
                if (((OnOffType) command) == OnOffType.ON) {
                  charge(true);
                } else {
                  charge(false);
                }
              }
              break;
            }
          case FLASH:
            {
              if (command instanceof OnOffType) {
                if (((OnOffType) command) == OnOffType.ON) {
                  flashLights();
                }
              }
              break;
            }
          case HONK_HORN:
            {
              if (command instanceof OnOffType) {
                if (((OnOffType) command) == OnOffType.ON) {
                  honkHorn();
                }
              }
              break;
            }
          case CHARGEPORT:
            {
              if (command instanceof OnOffType) {
                if (((OnOffType) command) == OnOffType.ON) {
                  openChargePort();
                }
              }
              break;
            }
          case DOOR_LOCK:
            {
              if (command instanceof OnOffType) {
                if (((OnOffType) command) == OnOffType.ON) {
                  lockDoors(true);
                } else {
                  lockDoors(false);
                }
              }
              break;
            }
          case AUTO_COND:
            {
              if (command instanceof OnOffType) {
                if (((OnOffType) command) == OnOffType.ON) {
                  autoConditioning(true);
                } else {
                  autoConditioning(false);
                }
              }
              break;
            }
          default:
            break;
        }
        return;
      } catch (IllegalArgumentException e) {
        logger.warn(
            "An error occurred while trying to set the read-only variable associated with channel '{}' to '{}'",
            channelID,
            command.toString());
      }
    }
  }