Skip to content

Commit

Permalink
Making GetValue code more consistent, Releasing values (#1985)
Browse files Browse the repository at this point in the history
* Making GetValue code more persistent throughout application, releasing values
* Removed duplicate item declaration
* Add "else" parts and comment
  • Loading branch information
gizmocuz authored and petergebruers committed Nov 11, 2019
1 parent a06ee56 commit 79663e1
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions cpp/src/command_classes/ClimateControlSchedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,27 +310,43 @@ namespace OpenZWave
else
{
// Set an override
Internal::VC::ValueList* state = static_cast<Internal::VC::ValueList*>(GetValue(instance, ValueID_Index_ClimateControlSchedule::OverrideState));
Internal::VC::ValueByte* setback = static_cast<Internal::VC::ValueByte*>(GetValue(instance, ValueID_Index_ClimateControlSchedule::OverrideSetback));

if (state && setback)
if (Internal::VC::ValueList* state = static_cast<Internal::VC::ValueList*>(GetValue(instance, ValueID_Index_ClimateControlSchedule::OverrideState)))
{
Internal::VC::ValueList::Item const *item = state->GetItem();
if (item == NULL)
if (Internal::VC::ValueList::Item const* item = state->GetItem())
{
return false;
if (Internal::VC::ValueByte* setback = static_cast<Internal::VC::ValueByte*>(GetValue(instance, ValueID_Index_ClimateControlSchedule::OverrideSetback)))
{
Msg* msg = new Msg("ClimateControlScheduleCmd_OverrideSet", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId());
// nullptr check after "new" is kind of placebo, but it makes for consistent code
// discussion: https://github.com/OpenZWave/open-zwave/pull/1985
if (msg != nullptr)
{
msg->SetInstance(this, instance);
msg->Append(GetNodeId());
msg->Append(4);
msg->Append(GetCommandClassId());
msg->Append(ClimateControlScheduleCmd_OverrideSet);
msg->Append((uint8)item->m_value);
msg->Append(setback->GetValue());
msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
}
setback->Release();
}
else
{
Log::Write(LogLevel_Warning, GetNodeId(), "ClimateControlSchedule::SetValue couldn't Find ValueID_Index_ClimateControlSchedule::OverrideSetback");
}
}

Msg* msg = new Msg("ClimateControlScheduleCmd_OverrideSet", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId());
msg->SetInstance(this, instance);
msg->Append(GetNodeId());
msg->Append(4);
msg->Append(GetCommandClassId());
msg->Append(ClimateControlScheduleCmd_OverrideSet);
msg->Append((uint8) item->m_value);
msg->Append(setback->GetValue());
msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
else
{
Log::Write(LogLevel_Warning, GetNodeId(), "ClimateControlSchedule::SetValue state->GetItem() returned nullptr");
}
state->Release();
}
else
{
Log::Write(LogLevel_Warning, GetNodeId(), "ClimateControlSchedule::SetValue couldn't Find ValueID_Index_ClimateControlSchedule::OverrideState");
}
}

Expand Down

0 comments on commit 79663e1

Please sign in to comment.