2626// -----------------------------------------------------------------------------
2727
2828#include " command_classes/CommandClasses.h"
29+ #include " command_classes/Supervision.h"
2930#include " command_classes/ThermostatMode.h"
3031#include " Defs.h"
3132#include " Msg.h"
@@ -92,7 +93,7 @@ namespace OpenZWave
9293
9394 static char const * c_modeName[] =
9495 { " Off" , " Heat" , " Cool" , " Auto" , " Aux Heat" , " Resume" , " Fan Only" , " Furnace" , " Dry Air" , " Moist Air" , " Auto Changeover" , " Heat Econ" , " Cool Econ" , " Away" , " Unknown" , " Full Power" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Unknown" , " Manufacturer Specific" };
95-
96+
9697
9798 ThermostatMode::ThermostatMode (uint32 const _homeId, uint8 const _nodeId) :
9899 CommandClass (_homeId, _nodeId),
@@ -323,6 +324,7 @@ namespace OpenZWave
323324 }
324325 }
325326 }
327+
326328 /* at this stage, we don't know the Actual Mode of the Fan, so set it to the lowest
327329 * value... If not, set to 0, which possibly could be invalid...
328330 */
@@ -341,29 +343,70 @@ namespace OpenZWave
341343 return false ;
342344 }
343345
346+ void ThermostatMode::SupervisionSessionSuccess (uint8 _session_id, uint32 const _instance)
347+ {
348+ if (Node* node = GetNodeUnsafe ())
349+ {
350+ uint32 index = node->GetSupervisionIndex (_session_id);
351+
352+ if (index != Internal::CC::Supervision::StaticNoIndex ())
353+ {
354+ // We have received the confirmation for the thermostat mode from the Z-Wave device
355+ if (Internal::VC::ValueList* valueList = static_cast <Internal::VC::ValueList*>(GetValue (_instance, ValueID_Index_ThermostatMode::Mode)))
356+ {
357+ valueList->ConfirmNewValue ();
358+ if (valueList->GetItem ())
359+ {
360+ Log::Write (LogLevel_Info, GetNodeId (), " Confirmed thermostat mode: %s" , valueList->GetItem ()->m_label .c_str ());
361+ m_currentMode = valueList->GetItem ()->m_value ;
362+ }
363+ else
364+ Log::Write (LogLevel_Warning, GetNodeId (), " Confirmed thermostat mode (No Item)" );
365+ valueList->Release ();
366+ }
367+ }
368+ else
369+ {
370+ Log::Write (LogLevel_Info, GetNodeId (), " Ignore unknown supervision session %d" , _session_id);
371+ }
372+ }
373+ }
374+
344375// -----------------------------------------------------------------------------
345376// <ThermostatMode::SetValue>
346377// Set the device's thermostat mode
347378// -----------------------------------------------------------------------------
348379 bool ThermostatMode::SetValue (Internal::VC::Value const & _value)
349380 {
350- if (ValueID::ValueType_List == _value.GetID ().GetType ())
381+
382+ if (Node* node = GetNodeUnsafe ())
351383 {
352- Internal::VC::ValueList const * value = static_cast <Internal::VC::ValueList const *>(&_value);
353- if (value->GetItem () == NULL )
354- return false ;
355- uint8 state = (uint8) value->GetItem ()->m_value ;
384+ if (ValueID::ValueType_List == _value.GetID ().GetType ())
385+ {
386+ Internal::VC::ValueList const * value = static_cast <Internal::VC::ValueList const *>(&_value);
387+ if (value->GetItem () == NULL )
388+ return false ;
389+ uint8 state = (uint8)value->GetItem ()->m_value ;
390+
391+ uint8 index = value->GetID ().GetIndex () & 0xFF ;
392+ uint8 supervision_session_id = node->CreateSupervisionSession (StaticGetCommandClassId (), index);
393+ if (supervision_session_id == Internal::CC::Supervision::StaticNoSessionId ())
394+ {
395+ Log::Write (LogLevel_Debug, GetNodeId (), " Supervision not supported, fall back to setpoint set/get" );
396+ }
356397
357- Msg* msg = new Msg (" ThermostatModeCmd_Set" , GetNodeId (), REQUEST, FUNC_ID_ZW_SEND_DATA, true );
358- msg->SetInstance (this , _value.GetID ().GetInstance ());
359- msg->Append (GetNodeId ());
360- msg->Append (3 );
361- msg->Append (GetCommandClassId ());
362- msg->Append (ThermostatModeCmd_Set);
363- msg->Append (state);
364- msg->Append (GetDriver ()->GetTransmitOptions ());
365- GetDriver ()->SendMsg (msg, Driver::MsgQueue_Send);
366- return true ;
398+ Msg* msg = new Msg (" ThermostatModeCmd_Set" , GetNodeId (), REQUEST, FUNC_ID_ZW_SEND_DATA, true );
399+ msg->SetInstance (this , _value.GetID ().GetInstance ());
400+ msg->SetSupervision (supervision_session_id);
401+ msg->Append (GetNodeId ());
402+ msg->Append (3 );
403+ msg->Append (GetCommandClassId ());
404+ msg->Append (ThermostatModeCmd_Set);
405+ msg->Append (state);
406+ msg->Append (GetDriver ()->GetTransmitOptions ());
407+ GetDriver ()->SendMsg (msg, Driver::MsgQueue_Send);
408+ return true ;
409+ }
367410 }
368411
369412 return false ;
0 commit comments