Skip to content

Commit aa40ab9

Browse files
committed
Making use of the Supervision CC to set the thermostat mode.
1 parent 221cbaf commit aa40ab9

4 files changed

Lines changed: 68 additions & 16 deletions

File tree

cpp/src/command_classes/ThermostatMode.cpp

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
//-----------------------------------------------------------------------------
2727

2828
#include "command_classes/CommandClasses.h"
29+
#include "command_classes/Supervision.h"
2930
#include "command_classes/ThermostatMode.h"
3031
#include "Defs.h"
3132
#include "Msg.h"
@@ -92,7 +93,7 @@ namespace OpenZWave
9293

9394
static char const* c_modeName[] =
9495
{ "Off", "Heat", "Cool", "Auto", "Aux Heat", "Resume", "Fan Only", "Furnace", "Dry Air", "Moist Air", "Auto Changeover", "Heat Econ", "Cool Econ", "Away", "Unknown", "Full Power", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Manufacturer Specific" };
95-
96+
9697

9798
ThermostatMode::ThermostatMode(uint32 const _homeId, uint8 const _nodeId) :
9899
CommandClass(_homeId, _nodeId),
@@ -323,6 +324,7 @@ namespace OpenZWave
323324
}
324325
}
325326
}
327+
326328
/* at this stage, we don't know the Actual Mode of the Fan, so set it to the lowest
327329
* value... If not, set to 0, which possibly could be invalid...
328330
*/
@@ -341,29 +343,70 @@ namespace OpenZWave
341343
return false;
342344
}
343345

346+
void ThermostatMode::SupervisionSessionSuccess(uint8 _session_id, uint32 const _instance)
347+
{
348+
if (Node* node = GetNodeUnsafe())
349+
{
350+
uint32 index = node->GetSupervisionIndex(_session_id);
351+
352+
if (index != Internal::CC::Supervision::StaticNoIndex())
353+
{
354+
// We have received the confirmation for the thermostat mode from the Z-Wave device
355+
if (Internal::VC::ValueList* valueList = static_cast<Internal::VC::ValueList*>(GetValue(_instance, ValueID_Index_ThermostatMode::Mode)))
356+
{
357+
valueList->ConfirmNewValue();
358+
if (valueList->GetItem())
359+
{
360+
Log::Write(LogLevel_Info, GetNodeId(), "Confirmed thermostat mode: %s", valueList->GetItem()->m_label.c_str());
361+
m_currentMode = valueList->GetItem()->m_value;
362+
}
363+
else
364+
Log::Write(LogLevel_Warning, GetNodeId(), "Confirmed thermostat mode (No Item)");
365+
valueList->Release();
366+
}
367+
}
368+
else
369+
{
370+
Log::Write(LogLevel_Info, GetNodeId(), "Ignore unknown supervision session %d", _session_id);
371+
}
372+
}
373+
}
374+
344375
//-----------------------------------------------------------------------------
345376
// <ThermostatMode::SetValue>
346377
// Set the device's thermostat mode
347378
//-----------------------------------------------------------------------------
348379
bool ThermostatMode::SetValue(Internal::VC::Value const& _value)
349380
{
350-
if (ValueID::ValueType_List == _value.GetID().GetType())
381+
382+
if (Node* node = GetNodeUnsafe())
351383
{
352-
Internal::VC::ValueList const* value = static_cast<Internal::VC::ValueList const*>(&_value);
353-
if (value->GetItem() == NULL)
354-
return false;
355-
uint8 state = (uint8) value->GetItem()->m_value;
384+
if (ValueID::ValueType_List == _value.GetID().GetType())
385+
{
386+
Internal::VC::ValueList const* value = static_cast<Internal::VC::ValueList const*>(&_value);
387+
if (value->GetItem() == NULL)
388+
return false;
389+
uint8 state = (uint8)value->GetItem()->m_value;
390+
391+
uint8 index = value->GetID().GetIndex() & 0xFF;
392+
uint8 supervision_session_id = node->CreateSupervisionSession(StaticGetCommandClassId(), index);
393+
if (supervision_session_id == Internal::CC::Supervision::StaticNoSessionId())
394+
{
395+
Log::Write(LogLevel_Debug, GetNodeId(), "Supervision not supported, fall back to setpoint set/get");
396+
}
356397

357-
Msg* msg = new Msg("ThermostatModeCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true);
358-
msg->SetInstance(this, _value.GetID().GetInstance());
359-
msg->Append(GetNodeId());
360-
msg->Append(3);
361-
msg->Append(GetCommandClassId());
362-
msg->Append(ThermostatModeCmd_Set);
363-
msg->Append(state);
364-
msg->Append(GetDriver()->GetTransmitOptions());
365-
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
366-
return true;
398+
Msg* msg = new Msg("ThermostatModeCmd_Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true);
399+
msg->SetInstance(this, _value.GetID().GetInstance());
400+
msg->SetSupervision(supervision_session_id);
401+
msg->Append(GetNodeId());
402+
msg->Append(3);
403+
msg->Append(GetCommandClassId());
404+
msg->Append(ThermostatModeCmd_Set);
405+
msg->Append(state);
406+
msg->Append(GetDriver()->GetTransmitOptions());
407+
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
408+
return true;
409+
}
367410
}
368411

369412
return false;

cpp/src/command_classes/ThermostatMode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace OpenZWave
8282
{
8383
return 3;
8484
}
85+
virtual void SupervisionSessionSuccess(uint8 _session_id, uint32 const _instance);
8586

8687
protected:
8788
virtual void CreateVars(uint8 const _instance) override;

cpp/src/value_classes/ValueList.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ namespace OpenZWave
229229
ValueList* tempValue = new ValueList(*this);
230230
tempValue->m_valueIdx = _value;
231231

232+
// Save the new value to be stored when the device confirms the value was set successfully,
233+
m_newValue = _value;
234+
232235
// Set the value in the device.
233236
bool ret = ((Value*) tempValue)->Set();
234237

cpp/src/value_classes/ValueList.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ namespace OpenZWave
6666
bool SetByValue(int32 const _value);
6767

6868
void OnValueRefreshed(int32 const _valueIdx);
69+
void ConfirmNewValue()
70+
{
71+
OnValueRefreshed(m_items[m_newValue].m_value);
72+
};
6973

7074
// From Value
7175
virtual string const GetAsString() const
@@ -98,6 +102,7 @@ namespace OpenZWave
98102
vector<Item> m_items;
99103
int32 m_valueIdx; // the current index in the m_items vector
100104
int32 m_valueIdxCheck; // the previous index in the m_items vector (used for double-checking spurious value reads)
105+
int32 m_newValue; // a new index to be set on the appropriate device (used by Supervision CC)
101106
uint8 m_size;
102107
int32 m_targetValue; // the Target Value, if the CC support it
103108

0 commit comments

Comments
 (0)