-
Notifications
You must be signed in to change notification settings - Fork 40
/
NukiOpenerWrapper.h
88 lines (69 loc) · 2.6 KB
/
NukiOpenerWrapper.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include "NukiOpener.h"
#include "NetworkOpener.h"
#include "NukiOpenerConstants.h"
#include "NukiDataTypes.h"
#include "BleScanner.h"
class NukiOpenerWrapper : public NukiOpener::SmartlockEventHandler
{
public:
NukiOpenerWrapper(const std::string& deviceName, uint32_t id, BleScanner::Scanner* scanner, NetworkOpener* network, Preferences* preferences);
virtual ~NukiOpenerWrapper();
void initialize();
void update();
void setPin(const uint16_t pin);
void unpair();
void disableHASS();
const NukiOpener::OpenerState& keyTurnerState();
const bool isPaired();
const BLEAddress getBleAddress() const;
BleScanner::Scanner* bleScanner();
void notify(NukiOpener::EventType eventType) override;
private:
static bool onLockActionReceivedCallback(const char* value);
static void onConfigUpdateReceivedCallback(const char* topic, const char* value);
void onConfigUpdateReceived(const char* topic, const char* value);
void updateKeyTurnerState();
void updateBatteryState();
void updateConfig();
void updateAuthData();
void readConfig();
void readAdvancedConfig();
void setupHASS();
NukiOpener::LockAction lockActionToEnum(const char* str); // char array at least 14 characters
std::string _deviceName;
NukiOpener::NukiOpener _nukiOpener;
BleScanner::Scanner* _bleScanner;
NetworkOpener* _network;
Preferences* _preferences;
int _intervalLockstate = 0; // seconds
int _intervalBattery = 0; // seconds
int _intervalConfig = 60 * 60; // seconds
int _restartBeaconTimeout = 0; // seconds
bool _publishAuthData = false;
bool _clearAuthData = false;
int _nrOfRetries = 0;
int _retryDelay = 0;
int _retryCount = 0;
unsigned long _nextRetryTs = 0;
NukiOpener::OpenerState _lastKeyTurnerState;
NukiOpener::OpenerState _keyTurnerState;
NukiOpener::BatteryReport _batteryReport;
NukiOpener::BatteryReport _lastBatteryReport;
NukiOpener::Config _nukiConfig = {0};
NukiOpener::AdvancedConfig _nukiAdvancedConfig = {0};
bool _nukiConfigValid = false;
bool _nukiAdvancedConfigValid = false;
bool _hassEnabled = false;
bool _hassSetupCompleted = false;
bool _paired = false;
bool _statusUpdated = false;
long _rssiPublishInterval = 0;
unsigned long _nextLockStateUpdateTs = 0;
unsigned long _nextBatteryReportTs = 0;
unsigned long _nextConfigUpdateTs = 0;
unsigned long _nextPairTs = 0;
long _nextRssiTs = 0;
unsigned long _lastRssi = 0;
NukiOpener::LockAction _nextLockAction = (NukiOpener::LockAction)0xff;
};