gt:         for (SubType s : SubType.values()) {
context: /**
   * Copyright (c) 2010-2016 by the respective copyright holders.
   *
   * All rights reserved. This program and the accompanying materials
   * are made available under the terms of the Eclipse Public License v1.0
   * which accompanies this distribution, and is available at
   * http://www.eclipse.org/legal/epl-v10.html
   */
  package org.openhab.binding.rfxcom.internal.messages;
  
  import java.util.Arrays;
  import java.util.List;
  
  import javax.xml.bind.DatatypeConverter;
  
  import org.openhab.binding.rfxcom.RFXComValueSelector;
  import org.openhab.binding.rfxcom.internal.RFXComException;
  import org.openhab.core.library.items.NumberItem;
  import org.openhab.core.library.items.StringItem;
  import org.openhab.core.library.types.DecimalType;
  import org.openhab.core.library.types.StringType;
  import org.openhab.core.types.State;
  import org.openhab.core.types.Type;
  import org.openhab.core.types.UnDefType;
  
  public class RFXComChimeMessage extends RFXComBaseMessage {
      /*
       * Chime packet layout (length 7) - CHIME
       * packetlength = 0
       * packettype = 1
       * subtype = 2
       * seqnbr = 3
       * id_1 = 4
       * id_2 = 5
       * sound = 6
       * battery_level = 7 //bits 3-0
       * signal_level = 7 //bits 7-4
       */
  
      public enum SubType {
          BYRONSX(0),
          BYRONMP001(1),
          SELECTPLUS(2),
          SELECTPLUS3(3),
          ENVIVO(4),
  
          UNKNOWN(255);
  
          private final int subType;
  
          SubType(int subType) {
              this.subType = subType;
          }
  
          SubType(byte subType) {
              this.subType = subType;
          }
  
          public byte toByte() {
              return (byte) subType;
          }
      }
  
      private final static List<RFXComValueSelector> supportedValueSelectors = Arrays.asList(RFXComValueSelector.RAW_DATA,
              RFXComValueSelector.SIGNAL_LEVEL, RFXComValueSelector.BATTERY_LEVEL, RFXComValueSelector.CHIME_SOUND);
  
      public SubType subType = SubType.BYRONSX;
      public int sensorId = 0;
      public int chimeSound = 0;
      public byte signalLevel = 0;
      public byte batteryLevel = 0;
  
      public RFXComChimeMessage() {
          packetType = PacketType.CHIME;
      }
  
      public RFXComChimeMessage(byte[] data) {
          encodeMessage(data);
      }
  
      @Override
      public String toString() {
          String str = "";
  
          str += super.toString();
          str += "\n - Sub type = " + subType;
          str += "\n - Id = " + sensorId;
          str += "\n - Chime Sound = " + chimeSound;
          str += "\n - Signal level = " + signalLevel;
          str += "\n - Battery level = " + batteryLevel;
  
          return str;
      }
  
      @Override
      public void encodeMessage(byte[] data) {
  
          super.encodeMessage(data);
  
          try {
              subType = SubType.values()[super.subType];
          } catch (Exception e) {
              subType = SubType.UNKNOWN;
          }
  
          sensorId = (data[4] & 0xFF) << 8 | (data[5] & 0xFF);
          chimeSound = (data[6]);
  
          signalLevel = (byte) ((data[7] & 0xF0) >> 4);
          batteryLevel = (byte) (data[7] & 0x0F);
      }
  
      @Override
      public byte[] decodeMessage() {
          byte[] data = new byte[8];
  
          data[0] = 0x07;
          data[1] = RFXComBaseMessage.PacketType.CHIME.toByte();
          data[2] = subType.toByte();
          data[3] = seqNbr;
  
          data[4] = (byte) ((sensorId & 0xFF00) >> 8);
          data[5] = (byte) (sensorId & 0x00FF);
          data[6] = (byte) (chimeSound);
  
          data[7] = (byte) (((signalLevel & 0x0F) << 4) | (batteryLevel & 0x0F));
  
          return data;
      }
  
      @Override
      public String generateDeviceId() {
          return String.valueOf(sensorId);
      }
  
      @Override
      public State convertToState(RFXComValueSelector valueSelector) throws RFXComException {
  
          org.openhab.core.types.State state = UnDefType.UNDEF;
  
          if (valueSelector.getItemClass() == NumberItem.class) {
  
              if (valueSelector == RFXComValueSelector.SIGNAL_LEVEL) {
  
                  state = new DecimalType(signalLevel);
  
              } else if (valueSelector == RFXComValueSelector.BATTERY_LEVEL) {
  
                  state = new DecimalType(batteryLevel);
  
              } else if (valueSelector == RFXComValueSelector.CHIME_SOUND) {
  
                  state = new DecimalType(chimeSound);
  
              } else {
  
                  throw new RFXComException("Can't convert " + valueSelector + " to NumberItem");
  
              }
  
          } else if (valueSelector.getItemClass() == StringItem.class) {
  
              if (valueSelector == RFXComValueSelector.RAW_DATA) {
  
                  state = new StringType(DatatypeConverter.printHexBinary(rawMessage));
              } else {
                  throw new RFXComException("Can't convert " + valueSelector + " to StringItem");
              }
          } else {
  
              throw new RFXComException("Can't convert " + valueSelector + " to " + valueSelector.getItemClass());
  
          }
  
          return state;
      }
  
      @Override
      public void convertFromState(RFXComValueSelector valueSelector, String id, Object subType, Type type,
              byte seqNumber) throws RFXComException {
  
          this.subType = ((SubType) subType);
          seqNbr = seqNumber;
          String[] ids = id.split("\\.");
          sensorId = Integer.parseInt(ids[0]);
  
          switch (valueSelector) {
              case CHIME_SOUND:
                  if (type instanceof DecimalType) {
                      chimeSound = (int) ((DecimalType) type).intValue();
                  } else {
                      throw new RFXComException("Can't convert " + type + " to chime sound");
                  }
                  break;
  
              default:
                  throw new RFXComException("Can't convert " + type + " to " + valueSelector);
          }
      }
  
      @Override
      public Object convertSubType(String subType) throws RFXComException {
  
  