Skip to content

Commit 238197f

Browse files
committed
Add HTTP automation messages
1 parent 3ab8598 commit 238197f

File tree

4 files changed

+72
-13
lines changed

4 files changed

+72
-13
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## v2.4.5 (2020-08-15)
6+
7+
### Changes
8+
9+
- Return messages and error codes when using HTTP automation.
10+
11+
### Bug Fixes
12+
13+
- Fixed bug preventing MQTT/HTTP automation from working.
14+
515
## v2.4.4 (2020-08-07)
616

717
### Changes
818

9-
- Added support for unbridging specific cameras.This can aid with performance of the camera and Homebridge as a whole, but requires manually adding any unbridged cameras to HomeKit.
19+
- Added support for unbridging specific cameras. This can aid with performance of the camera and Homebridge as a whole, but requires manually adding any unbridged cameras to HomeKit.
1020

1121
## v2.4.3 (2020-07-29)
1222

config.schema.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@
253253
"debug": {
254254
"title": "Debug Logging",
255255
"type": "boolean",
256-
"default": true,
257256
"description": "Includes debugging output from FFmpeg in the Homebridge log."
258257
}
259258
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"displayName": "Homebridge Camera FFmpeg",
33
"name": "homebridge-camera-ffmpeg",
4-
"version": "2.4.4",
4+
"version": "2.4.5",
55
"description": "Homebridge Plugin Providing FFmpeg-based Camera Support",
66
"main": "dist/index.js",
77
"license": "ISC",

src/index.ts

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ let Accessory: typeof PlatformAccessory;
2727
const PLUGIN_NAME = 'homebridge-camera-ffmpeg';
2828
const PLATFORM_NAME = 'Camera-ffmpeg';
2929

30+
type AutomationReturn = {
31+
error: boolean;
32+
message: string;
33+
};
34+
3035
class FfmpegPlatform implements DynamicPlatformPlugin {
3136
private readonly log: Logger;
3237
private readonly api: API;
@@ -180,7 +185,7 @@ class FfmpegPlatform implements DynamicPlatformPlugin {
180185
this.cachedAccessories.push(accessory);
181186
}
182187

183-
private doorbellHandler(accessory: PlatformAccessory, active = true): void {
188+
private doorbellHandler(accessory: PlatformAccessory, active = true): AutomationReturn {
184189
const doorbell = accessory.getService(hap.Service.Doorbell);
185190
if (doorbell) {
186191
this.log.debug('Switch doorbell ' + (active ? 'on.' : 'off.'), accessory.displayName);
@@ -204,13 +209,28 @@ class FfmpegPlatform implements DynamicPlatformPlugin {
204209
}, timeoutConfig * 1000);
205210
this.doorbellTimers.set(accessory.UUID, timer);
206211
}
207-
} else if (doorbellTrigger) {
208-
doorbellTrigger.updateCharacteristic(hap.Characteristic.On, true);
212+
return {
213+
error: false,
214+
message: 'Doorbell switched on.'
215+
};
216+
} else {
217+
if (doorbellTrigger) {
218+
doorbellTrigger.updateCharacteristic(hap.Characteristic.On, false);
219+
}
220+
return {
221+
error: false,
222+
message: 'Doorbell switched off.'
223+
};
209224
}
225+
} else {
226+
return {
227+
error: true,
228+
message: 'Doorbell is not enabled for this camera.'
229+
};
210230
}
211231
}
212232

213-
private motionHandler(accessory: PlatformAccessory, active = true, minimumTimeout = 0): void {
233+
private motionHandler(accessory: PlatformAccessory, active = true, minimumTimeout = 0): AutomationReturn {
214234
const motionSensor = accessory.getService(hap.Service.MotionSensor);
215235
if (motionSensor) {
216236
this.log.debug('Switch motion detect ' + (active ? 'on.' : 'off.'), accessory.displayName);
@@ -240,27 +260,52 @@ class FfmpegPlatform implements DynamicPlatformPlugin {
240260
}, timeoutConfig * 1000);
241261
this.motionTimers.set(accessory.UUID, timer);
242262
}
263+
return {
264+
error: false,
265+
message: 'Motion switched on.'
266+
};
243267
} else {
244268
motionSensor.updateCharacteristic(hap.Characteristic.MotionDetected, false);
245269
if (motionTrigger) {
246270
motionTrigger.updateCharacteristic(hap.Characteristic.On, false);
247271
}
272+
return {
273+
error: false,
274+
message: 'Motion switched off.'
275+
};
248276
}
277+
} else {
278+
return {
279+
error: true,
280+
message: 'Motion is not enabled for this camera.'
281+
};
249282
}
250283
}
251284

252-
private automationHandler(fullpath: string, name: string): void{
253-
const accessory = this.cachedAccessories.find((curAcc: PlatformAccessory) => curAcc.displayName == name);
285+
private automationHandler(fullpath: string, name: string): AutomationReturn {
286+
const accessory = this.cachedAccessories.find((curAcc: PlatformAccessory) => {
287+
return curAcc.displayName == name;
288+
});
254289
if (accessory) {
255290
const path = fullpath.split('/').filter((value) => value.length > 0);
256291
switch (path[0]) {
257292
case 'motion':
258-
this.motionHandler(accessory, path[1] != 'reset');
293+
return this.motionHandler(accessory, path[1] != 'reset');
259294
break;
260295
case 'doorbell':
261-
this.doorbellHandler(accessory);
296+
return this.doorbellHandler(accessory);
262297
break;
298+
default:
299+
return {
300+
error: true,
301+
message: 'First directory level must be "motion" or "doorbell", got "' + path[0] + '".'
302+
};
263303
}
304+
} else {
305+
return {
306+
error: true,
307+
message: 'Camera "' + name + '" not found.'
308+
};
264309
}
265310
}
266311

@@ -295,14 +340,19 @@ class FfmpegPlatform implements DynamicPlatformPlugin {
295340
const hostname = this.config.localhttp ? 'localhost' : undefined;
296341
server.listen(this.config.porthttp, hostname);
297342
server.on('request', (request: http.IncomingMessage, response: http.ServerResponse) => {
343+
let results: AutomationReturn = {
344+
error: true,
345+
message: 'Malformed URL.'
346+
};
298347
if (request.url) {
299348
const parseurl = url.parse(request.url);
300349
if (parseurl.pathname && parseurl.query) {
301350
const name = decodeURIComponent(parseurl.query);
302-
this.automationHandler(parseurl.pathname, name);
351+
results = this.automationHandler(parseurl.pathname, name);
303352
}
304353
}
305-
response.writeHead(200);
354+
response.writeHead(results.error ? 500 : 200);
355+
response.write(results.message);
306356
response.end();
307357
});
308358
}

0 commit comments

Comments
 (0)