/**
   * Gets a SerialMessage with the THERMOSTAT_SETPOINT_GET command
   *
   * @param setpointType the setpoint type to get
   * @return the serial message
   */
  public SerialMessage getMessage(SetpointType setpointType) {
    if (setpointType == null) {
      return null;
    }

    logger.debug(
        "NODE {}: Creating new message for application command THERMOSTAT_SETPOINT_GET",
        this.getNode().getNodeId());
    SerialMessage result =
        new SerialMessage(
            this.getNode().getNodeId(),
            SerialMessageClass.SendData,
            SerialMessageType.Request,
            SerialMessageClass.SendData,
            SerialMessagePriority.Get);
    byte[] payload = {
      (byte) this.getNode().getNodeId(),
      3,
      (byte) getCommandClass().getKey(),
      THERMOSTAT_SETPOINT_GET,
      (byte) setpointType.getKey()
    };
    result.setMessagePayload(payload);
    return result;
  }
  /**
   * Gets a SerialMessage with the THERMOSTAT_SETPOINT_SET command
   *
   * @param scale the scale (DegC or DegF)
   * @param setpointType the setpoint type to set
   * @param setpoint the setpoint to set.
   * @return the serial message
   */
  public SerialMessage setMessage(int scale, SetpointType setpointType, BigDecimal setpoint) {
    logger.debug(
        "NODE {}: Creating new message for application command THERMOSTAT_SETPOINT_SET",
        this.getNode().getNodeId());
    SerialMessage result =
        new SerialMessage(
            this.getNode().getNodeId(),
            SerialMessageClass.SendData,
            SerialMessageType.Request,
            SerialMessageClass.SendData,
            SerialMessagePriority.Set);

    try {
      byte[] encodedValue = encodeValue(setpoint);

      byte[] payload =
          ArrayUtils.addAll(
              new byte[] {
                (byte) this.getNode().getNodeId(),
                (byte) (3 + encodedValue.length),
                (byte) getCommandClass().getKey(),
                THERMOSTAT_SETPOINT_SET,
                (byte) setpointType.getKey()
              },
              encodedValue);
      // Add the scale
      payload[5] += (byte) (scale << 3);

      result.setMessagePayload(payload);
      return result;
    } catch (ArithmeticException e) {
      logger.error(
          "NODE {}: Got an arithmetic exception converting value {} to a valid Z-Wave value. Ignoring THERMOSTAT_SETPOINT_SET message.",
          this.getNode().getNodeId(),
          setpoint);
      return null;
    }
  }