24
24
#include " PhilipsHueEntertainmentController.h"
25
25
#include " RGBController_PhilipsHue.h"
26
26
#include " RGBController_PhilipsHueEntertainment.h"
27
- #include " SettingsManager .h"
27
+ #include " PhilipsHueSettingsHandler .h"
28
28
29
29
/* *****************************************************************************************\
30
30
* *
36
36
37
37
void DetectPhilipsHueControllers ()
38
38
{
39
- json hue_settings;
39
+ PhilipsHueSettingsHandler hue_settings;
40
40
41
41
/* -------------------------------------------------*\
42
42
| Create an HTTP handler |
@@ -47,11 +47,6 @@ void DetectPhilipsHueControllers()
47
47
using SystemHttpHandler = hueplusplus::LinHttpHandler;
48
48
#endif
49
49
50
- /* -------------------------------------------------*\
51
- | Get Philips Hue settings from settings manager |
52
- \*-------------------------------------------------*/
53
- hue_settings = ResourceManager::get ()->GetSettingsManager ()->GetSettings (" PhilipsHueDevices" );
54
-
55
50
/* -------------------------------------------------*\
56
51
| Create a finder and find bridges |
57
52
\*-------------------------------------------------*/
@@ -62,24 +57,14 @@ void DetectPhilipsHueControllers()
62
57
| If no bridges were detected, manually add bridge |
63
58
| IP and MAC (need to get these from file) |
64
59
\*-------------------------------------------------*/
65
- if (bridges. empty () )
60
+ if (hue_settings. GetBridgeCount () > 0 )
66
61
{
67
- if (hue_settings.contains (" bridges" ))
68
- {
69
- hueplusplus::BridgeFinder::BridgeIdentification ident;
62
+ hueplusplus::BridgeFinder::BridgeIdentification ident;
70
63
71
- if (hue_settings[" bridges" ][0 ].contains (" ip" ))
72
- {
73
- ident.ip = hue_settings[" bridges" ][0 ][" ip" ];
74
- }
75
-
76
- if (hue_settings[" bridges" ][0 ].contains (" mac" ))
77
- {
78
- ident.mac = hue_settings[" bridges" ][0 ][" mac" ];
79
- }
64
+ ident.ip = hue_settings.GetBridgeIP (0 );
65
+ ident.mac = hue_settings.GetBridgeMAC (0 );
80
66
81
- bridges.push_back (ident);
82
- }
67
+ bridges.push_back (ident);
83
68
}
84
69
85
70
/* -------------------------------------------------*\
@@ -95,22 +80,22 @@ void DetectPhilipsHueControllers()
95
80
/* -------------------------------------------------*\
96
81
| Check if a saved username exists |
97
82
\*-------------------------------------------------*/
98
- if (hue_settings.contains ( " bridges " ) )
83
+ if (hue_settings.GetBridgeCount () > 0 )
99
84
{
100
85
/* -------------------------------------------------*\
101
86
| Add the username if it exists |
102
87
\*-------------------------------------------------*/
103
- if (hue_settings[ " bridges " ][ 0 ]. contains ( " username " ))
88
+ if (hue_settings. BridgeHasUsername ( 0 ))
104
89
{
105
- finder.addUsername (bridges[0 ].mac , hue_settings[ " bridges " ][ 0 ][ " username " ] );
90
+ finder.addUsername (bridges[0 ].mac , hue_settings. GetBridgeUsername ( 0 ) );
106
91
}
107
92
108
93
/* -------------------------------------------------*\
109
94
| Add the client key if it exists |
110
95
\*-------------------------------------------------*/
111
- if (hue_settings[ " bridges " ][ 0 ]. contains ( " clientkey " ))
96
+ if (hue_settings. BridgeHasClientKey ( 0 ))
112
97
{
113
- finder.addClientKey (bridges[0 ].mac , hue_settings[ " bridges " ][ 0 ][ " clientkey " ] );
98
+ finder.addClientKey (bridges[0 ].mac , hue_settings. GetBridgeClientKey ( 0 ) );
114
99
}
115
100
}
116
101
@@ -134,11 +119,11 @@ void DetectPhilipsHueControllers()
134
119
bool use_entertainment = false ;
135
120
bool auto_connect = false ;
136
121
137
- if (hue_settings.contains ( " bridges " ) )
122
+ if (hue_settings.GetBridgeCount () > 0 )
138
123
{
139
- if (hue_settings[ " bridges " ][ 0 ]. contains ( " username " ))
124
+ if (hue_settings. BridgeHasUsername ( 0 ))
140
125
{
141
- if (hue_settings[ " bridges " ][ 0 ][ " username " ] != bridge.getUsername ())
126
+ if (hue_settings. GetBridgeUsername ( 0 ) != bridge.getUsername ())
142
127
{
143
128
save_settings = true ;
144
129
}
@@ -148,9 +133,9 @@ void DetectPhilipsHueControllers()
148
133
save_settings = true ;
149
134
}
150
135
151
- if (hue_settings[ " bridges " ][ 0 ]. contains ( " clientkey " ))
136
+ if (hue_settings. BridgeHasClientKey ( 0 ))
152
137
{
153
- if (hue_settings[ " bridges " ][ 0 ][ " clientkey " ] != bridge.getClientKey ())
138
+ if (hue_settings. GetBridgeClientKey ( 0 ) != bridge.getClientKey ())
154
139
{
155
140
use_entertainment = true ;
156
141
save_settings = true ;
@@ -167,28 +152,18 @@ void DetectPhilipsHueControllers()
167
152
\*-------------------------------------------------*/
168
153
if (save_settings)
169
154
{
170
- hue_settings[" bridges" ][0 ][" username" ] = bridge.getUsername ();
171
- hue_settings[" bridges" ][0 ][" clientkey" ] = bridge.getClientKey ();
172
- hue_settings[" bridges" ][0 ][" entertainment" ] = use_entertainment;
173
- hue_settings[" bridges" ][0 ][" autoconnect" ] = auto_connect;
174
-
175
- ResourceManager::get ()->GetSettingsManager ()->SetSettings (" PhilipsHueDevices" , hue_settings);
176
-
177
- ResourceManager::get ()->GetSettingsManager ()->SaveSettings ();
155
+ hue_settings.SetBridgeUsername (0 , bridge.getUsername ());
156
+ hue_settings.SetBridgeClientKey (0 , bridge.getClientKey ());
157
+ hue_settings.SetBridgeUseEntertainment (0 , use_entertainment);
158
+ hue_settings.SetBridgeAutoconnect (0 , auto_connect);
159
+ hue_settings.SaveSettings ();
178
160
}
179
161
180
162
/* -------------------------------------------------*\
181
- | Get entertainment mode settings |
163
+ | Get entertainment mode settings |
182
164
\*-------------------------------------------------*/
183
- if (hue_settings[" bridges" ][0 ].contains (" entertainment" ))
184
- {
185
- use_entertainment = hue_settings[" bridges" ][0 ][" entertainment" ];
186
- }
187
-
188
- if (hue_settings[" bridges" ][0 ].contains (" autoconnect" ))
189
- {
190
- auto_connect = hue_settings[" bridges" ][0 ][" autoconnect" ];
191
- }
165
+ use_entertainment = hue_settings.GetBridgeUseEntertainment (0 );
166
+ auto_connect = hue_settings.GetBridgeAutoconnect (0 );
192
167
193
168
/* -------------------------------------------------*\
194
169
| Get all groups from the bridge |
0 commit comments