gt:     	byte[] newPayload = { 	(byte) this.getNode().getNodeId(), 
context: /**
   * Copyright (c) 2010-2015, openHAB.org and others.
   *
   * 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.zwave.internal.protocol.commandclass;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Map;
  
  import org.openhab.binding.zwave.internal.config.ZWaveDbCommandClass;
  import org.openhab.binding.zwave.internal.protocol.SerialMessage;
  import org.openhab.binding.zwave.internal.protocol.ZWaveController;
  import org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint;
  import org.openhab.binding.zwave.internal.protocol.ZWaveNode;
  import org.openhab.binding.zwave.internal.protocol.SerialMessage.SerialMessageClass;
  import org.openhab.binding.zwave.internal.protocol.SerialMessage.SerialMessagePriority;
  import org.openhab.binding.zwave.internal.protocol.SerialMessage.SerialMessageType;
  import org.openhab.binding.zwave.internal.protocol.event.ZWaveCommandClassValueEvent;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import com.thoughtworks.xstream.annotations.XStreamAlias;
  import com.thoughtworks.xstream.annotations.XStreamOmitField;
  
  /**
   * Handles the Alarm Sensor command class. Alarm sensors indicate an
   * event for each of their supported alarm types.
   * The event is reported as occurs (0xFF) or does not occur (0x00).
   * The commands include the possibility to get a given
   * value and report a value.
   * @author Jan-Willem Spuij
   * @author Chris Jackson
   * @since 1.3.0
   */
  @XStreamAlias("alarmSensorCommandClass")
  public class ZWaveAlarmSensorCommandClass extends ZWaveCommandClass 
  	implements ZWaveGetCommands, ZWaveCommandClassInitialization, ZWaveCommandClassDynamicState {
  
  	@XStreamOmitField
  	private static final Logger logger = LoggerFactory.getLogger(ZWaveAlarmSensorCommandClass.class);
  	
  	private static final int SENSOR_ALARM_GET = 0x01;
  	private static final int SENSOR_ALARM_REPORT = 0x02;
  	private static final int SENSOR_ALARM_SUPPORTED_GET = 0x03;
  	private static final int SENSOR_ALARM_SUPPORTED_REPORT = 0x04;
  
  	private final Map<AlarmType, Alarm> alarms = new HashMap<AlarmType, Alarm>();
  
  	@XStreamOmitField
  	private boolean initialiseDone = false;
  	
  	private boolean isGetSupported = true;
  
  	/**
  	 * Creates a new instance of the ZWaveAlarmSensorCommandClass class.
  	 * @param node the node this command class belongs to
  	 * @param controller the controller to use
  	 * @param endpoint the endpoint this Command class belongs to
  	 */
  	public ZWaveAlarmSensorCommandClass(ZWaveNode node,
  			ZWaveController controller, ZWaveEndpoint endpoint) {
  		super(node, controller, endpoint);
  	}
  
  	/**
  	 * {@inheritDoc}
  	 */
  	@Override
  	public CommandClass getCommandClass() {
  		return CommandClass.SENSOR_ALARM;
  	}
  
  	/**
  	 * {@inheritDoc}
  	 */
  	@Override
  	public void handleApplicationCommandRequest(SerialMessage serialMessage,
  			int offset, int endpoint) {
  		logger.debug("NODE {}: Received Sensor Alarm Request", this.getNode().getNodeId());
  		int command = serialMessage.getMessagePayloadByte(offset);
  		switch (command) {
  			case SENSOR_ALARM_GET:
  			case SENSOR_ALARM_SUPPORTED_GET:
  				logger.warn("Command {} not implemented.", command);
  				return;
  			case SENSOR_ALARM_REPORT:
  				logger.trace("Process Sensor Alarm Report");
  				
  				int sourceNode = serialMessage.getMessagePayloadByte(offset + 1);
  				int alarmTypeCode = serialMessage.getMessagePayloadByte(offset + 2);
  				int value = serialMessage.getMessagePayloadByte(offset + 3);
  
  				// Alarm type seems to be supported, add it to the list if it's not already there.
  				Alarm alarm = getAlarm(alarmTypeCode);
  				if(alarm != null) {
  					alarm.setInitialised();
  	
  					logger.debug("NODE {}: Alarm Report: Source={}, Type={}({}), Value={}",
  							this.getNode().getNodeId(),
  							sourceNode,
  							alarm.getAlarmType().getLabel(), alarmTypeCode,
  							value);
  	
  					ZWaveAlarmSensorValueEvent zEvent = new ZWaveAlarmSensorValueEvent(this.getNode().getNodeId(), endpoint, alarm.getAlarmType(), value);
  					this.getController().notifyEventListeners(zEvent);
  				}
  				break;
  			case SENSOR_ALARM_SUPPORTED_REPORT:
  				logger.debug("NODE {}: Process Sensor Supported Alarm Report", this.getNode().getNodeId());
  
  				int numBytes = serialMessage.getMessagePayloadByte(offset + 1);
  
  				int manufacturerId = this.getNode().getManufacturer();
  				int deviceType = this.getNode().getDeviceType();
  				
  				// TODO: This bodge should be configured through the database!!!
  				// Fibaro alarm sensors do not provide a bitmap of alarm types, but list them byte by byte.
  				if (manufacturerId == 0x010F && deviceType == 0x0700) {
  					logger.debug("Detected Fibaro FGK - 101 Door / Window sensor, activating workaround for incorrect encoding of supported alarm bitmap.");
  				
  					for(int i=0; i < numBytes; ++i ) {
  						int index = serialMessage.getMessagePayloadByte(offset + i + 2);
  						if(index >= AlarmType.values().length) {
  							continue;
  						}
  
  						// Alarm type seems to be supported, add it to the list if it's not already there.
  						getAlarm(index);
  					}
  				} else {
  					for(int i=0; i < numBytes; ++i ) {
  						for(int bit = 0; bit < 8; ++bit) {
  							if (((serialMessage.getMessagePayloadByte(offset + i + 2)) & (1 << bit)) == 0) {
  								continue;
  							}
  	
  							int index = (i << 3) + bit;
  							if (index >= AlarmType.values().length) {
  								continue;
  							}
  	
  							// (n)th bit is set. n is the index for the alarm type
  							// enumeration.
  							// Alarm type seems to be supported, add it to the list if it's not already there.
  							getAlarm(index);
  						}
  					}
  				}
  
  				initialiseDone = true;
  				break;
  			default:
  			logger.warn(String.format("Unsupported Command 0x%02X for command class %s (0x%02X).", 
  					command, 
  					this.getCommandClass().getLabel(),
  					this.getCommandClass().getKey()));
  		}
  	}
  
  	private Alarm getAlarm(int alarmTypeCode) {
  		AlarmType alarmType = AlarmType.getAlarmType(alarmTypeCode);
  		if (alarmType == null) {
  			logger.error("NODE {}: Unknown Alarm Type = {}, ignoring report.", this.getNode().getNodeId(), alarmTypeCode);
  			return null;
  		}
  
  		// Add alarm to the list if it's not already there.
  		Alarm alarm = alarms.get(alarmType);
  		if (alarm == null) {
  			logger.debug("NODE {}: Adding new alarm type {}({})", this.getNode().getNodeId(),
  					alarmType.getLabel(), alarmTypeCode);
  			alarm = new Alarm(alarmType);
  			this.alarms.put(alarmType, alarm);
  		}
  
  		return alarm;
  	}
  
  	/**
  	 * Gets a SerialMessage with the SENSOR_ALARM_GET command 
  	 * @return the serial message
  	 */
  	public SerialMessage getValueMessage() {
  		//TODO: Why does this return!!!???!!!
  		for (Map.Entry<AlarmType, Alarm> entry : this.alarms.entrySet()) {
  			return getMessage(entry.getValue().getAlarmType());
  		}
  		
  		// in case there are no supported alarms, get them.
  		return this.getSupportedMessage();
  	}
  	
  	/**
  	 * Gets a SerialMessage with the SENSOR_ALARM_GET command 
  	 * @return the serial message
  	 */
  	public SerialMessage getMessage(AlarmType alarmType) {
  		if(isGetSupported == false) {
  			logger.debug("NODE {}: Node doesn't support get requests", this.getNode().getNodeId());
  			return null;
  		}
  
  		logger.debug("NODE {}: Creating new message for command SENSOR_ALARM_GET, type {}", this.getNode().getNodeId(), alarmType.getLabel());
  		SerialMessage result = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.ApplicationCommandHandler, SerialMessagePriority.Get);
      	byte[] newPayload = { 	(byte) this.getNode().getNodeId(), 
      							3, 
  								(byte) getCommandClass().getKey(), 
  								(byte) SENSOR_ALARM_GET,
  								(byte) alarmType.getKey() };
      	result.setMessagePayload(newPayload);
      	return result;		
  	}
  
  	@Override
  	public boolean setOptions (ZWaveDbCommandClass options) {
  		if(options.isGetSupported != null) {
  			isGetSupported = options.isGetSupported;
  		}
  		
  		return true;
  	}
  
  	/**
  	 * Gets a SerialMessage with the SENSOR_ALARM_SUPPORTED_GET command 
  	 * @return the serial message, or null if the supported command is not supported.
  	 */
  	public SerialMessage getSupportedMessage() {
  		logger.debug("NODE {}: Creating new message for command SENSOR_ALARM_SUPPORTED_GET", this.getNode().getNodeId());
  		
  		if (this.getNode().getManufacturer() == 0x010F && this.getNode().getDeviceType() == 0x0501) {
  			logger.warn("NODE {}: Detected Fibaro FGBS001 Universal Sensor - this device fails to respond to SENSOR_ALARM_GET and SENSOR_ALARM_SUPPORTED_GET.", this.getNode().getNodeId());
  			return null;
  		}
  		if (this.getNode().getManufacturer() == 0x010F && this.getNode().getDeviceType() == 0x0600) {
  			logger.warn("NODE {}: Detected Fibaro FGWPE Wall Plug - this device fails to respond to SENSOR_ALARM_GET and SENSOR_ALARM_SUPPORTED_GET.", this.getNode().getNodeId());
  			return null;
  		}
  		
  		SerialMessage result = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.ApplicationCommandHandler, SerialMessagePriority.High);
  