----------------------------------------------------------------------------- Set a new value in the device -----------------------------------------------------------------------------
| 340 | // Set a new value in the device |
| 341 | //----------------------------------------------------------------------------- |
| 342 | bool Value::Set |
| 343 | ( |
| 344 | ) |
| 345 | { |
| 346 | // nothing to do if this is a read-only value (return false to indicate an error) |
| 347 | if( IsReadOnly() ) |
| 348 | { |
| 349 | return false; |
| 350 | } |
| 351 | |
| 352 | // retrieve the driver, node and commandclass object for this value |
| 353 | bool res = false; |
| 354 | Node* node = NULL; |
| 355 | if( Driver* driver = Manager::Get()->GetDriver( m_id.GetHomeId() ) ) |
| 356 | { |
| 357 | node = driver->GetNodeUnsafe( m_id.GetNodeId() ); |
| 358 | if( node != NULL ) |
| 359 | { |
| 360 | if( CommandClass* cc = node->GetCommandClass( m_id.GetCommandClassId() ) ) |
| 361 | { |
| 362 | Log::Write(LogLevel_Info, m_id.GetNodeId(), "Value::Set - %s - %s - %d - %d - %s", cc->GetCommandClassName().c_str(), this->GetLabel().c_str(), m_id.GetIndex(), m_id.GetInstance(), this->GetAsString().c_str()); |
| 363 | // flag value as set and queue a "Set Value" message for transmission to the device |
| 364 | res = cc->SetValue( *this ); |
| 365 | |
| 366 | if( res ) |
| 367 | { |
| 368 | if( !IsWriteOnly() ) |
| 369 | { |
| 370 | // queue a "RequestValue" message to update the value |
| 371 | cc->RequestValue( 0, m_id.GetIndex(), m_id.GetInstance(), Driver::MsgQueue_Send ); |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | // There is a "bug" here in that write only values |
| 376 | // never send a notification about the value changing. |
| 377 | // For sleeping devices it may not change until the |
| 378 | // device wakes up at some point in the future. |
| 379 | // So when is the right time to change it? |
| 380 | if( m_affectsAll ) |
| 381 | { |
| 382 | node->RequestAllConfigParams( 0 ); |
| 383 | } |
| 384 | else if( m_affectsLength > 0 ) |
| 385 | { |
| 386 | for( int i = 0; i < m_affectsLength; i++ ) |
| 387 | { |
| 388 | node->RequestConfigParam( m_affects[i] ); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | return res; |
| 398 | } |
| 399 |
no test coverage detected