MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / SetState

Method SetState

cpp/src/command_classes/SwitchBinary.cpp:228–277  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Set a new state for the switch -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

226// Set a new state for the switch
227//-----------------------------------------------------------------------------
228bool SwitchBinary::SetState
229(
230 uint8 const _instance,
231 bool const _state
232)
233{
234 uint8 const nodeId = GetNodeId();
235 uint8 const targetValue = _state ? 0xff : 0;
236
237 Log::Write( LogLevel_Info, nodeId, "SwitchBinary::Set - Setting to %s", _state ? "On" : "Off");
238 Msg* msg = new Msg( "SwitchBinaryCmd_Set", nodeId, REQUEST, FUNC_ID_ZW_SEND_DATA, true );
239 msg->SetInstance( this, _instance );
240 msg->Append( nodeId );
241
242 if( GetVersion() >= 2 )
243 {
244 ValueByte* durationValue = static_cast<ValueByte*>( GetValue( _instance, SwitchBinaryIndex_Duration ) );
245 uint8 duration = durationValue->GetValue();
246 durationValue->Release();
247 if( duration == 0xff )
248 {
249 Log::Write( LogLevel_Info, GetNodeId(), " Duration: Default" );
250 }
251 else if( duration >= 0x80 )
252 {
253 Log::Write( LogLevel_Info, GetNodeId(), " Duration: %d minutes", duration - 0x7f );
254 }
255 else
256 {
257 Log::Write( LogLevel_Info, GetNodeId(), " Duration: %d seconds", duration );
258 }
259
260 msg->Append( 4 );
261 msg->Append( GetCommandClassId() );
262 msg->Append( SwitchBinaryCmd_Set );
263 msg->Append( targetValue );
264 msg->Append( duration );
265 }
266 else
267 {
268 msg->Append( 3 );
269 msg->Append( GetCommandClassId() );
270 msg->Append( SwitchBinaryCmd_Set );
271 msg->Append( targetValue );
272 }
273
274 msg->Append( GetDriver()->GetTransmitOptions() );
275 GetDriver()->SendMsg( msg, Driver::MsgQueue_Send );
276 return true;
277}
278
279//-----------------------------------------------------------------------------
280// <SwitchBinary::CreateVars>

Callers

nothing calls this directly

Calls 9

WriteFunction · 0.85
GetVersionFunction · 0.85
GetCommandClassIdFunction · 0.85
SendMsgMethod · 0.80
GetNodeIdFunction · 0.70
SetInstanceMethod · 0.45
AppendMethod · 0.45
GetValueMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected