Skip to content

Commit 9cb4621

Browse files
authored
Merge pull request #2617 from nebuohyrrah/feature_Supervision_Switch_Binary
Supervision CC support for SwitchBinary
2 parents 41bfba6 + 81409e3 commit 9cb4621

4 files changed

Lines changed: 77 additions & 31 deletions

File tree

cpp/src/command_classes/SwitchBinary.cpp

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "command_classes/CommandClasses.h"
3131
#include "command_classes/SwitchBinary.h"
3232
#include "command_classes/WakeUp.h"
33+
#include "command_classes/Supervision.h"
3334
#include "Defs.h"
3435
#include "Msg.h"
3536
#include "Driver.h"
@@ -139,6 +140,29 @@ namespace OpenZWave
139140

140141
return false;
141142
}
143+
144+
void SwitchBinary::SupervisionSessionSuccess(uint8 _session_id, uint32 const _instance)
145+
{
146+
if (Node* node = GetNodeUnsafe())
147+
{
148+
uint32 index = node->GetSupervisionIndex(_session_id);
149+
150+
if (index != Internal::CC::Supervision::StaticNoIndex())
151+
{
152+
if (Internal::VC::ValueBool* value = static_cast<Internal::VC::ValueBool*>(GetValue(_instance, index)))
153+
{
154+
value->ConfirmNewValue();
155+
156+
Log::Write(LogLevel_Info, GetNodeId(), "Confirmed switch binary index %d to value=%s",
157+
index, value->GetValue() ? "On" : "Off");
158+
}
159+
}
160+
else
161+
{
162+
Log::Write(LogLevel_Info, GetNodeId(), "Ignore unknown supervision session %d", _session_id);
163+
}
164+
}
165+
}
142166

