----------------------------------------------------------------------------- Set a new state for the switch -----------------------------------------------------------------------------
| 226 | // Set a new state for the switch |
| 227 | //----------------------------------------------------------------------------- |
| 228 | bool 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> |
nothing calls this directly
no test coverage detected