-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTVModeDetector.cpp
More file actions
45 lines (42 loc) · 1.22 KB
/
TVModeDetector.cpp
File metadata and controls
45 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "TVModeDetector.h"
#include <optional>
#include "StringDict.h"
#include "Config.h"
#include <WString.h>
#include "SmartThingsManager.h"
namespace SA
{
void TVModeDetector::Update()
{
if (!m_isEnabled.has_value())
{
m_isEnabled = SmartThingsManager::Get().IsSwitchEnabled(Config::c_outputDeviceID, true);
}
bool shouldTVModeBeOn = false;
const StringDict states = SmartThingsManager::Get().GetDeviceStatus(SA::Config::c_TVDeviceID, true);
if (auto switchValue = states.GetValue<bool>("switch/switch/value"))
{
if (*switchValue)
{
if (auto tvChannelName = states.GetValue<const char*>("tvChannel/tvChannelName/value"))
{
if (strlen(*tvChannelName) == 0)
{
if (auto tvSource = states.GetValue<const char*>("samsungvd.mediaInputSource/inputSource/value"))
{
if (Utils::StrCmpIgnoreCase(*tvSource, "HDMI1"))
{
shouldTVModeBeOn = true;
}
}
}
}
}
}
if (shouldTVModeBeOn != m_isEnabled)
{
SmartThingsManager::Get().SetSwitchValue(Config::c_outputDeviceID, shouldTVModeBeOn);
m_isEnabled = shouldTVModeBeOn;
}
}
}