|
30 | 30 | #include "command_classes/CommandClasses.h" |
31 | 31 | #include "command_classes/SwitchBinary.h" |
32 | 32 | #include "command_classes/WakeUp.h" |
| 33 | +#include "command_classes/Supervision.h" |
33 | 34 | #include "Defs.h" |
34 | 35 | #include "Msg.h" |
35 | 36 | #include "Driver.h" |
@@ -139,6 +140,29 @@ namespace OpenZWave |
139 | 140 |
|
140 | 141 | return false; |
141 | 142 | } |
| 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 | + } |
142 | 166 |
|
143 | 167 | //----------------------------------------------------------------------------- |
144 | 168 | // <SwitchBinary::SetValue> |
@@ -212,41 +236,54 @@ namespace OpenZWave |
212 | 236 | { |
213 | 237 | uint8 const nodeId = GetNodeId(); |
214 | 238 | 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 | + } |
215 | 249 |
|
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); |
220 | 255 |
|
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); |
232 | 267 |
|
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 | + } |
246 | 281 |
|
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; |
250 | 287 | } |
251 | 288 |
|
252 | 289 | //----------------------------------------------------------------------------- |
|
0 commit comments