-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaMetricBluetoothController.cpp
More file actions
42 lines (38 loc) · 1.14 KB
/
LaMetricBluetoothController.cpp
File metadata and controls
42 lines (38 loc) · 1.14 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
#include "LaMetricBluetoothController.h"
#include "SmartThingsManager.h"
#include "Config.h"
#include <HTTPClient.h>
#include "base64.h"
#include <NetworkClient.h>
#include "LaMetricUtils.h"
#include "StringDict.h"
namespace SA
{
void LaMetricBluetoothController::Update()
{
if (!m_shouldBeEnabled.has_value())
{
const StringDict states(Utils::GetToLaMetric(Config::c_laMetricDeviceBluetooth).c_str(), "/root/");
if (auto value = states.GetValue<bool>("active"))
{
m_shouldBeEnabled = *value;
}
else
{
Serial.println("Failed to fetch LaMetric bluetooth state");
return;
}
}
const bool shouldBluetoothBeEnabled = !SmartThingsManager::Get().IsSwitchEnabled(Config::c_disableLaMetricBluetoothDevice, false);
if (*m_shouldBeEnabled == shouldBluetoothBeEnabled)
{
return;
}
m_shouldBeEnabled = shouldBluetoothBeEnabled;
{
char bodyBuffer[256];
snprintf(bodyBuffer, sizeof(bodyBuffer), R"rl({ "active": %s })rl", shouldBluetoothBeEnabled ? "true" : "false");
Utils::PutToLaMetric(Config::c_laMetricDeviceBluetooth, bodyBuffer);
}
}
}