@@ -74,7 +74,7 @@ void ReloadLights()
74
74
75
75
private void MainForm_Load ( object sender , EventArgs e )
76
76
{
77
- RefreshCameraState ( ) ;
77
+ RefreshCamerasState ( ) ;
78
78
tmrCameraCheck_Tick ( sender , e ) ;
79
79
80
80
ReloadLights ( ) ;
@@ -129,69 +129,74 @@ private void MainForm_Load(object sender, EventArgs e)
129
129
Icon = Properties . Resources . Icon ;
130
130
}
131
131
132
- private async void RefreshCameraState ( )
132
+ private void RefreshCamerasState ( )
133
+ {
134
+ foreach ( string IP in lbIPs . Items )
135
+ {
136
+ RefreshCameraState ( IP ) ;
137
+ }
138
+ }
139
+
140
+ private async void RefreshCameraState ( string IP )
133
141
{
134
142
lblError . Visible = false ;
135
143
136
- foreach ( string IP in lbIPs . Items )
144
+ try
137
145
{
138
- try
139
- {
140
- string keylightURL = $ "http://{ IP } :9123/elgato/lights";
146
+ string keylightURL = $ "http://{ IP } :9123/elgato/lights";
141
147
142
- HttpResponseMessage response = await httpClient . GetAsync ( keylightURL , requestStateToken ) ;
148
+ HttpResponseMessage response = await httpClient . GetAsync ( keylightURL , requestStateToken ) ;
143
149
144
- if ( response . IsSuccessStatusCode )
145
- {
146
- bool success = false ;
150
+ if ( response . IsSuccessStatusCode )
151
+ {
152
+ bool success = false ;
147
153
148
- JsonNode ? responseRoot = JsonNode . Parse ( await response . Content . ReadAsStringAsync ( requestStateToken ) ) ;
149
- if ( responseRoot != null )
154
+ JsonNode ? responseRoot = JsonNode . Parse ( await response . Content . ReadAsStringAsync ( requestStateToken ) ) ;
155
+ if ( responseRoot != null )
156
+ {
157
+ JsonNode ? lightsArray = responseRoot . AsObject ( ) [ "lights" ] ;
158
+ if ( lightsArray != null )
150
159
{
151
- JsonNode ? lightsArray = responseRoot . AsObject ( ) [ "lights" ] ;
152
- if ( lightsArray != null )
160
+ JsonNode ? lightObject = lightsArray . AsArray ( ) [ 0 ] ;
161
+ if ( lightObject != null )
153
162
{
154
- JsonNode ? lightObject = lightsArray . AsArray ( ) [ 0 ] ;
155
- if ( lightObject != null )
163
+ JsonNode ? onProperty = lightObject . AsObject ( ) [ "on" ] ;
164
+ if ( onProperty != null )
156
165
{
157
- JsonNode ? onProperty = lightObject . AsObject ( ) [ "on" ] ;
158
- if ( onProperty != null )
159
- {
160
- isCameraOn = onProperty . GetValue < int > ( ) == 1 ;
161
- lblLightState . Text = isCameraOn ? "Lights are ON" : "Lights are OFF" ;
162
- lblLightState . ForeColor = isCameraOn ? Color . LawnGreen : Color . IndianRed ;
163
- success = true ;
164
- }
166
+ isCameraOn = onProperty . GetValue < int > ( ) == 1 ;
167
+ lblLightState . Text = isCameraOn ? "Lights are ON" : "Lights are OFF" ;
168
+ lblLightState . ForeColor = isCameraOn ? Color . LawnGreen : Color . IndianRed ;
169
+ success = true ;
165
170
}
166
171
}
167
172
}
168
-
169
- if ( ! success )
170
- {
171
- lblError . Visible = true ;
172
- lblError . Text = "Malformed JSON please\n create an Issue on GitHub" ;
173
- }
174
173
}
175
- else
174
+
175
+ if ( ! success )
176
176
{
177
177
lblError . Visible = true ;
178
- lblLightState . Text = $ "Error, check IP: { IP } ";
178
+ lblError . Text = "Malformed JSON please \n create an Issue on GitHub ";
179
179
}
180
180
}
181
- catch
181
+ else
182
182
{
183
183
lblError . Visible = true ;
184
- lblError . Text = $ "Error, check IP: { IP } ";
185
-
186
- requestStateTokenSource = new CancellationTokenSource ( ) ;
187
- requestStateToken = requestStateTokenSource . Token ;
184
+ lblLightState . Text = $ "Error, check IP: { IP } ";
188
185
}
189
186
}
187
+ catch
188
+ {
189
+ lblError . Visible = true ;
190
+ lblError . Text = $ "Error, check IP: { IP } ";
191
+
192
+ requestStateTokenSource = new CancellationTokenSource ( ) ;
193
+ requestStateToken = requestStateTokenSource . Token ;
194
+ }
190
195
}
191
196
192
197
private void CameraIsOn ( )
193
198
{
194
- RefreshCameraState ( ) ;
199
+ RefreshCamerasState ( ) ;
195
200
196
201
lblCameraState . Text = "Camera is ON" ;
197
202
lblCameraState . ForeColor = Color . LawnGreen ;
@@ -214,7 +219,7 @@ private void CameraIsOn()
214
219
215
220
private void CameraIsOff ( )
216
221
{
217
- RefreshCameraState ( ) ;
222
+ RefreshCamerasState ( ) ;
218
223
niTray . Icon = TrayIconUnlit ;
219
224
220
225
lblCameraState . Text = "Camera is OFF" ;
0 commit comments