143167
//-----------------------------------------------------------------------------
144168
// <SwitchBinary::SetValue>
@@ -212,41 +236,54 @@ namespace OpenZWave
212236
{
213237
uint8 const nodeId = GetNodeId();
214238
uint8 const targetValue = _state ? 0xff : 0;
239+
240+
if (Node* node = GetNodeUnsafe())
241+
{
242+
//add supervision encapsulation if supported
243+
uint8 index = ValueID_Index_SwitchBinary::Level;
244+
uint8 supervision_session_id = node->CreateSupervisionSession(StaticGetCommandClassId(), index);
245+
if (supervision_session_id == Internal::CC::Supervision::StaticNoSessionId())
246+
{
247+
Log::Write(LogLevel_Debug, GetNodeId(), "Supervision not supported, fall back to setpoint set/get");
248+
}
215249

216-
Log::Write(LogLevel_Info, nodeId, "SwitchBinary::Set - Setting to %s", _state ? "On" : "Off");
217-
Msg* msg = new Msg("SwitchBinaryCmd_Set", nodeId, REQUEST, FUNC_ID_ZW_SEND_DATA, true);
218-
msg->SetInstance(this, _instance);
219-
msg->Append(nodeId);
250+
Log::Write(LogLevel_Info, nodeId, "SwitchBinary::Set - Setting to %s", _state ? "On" : "Off");
251+
Msg* msg = new Msg("SwitchBinaryCmd_Set", nodeId, REQUEST, FUNC_ID_ZW_SEND_DATA, true);
252+
msg->SetInstance(this, _instance);
253+
msg->SetSupervision(supervision_session_id);
254+
msg->Append(nodeId);
220255

221-
if (GetVersion() >= 2)
222-
{
223-
Internal::VC::ValueInt* durationValue = static_cast<Internal::VC::ValueInt*>(GetValue(_instance, ValueID_Index_SwitchBinary::Duration));
224-
uint32 duration = durationValue->GetValue();
225-
durationValue->Release();
226-
if (duration > 7620)
227-
Log::Write(LogLevel_Info, GetNodeId(), " Duration: Device Default");
228-
else if (duration > 0x7F)
229-
Log::Write(LogLevel_Info, GetNodeId(), " Rouding to %d Minutes (over 127 seconds)", encodeDuration(duration)-0x79);
230-
else
231-
Log::Write(LogLevel_Info, GetNodeId(), " Duration: %d seconds", duration);
256+
if (GetVersion() >= 2)
257+
{
258+
Internal::VC::ValueInt* durationValue = static_cast<Internal::VC::ValueInt*>(GetValue(_instance, ValueID_Index_SwitchBinary::Duration));
259+
uint32 duration = durationValue->GetValue();
260+
durationValue->Release();
261+
if (duration > 7620)
262+
Log::Write(LogLevel_Info, GetNodeId(), " Duration: Device Default");
263+
else if (duration > 0x7F)
264+
Log::Write(LogLevel_Info, GetNodeId(), " Rouding to %d Minutes (over 127 seconds)", encodeDuration(duration)-0x79);
265+
else
266+
Log::Write(LogLevel_Info, GetNodeId(), " Duration: %d seconds", duration);
232267

233-
msg->Append(4);
234-
msg->Append(GetCommandClassId());
235-
msg->Append(SwitchBinaryCmd_Set);
236-
msg->Append(targetValue);
237-
msg->Append(encodeDuration(duration));
238-
}
239-
else
240-
{
241-
msg->Append(3);
242-
msg->Append(GetCommandClassId());
243-
msg->Append(SwitchBinaryCmd_Set);
244-
msg->Append(targetValue);
245-
}
268+
msg->Append(4);
269+
msg->Append(GetCommandClassId());
270+
msg->Append(SwitchBinaryCmd_Set);
271+
msg->Append(targetValue);
272+
msg->Append(encodeDuration(duration));
273+
}
274+
else
275+
{
276+
msg->Append(3);
277+
msg->Append(GetCommandClassId());
278+
msg->Append(SwitchBinaryCmd_Set);
279+
msg->Append(targetValue);
280+
}
246281

247-
msg->Append(GetDriver()->GetTransmitOptions());
248-
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
249-
return true;
282+
msg->Append(GetDriver()->GetTransmitOptions());
283+
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
284+
return true;
285+
}
286+
return false;
250287
}
251288

252289
//-----------------------------------------------------------------------------

cpp/src/command_classes/SwitchBinary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace OpenZWave
8080
{
8181
return 2;
8282
}
83+
virtual void SupervisionSessionSuccess(uint8 _session_id, uint32 const _instance);
8384

8485
protected:
8586
virtual void CreateVars(uint8 const _instance) override;

cpp/src/value_classes/ValueBool.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ namespace OpenZWave
100100
// create a temporary copy of this value to be submitted to the Set() call and set its value to the function param
101101
ValueBool* tempValue = new ValueBool(*this);
102102
tempValue->m_value = _value;
103+
104+
// Save the new value to be stored when the device confirms the value was set successfully,
105+
m_newValue = _value;
103106

104107
// Set the value in the device.
105108
bool ret = ((Value*) tempValue)->Set();

cpp/src/value_classes/ValueBool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ namespace OpenZWave
5757

5858
bool Set(bool const _value);
5959
void OnValueRefreshed(bool const _value);
60+
void ConfirmNewValue()
61+
{
62+
OnValueRefreshed(m_newValue != 0);
63+
};
6064
void SetTargetValue(bool const _target, uint32 _duration = 0);
6165

6266

@@ -78,6 +82,7 @@ namespace OpenZWave
7882
bool m_value; // the current index in the m_items vector
7983
bool m_valueCheck; // the previous value (used for double-checking spurious value reads)
8084
bool m_targetValue; // The Target Value
85+
bool m_newValue; // a new value to be set on the appropriate device (used by Supervision CC)
8186
};
8287
} // namespace VC
8388
} // namespace Internal

0 commit comments

Comments
 (0)