Skip to content

Commit

Permalink
Retain min temp field size for setpoint command and apply it there Op…
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberwizzard committed Nov 11, 2020
1 parent b0afd4c commit 5deb6af
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 115 deletions.
1 change: 1 addition & 0 deletions cpp/src/ValueIDIndexesDefines.def
Original file line number Diff line number Diff line change
Expand Up @@ -3166,6 +3166,7 @@ ENUM(ValueID_Index_ThermostatSetpoint,
CoolingEcon,
AwayHeating,
CoolingHeating,
SetPointMinSize,
Unused_0_Minimum = 100,
Heating_Minimum,
Cooling_Minimum,
Expand Down
111 changes: 1 addition & 110 deletions cpp/src/ValueIDIndexesDefines.h

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion cpp/src/command_classes/CommandClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,12 @@ namespace OpenZWave
// <CommandClass::AppendValue>
// Add a value to a message as a sequence of bytes
//-----------------------------------------------------------------------------
void CommandClass::AppendValue(Msg* _msg, std::string const& _value, uint8 const _scale) const
void CommandClass::AppendValue(Msg* _msg, std::string const& _value, uint8 const _scale, uint8 const _minsize) const
{
uint8 precision;
uint8 size;
int32 val = ValueToInteger(_value, &precision, &size);
if(size < _minsize) size = _minsize;

_msg->Append((precision << c_precisionShift) | (_scale << c_scaleShift) | size);

Expand Down
3 changes: 2 additions & 1 deletion cpp/src/command_classes/CommandClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ namespace OpenZWave
* \param _msg The message to which the value should be appended.
* \param _value A string containing a decimal number to be appended.
* \param _scale A byte indicating the scale corresponding to this value (e.g., 1=F and 0=C for temperatures).
* \param _minsize Indicating the minimum size in bytes to pass the field value (default 0 to use the smallest size possible)
* \see Msg
*/
void AppendValue(Msg* _msg, string const& _value, uint8 const _scale) const;
void AppendValue(Msg* _msg, string const& _value, uint8 const _scale, uint8 const _minsize = 0) const;
uint8 const GetAppendValueSize(string const& _value) const;
int32 ValueToInteger(string const& _value, uint8* o_precision, uint8* o_size) const;

Expand Down
16 changes: 13 additions & 3 deletions cpp/src/command_classes/ThermostatSetpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "platform/Log.h"

#include "value_classes/ValueDecimal.h"
#include "value_classes/ValueByte.h"

#include "tinyxml.h"

Expand Down Expand Up @@ -241,14 +242,15 @@ namespace OpenZWave
string minValue = ExtractValue(&_data[2], &scale, &precision);
string maxValue = ExtractValue(&_data[2 + size + 1], &scale, &precision);

Log::Write(LogLevel_Info, GetNodeId(), "Received capabilities of thermostat setpoint type %d, min %s max %s", (int) _data[1], minValue.c_str(), maxValue.c_str());
Log::Write(LogLevel_Info, GetNodeId(), "Received capabilities of thermostat setpoint type %d, min %s (field size: %i) max %s", (int) _data[1], minValue.c_str(), size, maxValue.c_str());

uint8 index = _data[1];
// Add supported setpoint
if (index < ThermostatSetpoint_Count)
{
string setpointName = c_setpointName[index];

// Retain the size of the minimum temperature as the minimum field size for the temperature
node->CreateValueByte(ValueID::ValueGenre_User, GetCommandClassId(), _instance, ValueID_Index_ThermostatSetpoint::SetPointMinSize, setpointName + "_setpointminsize", "B", true, false, 0, 0);
node->CreateValueDecimal(ValueID::ValueGenre_User, GetCommandClassId(), _instance, ValueID_Index_ThermostatSetpoint::Unused_0_Minimum + index, setpointName + "_minimum", "C", false, false, minValue, 0);
node->CreateValueDecimal(ValueID::ValueGenre_User, GetCommandClassId(), _instance, ValueID_Index_ThermostatSetpoint::Unused_0_Maximum + index, setpointName + "_maximum", "C", false, false, maxValue, 0);
Log::Write(LogLevel_Info, GetNodeId(), " Added setpoint: %s", setpointName.c_str());
Expand All @@ -270,6 +272,14 @@ namespace OpenZWave
{
Internal::VC::ValueDecimal const* value = static_cast<Internal::VC::ValueDecimal const*>(&_value);
uint8 scale = strcmp("C", value->GetUnits().c_str()) ? 1 : 0;
int8 setpointminsize = 0;
uint8 _instance = 1; // FIXME where is the instance ID supposed to come from?

if (Node* node = GetNodeUnsafe()) {
Internal::VC::Value const* _minsizeValue = node->GetValue(GetCommandClassId(), _instance, ValueID_Index_ThermostatSetpoint::SetPointMinSize);
Internal::VC::ValueByte const* minsizeValue = static_cast<Internal::VC::ValueByte const*>(_minsizeValue);
setpointminsize = minsizeValue->GetValue();
}

Msg* msg = new Msg("ThermostatSetpointCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true);
msg->SetInstance(this, _value.GetID().GetInstance());
Expand All @@ -278,7 +288,7 @@ namespace OpenZWave
msg->Append(GetCommandClassId());
msg->Append(ThermostatSetpointCmd_Set);
msg->Append((uint8_t) (value->GetID().GetIndex() & 0xFF));
AppendValue(msg, value->GetValue(), scale);
AppendValue(msg, value->GetValue(), scale, setpointminsize);
msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
return true;
Expand Down

0 comments on commit 5deb6af

Please sign in to comment.