-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomeAssistantMqttService.cpp
40 lines (33 loc) · 1.64 KB
/
HomeAssistantMqttService.cpp
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
#include "HomeAssistantMqttService.h"
#include <ArduinoJson.h>
#include "dbg.h"
static const char* HOME_ASSISTANT_SETTINGS_ENDPOINT = "/rest/ha";
static const char* HOME_ASSISTANT_SETTINGS_FILE = "/config/ha";
static void homeAssistantMqttSettingsSerialize(HomeAssistantMqttSettings& settings, JsonObject& root) {
root["name"] = settings.deviceDisplayName;
DBG("Serialize called with %s\n", settings.deviceDisplayName.c_str());
}
static StateUpdateResult homeAssistantMqttSettingsDeserialize(JsonObject& root, HomeAssistantMqttSettings& settings) {
settings.deviceDisplayName = root["name"] | "";
if (settings.deviceDisplayName.isEmpty()) {
settings.deviceDisplayName = F("Cointreau Bottle");
}
DBG("Deserialize called with %s\n", settings.deviceDisplayName.c_str());
return StateUpdateResult::CHANGED;
}
HomeAssistantMqttService::HomeAssistantMqttService(LightControllerService* lightControllerService,
AsyncWebServer* server,
FS* fs,
SecurityManager* securityManager) :
_httpEndpoint(homeAssistantMqttSettingsSerialize,
homeAssistantMqttSettingsDeserialize,
this,
server,
HOME_ASSISTANT_SETTINGS_ENDPOINT,
securityManager,
AuthenticationPredicates::IS_AUTHENTICATED),
_fsPersistence(homeAssistantMqttSettingsSerialize,
homeAssistantMqttSettingsDeserialize,
this,
fs,
HOME_ASSISTANT_SETTINGS_FILE) {}