Working debug configuration
This commit is contained in:
@ -14,14 +14,18 @@ export interface IRoom {
|
||||
}
|
||||
|
||||
export const isRoom = (object: any): object is IRoom => {
|
||||
return "name" in object && "rtspCameraConnectionString" in object;
|
||||
return "name" in object && "rtspConnectionStrings" in object;
|
||||
};
|
||||
|
||||
export const isConfig = (object: any): object is IConfig => {
|
||||
const roomsOkay =
|
||||
object["rooms"].filter((room: any) => isRoom(room)).length ===
|
||||
object["rooms"].length;
|
||||
return (
|
||||
"refImageDirectory" in object &&
|
||||
"trainedModelDirectory" in object &&
|
||||
"weightDirectory" in object &&
|
||||
"rooms" in object &&
|
||||
isRoom(object["rooms"])
|
||||
roomsOkay
|
||||
);
|
||||
};
|
||||
|
@ -5,7 +5,7 @@ import {
|
||||
CharacteristicSetCallback,
|
||||
CharacteristicGetCallback,
|
||||
} from "homebridge";
|
||||
|
||||
import { LocationMonitor } from "./locationMonitor";
|
||||
import { HomeLocationPlatform } from "./platform";
|
||||
|
||||
/**
|
||||
@ -27,7 +27,8 @@ export class MonitorAccessory {
|
||||
|
||||
constructor(
|
||||
private readonly platform: HomeLocationPlatform,
|
||||
private readonly accessory: PlatformAccessory
|
||||
private readonly accessory: PlatformAccessory,
|
||||
private monitor: LocationMonitor
|
||||
) {
|
||||
// set accessory information
|
||||
this.accessory
|
||||
@ -42,17 +43,17 @@ export class MonitorAccessory {
|
||||
"Default-Serial"
|
||||
);
|
||||
|
||||
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
||||
// get the MotionSensor service if it exists, otherwise create a new MotionSensor service
|
||||
// you can create multiple services for each accessory
|
||||
this.service =
|
||||
this.accessory.getService(this.platform.Service.Lightbulb) ||
|
||||
this.accessory.addService(this.platform.Service.Lightbulb);
|
||||
this.accessory.getService(this.platform.Service.MotionSensor) ||
|
||||
this.accessory.addService(this.platform.Service.MotionSensor);
|
||||
|
||||
// set the service name, this is what is displayed as the default name on the Home app
|
||||
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
||||
this.service.setCharacteristic(
|
||||
this.platform.Characteristic.Name,
|
||||
accessory.context.device.exampleDisplayName
|
||||
accessory.context["DeviceName"]
|
||||
);
|
||||
|
||||
// each service must implement at-minimum the "required characteristics" for the given service type
|
||||
|
@ -19,7 +19,8 @@ import {
|
||||
FaceMatcher,
|
||||
} from "@vladmandic/face-api";
|
||||
import * as mime from "mime-types";
|
||||
import { getFaceDetectorOptions } from "../src/common";
|
||||
import { LocationMonitor } from "./locationMonitor";
|
||||
import { getFaceDetectorOptions } from "./common";
|
||||
require("@tensorflow/tfjs-node");
|
||||
|
||||
const { Canvas, Image, ImageData } = canvas;
|
||||
@ -99,16 +100,7 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
|
||||
faceMatcher = FaceMatcher.fromJSON(JSON.parse(raw));
|
||||
}
|
||||
|
||||
const exampleDevices = [
|
||||
{
|
||||
exampleUniqueId: "ABCD",
|
||||
exampleDisplayName: "Bedroom",
|
||||
},
|
||||
{
|
||||
exampleUniqueId: "EFGH",
|
||||
exampleDisplayName: "Kitchen",
|
||||
},
|
||||
];
|
||||
const locationMonitor = new LocationMonitor(this.config.rooms, faceMatcher);
|
||||
|
||||
const labels = faceMatcher.labeledDescriptors.map((e) => e.label);
|
||||
for (const room of this.config.rooms) {
|
||||
@ -122,28 +114,23 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
|
||||
existingAccessory.displayName
|
||||
);
|
||||
|
||||
// this is imported from `platformAccessory.ts`
|
||||
new MonitorAccessory(this, existingAccessory);
|
||||
new MonitorAccessory(this, existingAccessory, locationMonitor);
|
||||
|
||||
// update accessory cache with any changes to the accessory details and information
|
||||
this.api.updatePlatformAccessories([existingAccessory]);
|
||||
} else {
|
||||
// the accessory does not yet exist, so we need to create it
|
||||
this.log.info("Adding new accessory:", `${room}+${label}`);
|
||||
this.log.info("Adding new accessory:", `${room.name}+${label}`);
|
||||
|
||||
// create a new accessory
|
||||
const accessory = new this.api.platformAccessory(
|
||||
`${room}+${label}`,
|
||||
`${room.name} ${label}`,
|
||||
uuid
|
||||
);
|
||||
|
||||
// store a copy of the device object in the `accessory.context`
|
||||
// the `context` property can be used to store any data about the accessory you may need
|
||||
// accessory.context.device = device;
|
||||
accessory.context["DeviceName"] = `${room.name} ${label}`;
|
||||
|
||||
// create the accessory handler for the newly create accessory
|
||||
// this is imported from `platformAccessory.ts`
|
||||
new MonitorAccessory(this, accessory);
|
||||
new MonitorAccessory(this, accessory, locationMonitor);
|
||||
|
||||
// link the accessory to your platform
|
||||
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
||||
@ -152,73 +139,6 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loop over the discovered devices and register each one if it has not already been registered
|
||||
for (const device of exampleDevices) {
|
||||
// generate a unique id for the accessory this should be generated from
|
||||
// something globally unique, but constant, for example, the device serial
|
||||
// number or MAC address
|
||||
const uuid = this.api.hap.uuid.generate(device.exampleUniqueId);
|
||||
|
||||
// see if an accessory with the same uuid has already been registered and restored from
|
||||
// the cached devices we stored in the `configureAccessory` method above
|
||||
const existingAccessory = this.accessories.find(
|
||||
(accessory) => accessory.UUID === uuid
|
||||
);
|
||||
|
||||
if (existingAccessory) {
|
||||
// the accessory already exists
|
||||
if (device) {
|
||||
this.log.info(
|
||||
"Restoring existing accessory from cache:",
|
||||
existingAccessory.displayName
|
||||
);
|
||||
|
||||
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
||||
// existingAccessory.context.device = device;
|
||||
// this.api.updatePlatformAccessories([existingAccessory]);
|
||||
|
||||
// create the accessory handler for the restored accessory
|
||||
// this is imported from `platformAccessory.ts`
|
||||
new MonitorAccessory(this, existingAccessory);
|
||||
|
||||
// update accessory cache with any changes to the accessory details and information
|
||||
this.api.updatePlatformAccessories([existingAccessory]);
|
||||
} else if (!device) {
|
||||
// it is possible to remove platform accessories at any time using `api.unregisterPlatformAccessories`, eg.:
|
||||
// remove platform accessories when no longer present
|
||||
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
||||
existingAccessory,
|
||||
]);
|
||||
this.log.info(
|
||||
"Removing existing accessory from cache:",
|
||||
existingAccessory.displayName
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// the accessory does not yet exist, so we need to create it
|
||||
this.log.info("Adding new accessory:", device.exampleDisplayName);
|
||||
|
||||
// create a new accessory
|
||||
const accessory = new this.api.platformAccessory(
|
||||
device.exampleDisplayName,
|
||||
uuid
|
||||
);
|
||||
|
||||
// store a copy of the device object in the `accessory.context`
|
||||
// the `context` property can be used to store any data about the accessory you may need
|
||||
accessory.context.device = device;
|
||||
|
||||
// create the accessory handler for the newly create accessory
|
||||
// this is imported from `platformAccessory.ts`
|
||||
new MonitorAccessory(this, accessory);
|
||||
|
||||
// link the accessory to your platform
|
||||
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
||||
accessory,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async trainModels(): Promise<FaceMatcher> {
|
||||
|
@ -6,4 +6,4 @@ export const PLATFORM_NAME = "HomeLocation";
|
||||
/**
|
||||
* This must match the name of your plugin as defined the package.json
|
||||
*/
|
||||
export const PLUGIN_NAME = "homebridge-home-location";
|
||||
export const PLUGIN_NAME = "homebridge-face-location";
|
||||
|
Reference in New Issue
Block a user