Add CameraAccessory
This commit is contained in:
+19
-4
@@ -10,6 +10,7 @@ import { powerSwitchAccessory } from './powerSwitchAccessory'
|
||||
import { environmentSensorAccessory } from './environmentSensorAccessory'
|
||||
import { doorWindowSensorAccessory } from './doorWindowSensorAccessory'
|
||||
import { motionSensorAccessory } from './motionSensorAccessory'
|
||||
import { cameraAccessory } from './cameraAccessory'
|
||||
import { httpServer } from './httpServer'
|
||||
|
||||
export class domoticaPlatform implements DynamicPlatformPlugin {
|
||||
@@ -19,7 +20,7 @@ export class domoticaPlatform implements DynamicPlatformPlugin {
|
||||
public readonly accessories: accessory[] = []
|
||||
public readonly cachedAccessories: PlatformAccessory[] = []
|
||||
public readonly presentAccessories: PlatformAccessory[] = []
|
||||
|
||||
|
||||
private readonly discoveries: String[] = []
|
||||
private readonly completedDiscoveries: String[] = []
|
||||
|
||||
@@ -100,6 +101,16 @@ export class domoticaPlatform implements DynamicPlatformPlugin {
|
||||
.catch((error) => {
|
||||
this.log.debug('motionSensorAccessory.discoverDevices Error ->' + error)
|
||||
})
|
||||
|
||||
this.discoveryStarted('cameraAccessory')
|
||||
cameraAccessory.discoverDevices(this)
|
||||
.then((devices) => {
|
||||
this.processDiscoveredDevices(devices)
|
||||
this.discoveryCompleted('cameraAccessory')
|
||||
})
|
||||
.catch((error) => {
|
||||
this.log.debug('cameraAccessory.discoverDevices Error ->' + error)
|
||||
})
|
||||
}
|
||||
|
||||
processDiscoveredDevices(domoticaDevices: device[]) {
|
||||
@@ -130,6 +141,8 @@ export class domoticaPlatform implements DynamicPlatformPlugin {
|
||||
this.accessories.push(new doorWindowSensorAccessory(this, existingAccessory))
|
||||
} else if (existingAccessory.context.device.type == 'MotionSensor') {
|
||||
this.accessories.push(new motionSensorAccessory(this, existingAccessory))
|
||||
} else if (existingAccessory.context.device.type == 'Camera') {
|
||||
this.accessories.push(new cameraAccessory(this, existingAccessory))
|
||||
}
|
||||
} else {
|
||||
this.log.info('+ ' + device.type + ': ' + device.deviceName)
|
||||
@@ -149,6 +162,8 @@ export class domoticaPlatform implements DynamicPlatformPlugin {
|
||||
this.accessories.push(new doorWindowSensorAccessory(this, accessory))
|
||||
} else if (accessory.context.device.type == 'MotionSensor') {
|
||||
this.accessories.push(new motionSensorAccessory(this, accessory))
|
||||
} else if (accessory.context.device.type == 'Camera') {
|
||||
this.accessories.push(new cameraAccessory(this, accessory))
|
||||
}
|
||||
|
||||
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory])
|
||||
@@ -162,14 +177,14 @@ export class domoticaPlatform implements DynamicPlatformPlugin {
|
||||
|
||||
discoveryCompleted(deviceType) {
|
||||
this.completedDiscoveries.push(deviceType)
|
||||
|
||||
|
||||
if (this.completedDiscoveries.length == this.discoveries.length) {
|
||||
this.cleanupRemovedDevices()
|
||||
}
|
||||
|
||||
|
||||
//setInterval(this.updateAccessories.bind(this), 60 * 1000); // Poll every minute
|
||||
}
|
||||
|
||||
|
||||
updateAccessories() {
|
||||
for (const accessory of this.accessories) {
|
||||
accessory.update()
|
||||
|
||||
Reference in New Issue
Block a user