/** * Processes a THERMOSTAT_MODE_REPORT message. * * @param serialMessage the incoming message to process. * @param offset the offset position from which to start message processing. * @param endpoint the endpoint or instance number this message is meant for. */ protected void processThermostatModeReport( SerialMessage serialMessage, int offset, int endpoint) { int value = serialMessage.getMessagePayloadByte(offset + 1); logger.debug("NODE {}: Thermostat Mode report, value = {}", this.getNode().getNodeId(), value); ModeType modeType = ModeType.getModeType(value); if (modeType == null) { logger.error( "NODE {}: Unknown Mode Type = {}, ignoring report.", this.getNode().getNodeId(), value); return; } // mode type seems to be supported, add it to the list. if (!modeTypes.contains(modeType)) { modeTypes.add(modeType); } dynamicDone = true; logger.debug( "NODE {}: Thermostat Mode Report, value = {}", this.getNode().getNodeId(), modeType.getLabel()); ZWaveCommandClassValueEvent zEvent = new ZWaveCommandClassValueEvent( this.getNode().getNodeId(), endpoint, this.getCommandClass(), value); this.getController().notifyEventListeners(zEvent); }
/** {@inheritDoc} */ @Override public void handleApplicationCommandRequest( SerialMessage serialMessage, int offset, int endpoint) { logger.debug("NODE {}: Received Thermostat Mode Request", this.getNode().getNodeId()); int command = serialMessage.getMessagePayloadByte(offset); switch (command) { case THERMOSTAT_MODE_GET: case THERMOSTAT_MODE_SUPPORTED_GET: logger.warn("NODE {}: Command {} not implemented.", this.getNode().getNodeId(), command); return; case THERMOSTAT_MODE_SET: logger.trace("NODE {}: Process Thermostat Mode Get as Report", this.getNode().getNodeId()); processThermostatModeReport(serialMessage, offset, endpoint); break; case THERMOSTAT_MODE_SUPPORTED_REPORT: logger.debug( "NODE {}: Process Thermostat Supported Mode Report", this.getNode().getNodeId()); int payloadLength = serialMessage.getMessagePayload().length; for (int i = offset + 1; i < payloadLength; ++i) { int bitMask = serialMessage.getMessagePayloadByte(i); for (int bit = 0; bit < 8; ++bit) { if ((bitMask & (1 << bit)) == 0) { continue; } int index = ((i - (offset + 1)) * 8) + bit; // (n)th bit is set. n is the index for the mode type enumeration. ModeType modeTypeToAdd = ModeType.getModeType(index); if (modeTypeToAdd != null) { this.modeTypes.add(modeTypeToAdd); logger.debug( "NODE {}: Added mode type {} ({})", this.getNode().getNodeId(), modeTypeToAdd.getLabel(), index); } else { logger.warn("NODE {}: Unknown mode type {}", this.getNode().getNodeId(), index); } } } initialiseDone = true; break; case THERMOSTAT_MODE_REPORT: logger.trace("NODE {}: Process Thermostat Mode Report", this.getNode().getNodeId()); processThermostatModeReport(serialMessage, offset, endpoint); break; default: logger.warn( "NODE {}: Unsupported Command {} for command class {} ({}).", this.getNode().getNodeId(), command, this.getCommandClass().getLabel(), this.getCommandClass().getKey()); } }
/** {@inheritDoc} */ @Override public SerialMessage setValueMessage(int value) { logger.debug( "NODE {}: setValueMessage {}, modeType empty {}", this.getNode().getNodeId(), value, modeTypes.isEmpty()); // if we do not have any mode types yet, get them if (modeTypes.isEmpty()) { logger.warn( "NODE {}: requesting mode types, set request ignored (try again later)", this.getNode().getNodeId()); return this.getSupportedMessage(); } if (!modeTypes.contains(ModeType.getModeType(value))) { logger.error("NODE {}: Unsupported mode type {}", this.getNode().getNodeId(), value); return null; } logger.debug( "NODE {}: Creating new message for application command THERMOSTAT_MODE_SET", this.getNode().getNodeId()); SerialMessage result = new SerialMessage( this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.SendData, SerialMessagePriority.Set); byte[] newPayload = { (byte) this.getNode().getNodeId(), 3, (byte) getCommandClass().getKey(), THERMOSTAT_MODE_SET, (byte) value }; result.setMessagePayload(newPayload); return result; }