homebridge-unifi-access 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE.md +3 -3
  2. package/README.md +88 -3
  3. package/config.schema.json +202 -0
  4. package/dist/access-controller.d.ts +45 -0
  5. package/dist/access-controller.js +387 -0
  6. package/dist/access-controller.js.map +1 -0
  7. package/dist/access-device.d.ts +53 -0
  8. package/dist/access-device.js +362 -0
  9. package/dist/access-device.js.map +1 -0
  10. package/dist/access-events.d.ts +24 -0
  11. package/dist/access-events.js +151 -0
  12. package/dist/access-events.js.map +1 -0
  13. package/dist/access-hub.d.ts +21 -0
  14. package/dist/access-hub.js +269 -0
  15. package/dist/access-hub.js.map +1 -0
  16. package/dist/access-mqtt.d.ts +20 -0
  17. package/dist/access-mqtt.js +163 -0
  18. package/dist/access-mqtt.js.map +1 -0
  19. package/dist/access-options.d.ts +38 -0
  20. package/dist/access-options.js +167 -0
  21. package/dist/access-options.js.map +1 -0
  22. package/dist/access-platform.d.ts +16 -0
  23. package/dist/access-platform.js +103 -0
  24. package/dist/access-platform.js.map +1 -0
  25. package/dist/access-types.d.ts +11 -0
  26. package/dist/access-types.js +13 -0
  27. package/dist/access-types.js.map +1 -0
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.js +9 -5
  30. package/dist/index.js.map +1 -1
  31. package/dist/settings.d.ts +10 -0
  32. package/dist/settings.js +23 -10
  33. package/dist/settings.js.map +1 -1
  34. package/homebridge-ui/public/access-featureoptions.mjs +748 -0
  35. package/homebridge-ui/public/index.html +151 -0
  36. package/homebridge-ui/public/lib/featureoptions.mjs +201 -0
  37. package/homebridge-ui/public/ui.mjs +182 -0
  38. package/homebridge-ui/server.js +153 -0
  39. package/package.json +55 -23
  40. package/.eslintrc.json +0 -45
  41. package/dist/platform.js +0 -98
  42. package/dist/platform.js.map +0 -1
  43. package/dist/platformAccessory.js +0 -104
  44. package/dist/platformAccessory.js.map +0 -1
  45. package/src/index.ts +0 -11
  46. package/src/platform.ts +0 -116
  47. package/src/platformAccessory.ts +0 -130
  48. package/src/settings.ts +0 -9
  49. package/tsconfig.json +0 -20
package/package.json CHANGED
@@ -1,40 +1,72 @@
1
1
  {
2
- "displayName": "Plugin Name",
3
2
  "name": "homebridge-unifi-access",
4
- "version": "0.0.1",
5
- "description": "UniFi Access plugin for HomeKit (Homebridge).",
3
+ "version": "1.0.0",
4
+ "displayName": "Homebridge UniFi Access",
5
+ "description": "Homebridge UniFi Access plugin providing complete HomeKit integration for the UniFi Access ecosystem with full support for most features including autoconfiguration, motion detection, multiple controllers, and realtime updates.",
6
+ "author": {
7
+ "name": "HJD",
8
+ "url": "https://github.com/hjdhjd"
9
+ },
10
+ "homepage": "https://github.com/hjdhjd/homebridge-unifi-access#readme",
6
11
  "license": "ISC",
7
12
  "repository": {
8
13
  "type": "git",
9
14
  "url": "git://github.com/hjdhjd/homebridge-unifi-access.git"
10
15
  },
11
16
  "bugs": {
12
- "url": "https://github.com/hjdhjd/homebridge-unifi-access/issues"
17
+ "url": "http://github.com/hjdhjd/homebridge-unifi-access/issues"
13
18
  },
19
+ "type": "module",
14
20
  "engines": {
15
- "node": ">=10.17.0",
16
- "homebridge": ">0.4.53"
21
+ "homebridge": ">=1.6.0",
22
+ "node": ">=18"
17
23
  },
18
- "main": "dist/index.js",
24
+ "keywords": [
25
+ "homebridge",
26
+ "homebridge-plugin",
27
+ "homebridge-unifi-access",
28
+ "homekit",
29
+ "camera",
30
+ "doorbell",
31
+ "ubiquiti",
32
+ "unifi",
33
+ "unifi access",
34
+ "unifi protect",
35
+ "motion",
36
+ "motion sensor",
37
+ "security",
38
+ "udm",
39
+ "udm pro",
40
+ "udm-pro",
41
+ "unifi camera",
42
+ "unifi cloud key",
43
+ "unifi dream machine pro",
44
+ "unifios"
45
+ ],
19
46
  "scripts": {
20
- "lint": "eslint src/**.ts",
21
- "watch": "npm run build && npm link && nodemon",
22
47
  "build": "rimraf ./dist && tsc",
23
- "prepublishOnly": "npm run lint && npm run build"
48
+ "clean": "rimraf ./dist",
49
+ "lint": "eslint src/**.ts",
50
+ "jlint": "eslint homebridge-ui/public/**.mjs",
51
+ "postpublish": "npm run clean",
52
+ "prepublishOnly": "npm run lint && npm run build",
53
+ "test": "eslint src/**.ts",
54
+ "watch": "npm run build && npm link && nodemon"
55
+ },
56
+ "main": "dist/index.js",
57
+ "dependencies": {
58
+ "@homebridge/plugin-ui-utils": "1.0.1",
59
+ "mqtt": "5.3.6",
60
+ "unifi-access": "1.0.0"
24
61
  },
25
- "keywords": [
26
- "homebridge-plugin"
27
- ],
28
- "dependencies": {},
29
62
  "devDependencies": {
30
- "@types/node": "^14.0.14",
31
- "@typescript-eslint/eslint-plugin": "^3.4.0",
32
- "@typescript-eslint/parser": "^3.4.0",
33
- "eslint": "^7.3.1",
34
- "homebridge": "^1.1.1",
35
- "nodemon": "^2.0.4",
36
- "rimraf": "^3.0.2",
37
- "ts-node": "^8.10.2",
38
- "typescript": "^3.9.5"
63
+ "@stylistic/eslint-plugin": "1.6.3",
64
+ "@types/node": "20.11.26",
65
+ "@typescript-eslint/eslint-plugin": "7.2.0",
66
+ "@typescript-eslint/parser": "7.2.0",
67
+ "eslint": "8.57.0",
68
+ "homebridge": "1.7.0",
69
+ "rimraf": "5.0.5",
70
+ "typescript": "5.4.2"
39
71
  }
40
72
  }
package/.eslintrc.json DELETED
@@ -1,45 +0,0 @@
1
- {
2
- "parser": "@typescript-eslint/parser",
3
- "extends": [
4
- "eslint:recommended",
5
- "plugin:@typescript-eslint/eslint-recommended",
6
- "plugin:@typescript-eslint/recommended"
7
- ],
8
- "parserOptions": {
9
- "ecmaVersion": 2018,
10
- "sourceType": "module"
11
- },
12
- "ignorePatterns": ["dist"],
13
- "rules": {
14
- "quotes": ["warn", "double", {"avoidEscape": true}],
15
- "indent": [
16
- "warn",
17
- 2,
18
- {
19
- "SwitchCase": 1
20
- }
21
- ],
22
- "linebreak-style": ["warn", "unix"],
23
- "semi": ["warn", "always"],
24
- "comma-dangle": ["error"],
25
- "dot-notation": "warn",
26
- "eqeqeq": "warn",
27
- "curly": ["warn", "all"],
28
- "brace-style": ["warn"],
29
- "prefer-arrow-callback": ["warn"],
30
- "max-len": ["warn", 170],
31
- "no-console": ["warn"],
32
- "lines-between-class-members": [
33
- "warn",
34
- "always",
35
- {
36
- "exceptAfterSingleLine": true
37
- }
38
- ],
39
- "@typescript-eslint/explicit-function-return-type": "off",
40
- "@typescript-eslint/no-non-null-assertion": "off",
41
- "@typescript-eslint/explicit-module-boundary-types": "off",
42
- "@typescript-eslint/no-explicit-any": "off",
43
- "@typescript-eslint/no-this-alias": "off"
44
- }
45
- }
package/dist/platform.js DELETED
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExampleHomebridgePlatform = void 0;
4
- const settings_1 = require("./settings");
5
- const platformAccessory_1 = require("./platformAccessory");
6
- /**
7
- * HomebridgePlatform
8
- * This class is the main constructor for your plugin, this is where you should
9
- * parse the user config and discover/register accessories with Homebridge.
10
- */
11
- class ExampleHomebridgePlatform {
12
- constructor(log, config, api) {
13
- this.log = log;
14
- this.config = config;
15
- this.api = api;
16
- this.Service = this.api.hap.Service;
17
- this.Characteristic = this.api.hap.Characteristic;
18
- // this is used to track restored cached accessories
19
- this.accessories = [];
20
- this.log.debug("Finished initializing platform:", this.config.name);
21
- // When this event is fired it means Homebridge has restored all cached accessories from disk.
22
- // Dynamic Platform plugins should only register new accessories after this event was fired,
23
- // in order to ensure they weren't added to homebridge already. This event can also be used
24
- // to start discovery of new accessories.
25
- this.api.on("didFinishLaunching", () => {
26
- log.debug("Executed didFinishLaunching callback");
27
- // run the method to discover / register your devices as accessories
28
- this.discoverDevices();
29
- });
30
- }
31
- /**
32
- * This function is invoked when homebridge restores cached accessories from disk at startup.
33
- * It should be used to setup event handlers for characteristics and update respective values.
34
- */
35
- configureAccessory(accessory) {
36
- this.log.info("Loading accessory from cache:", accessory.displayName);
37
- // add the restored accessory to the accessories cache so we can track if it has already been registered
38
- this.accessories.push(accessory);
39
- }
40
- /**
41
- * This is an example method showing how to register discovered accessories.
42
- * Accessories must only be registered once, previously created accessories
43
- * must not be registered again to prevent "duplicate UUID" errors.
44
- */
45
- discoverDevices() {
46
- // EXAMPLE ONLY
47
- // A real plugin you would discover accessories from the local network, cloud services
48
- // or a user-defined array in the platform config.
49
- const exampleDevices = [
50
- {
51
- exampleUniqueId: "ABCD",
52
- exampleDisplayName: "Bedroom"
53
- },
54
- {
55
- exampleUniqueId: "EFGH",
56
- exampleDisplayName: "Kitchen"
57
- }
58
- ];
59
- // loop over the discovered devices and register each one if it has not already been registered
60
- for (const device of exampleDevices) {
61
- // generate a unique id for the accessory this should be generated from
62
- // something globally unique, but constant, for example, the device serial
63
- // number or MAC address
64
- const uuid = this.api.hap.uuid.generate(device.exampleUniqueId);
65
- // see if an accessory with the same uuid has already been registered and restored from
66
- // the cached devices we stored in the `configureAccessory` method above
67
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
68
- if (existingAccessory) {
69
- // the accessory already exists
70
- this.log.info("Restoring existing accessory from cache:", existingAccessory.displayName);
71
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
72
- // existingAccessory.context.device = device;
73
- // this.api.updatePlatformAccessories([existingAccessory]);
74
- // create the accessory handler for the restored accessory
75
- // this is imported from `platformAccessory.ts`
76
- new platformAccessory_1.ExamplePlatformAccessory(this, existingAccessory);
77
- }
78
- else {
79
- // the accessory does not yet exist, so we need to create it
80
- this.log.info("Adding new accessory:", device.exampleDisplayName);
81
- // create a new accessory
82
- const accessory = new this.api.platformAccessory(device.exampleDisplayName, uuid);
83
- // store a copy of the device object in the `accessory.context`
84
- // the `context` property can be used to store any data about the accessory you may need
85
- accessory.context.device = device;
86
- // create the accessory handler for the newly create accessory
87
- // this is imported from `platformAccessory.ts`
88
- new platformAccessory_1.ExamplePlatformAccessory(this, accessory);
89
- // link the accessory to your platform
90
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
91
- }
92
- // it is possible to remove platform accessories at any time using `api.unregisterPlatformAccessories`, eg.:
93
- // this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
94
- }
95
- }
96
- }
97
- exports.ExampleHomebridgePlatform = ExampleHomebridgePlatform;
98
- //# sourceMappingURL=platform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";;;AAEA,yCAAwD;AACxD,2DAA+D;AAE/D;;;;GAIG;AACH,MAAa,yBAAyB;IAOpC,YACkB,GAAW,EACX,MAAsB,EACtB,GAAQ;QAFR,QAAG,GAAH,GAAG,CAAQ;QACX,WAAM,GAAN,MAAM,CAAgB;QACtB,QAAG,GAAH,GAAG,CAAK;QATV,YAAO,GAAmB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC;QAC/C,mBAAc,GAA0B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC;QAEpF,oDAAoD;QACpC,gBAAW,GAAwB,EAAE,CAAC;QAOpD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEpE,8FAA8F;QAC9F,4FAA4F;QAC5F,2FAA2F;QAC3F,yCAAyC;QACzC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE;YACrC,GAAG,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAClD,oEAAoE;YACpE,IAAI,CAAC,eAAe,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,kBAAkB,CAAC,SAA4B;QAC7C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,+BAA+B,EAAE,SAA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IAAI,CAAC,CAAC;gBAElF,+DAA+D;gBAC/D,wFAAwF;gBACxF,SAAS,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;gBAElC,8DAA8D;gBAC9D,+CAA+C;gBAC/C,IAAI,4CAAwB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;gBAE9C,sCAAsC;gBACtC,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,sBAAW,EAAE,wBAAa,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;aAC/E;YAED,4GAA4G;YAC5G,mFAAmF;SACpF;IAEH,CAAC;CACF;AAzGD,8DAyGC"}
@@ -1,104 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExamplePlatformAccessory = void 0;
4
- /**
5
- * Platform Accessory
6
- * An instance of this class is created for each accessory your platform registers
7
- * Each accessory may expose multiple services of different service types.
8
- */
9
- class ExamplePlatformAccessory {
10
- constructor(platform, accessory) {
11
- this.platform = platform;
12
- this.accessory = accessory;
13
- /**
14
- * These are just used to create a working example
15
- * You should implement your own code to track the state of your accessory
16
- */
17
- this.exampleStates = {
18
- On: false,
19
- Brightness: 100
20
- };
21
- // set accessory information
22
- this.accessory.getService(this.platform.Service.AccessoryInformation)
23
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "Default-Manufacturer")
24
- .setCharacteristic(this.platform.Characteristic.Model, "Default-Model")
25
- .setCharacteristic(this.platform.Characteristic.SerialNumber, "Default-Serial");
26
- // get the LightBulb service if it exists, otherwise create a new LightBulb service
27
- // you can create multiple services for each accessory
28
- this.service = this.accessory.getService(this.platform.Service.Lightbulb) || this.accessory.addService(this.platform.Service.Lightbulb);
29
- // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
30
- // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
31
- // this.accessory.getService('NAME') ?? this.accessory.addService(this.platform.Service.Lightbulb, 'NAME', 'USER_DEFINED_SUBTYPE');
32
- // set the service name, this is what is displayed as the default name on the Home app
33
- // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
34
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.exampleDisplayName);
35
- // each service must implement at-minimum the "required characteristics" for the given service type
36
- // see https://developers.homebridge.io/#/service/Lightbulb
37
- // register handlers for the On/Off Characteristic
38
- this.service.getCharacteristic(this.platform.Characteristic.On)
39
- .on("set", this.setOn.bind(this)) // SET - bind to the `setOn` method below
40
- .on("get", this.getOn.bind(this)); // GET - bind to the `getOn` method below
41
- // register handlers for the Brightness Characteristic
42
- this.service.getCharacteristic(this.platform.Characteristic.Brightness)
43
- .on("set", this.setBrightness.bind(this)); // SET - bind to the 'setBrightness` method below
44
- // EXAMPLE ONLY
45
- // Example showing how to update the state of a Characteristic asynchronously instead
46
- // of using the `on('get')` handlers.
47
- //
48
- // Here we change update the brightness to a random value every 5 seconds using
49
- // the `updateCharacteristic` method.
50
- setInterval(() => {
51
- // assign the current brightness a random value between 0 and 100
52
- const currentBrightness = Math.floor(Math.random() * 100);
53
- // push the new value to HomeKit
54
- this.service.updateCharacteristic(this.platform.Characteristic.Brightness, currentBrightness);
55
- this.platform.log.debug("Pushed updated current Brightness state to HomeKit:", currentBrightness);
56
- }, 10000);
57
- }
58
- /**
59
- * Handle "SET" requests from HomeKit
60
- * These are sent when the user changes the state of an accessory, for example, turning on a Light bulb.
61
- */
62
- setOn(value, callback) {
63
- // implement your own code to turn your device on/off
64
- this.exampleStates.On = value;
65
- this.platform.log.debug("Set Characteristic On ->", value);
66
- // you must call the callback function
67
- callback(null);
68
- }
69
- /**
70
- * Handle the "GET" requests from HomeKit
71
- * These are sent when HomeKit wants to know the current state of the accessory, for example, checking if a Light bulb is on.
72
- *
73
- * GET requests should return as fast as possbile. A long delay here will result in
74
- * HomeKit being unresponsive and a bad user experience in general.
75
- *
76
- * If your device takes time to respond you should update the status of your device
77
- * asynchronously instead using the `updateCharacteristic` method instead.
78
-
79
- * @example
80
- * this.service.updateCharacteristic(this.platform.Characteristic.On, true)
81
- */
82
- getOn(callback) {
83
- // implement your own code to check if the device is on
84
- const isOn = this.exampleStates.On;
85
- this.platform.log.debug("Get Characteristic On ->", isOn);
86
- // you must call the callback function
87
- // the first argument should be null if there were no errors
88
- // the second argument should be the value to return
89
- callback(null, isOn);
90
- }
91
- /**
92
- * Handle "SET" requests from HomeKit
93
- * These are sent when the user changes the state of an accessory, for example, changing the Brightness
94
- */
95
- setBrightness(value, callback) {
96
- // implement your own code to set the brightness
97
- this.exampleStates.Brightness = value;
98
- this.platform.log.debug("Set Characteristic Brightness -> ", value);
99
- // you must call the callback function
100
- callback(null);
101
- }
102
- }
103
- exports.ExamplePlatformAccessory = ExamplePlatformAccessory;
104
- //# sourceMappingURL=platformAccessory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"platformAccessory.js","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":";;;AAIA;;;;GAIG;AACH,MAAa,wBAAwB;IAYnC,YACmB,QAAmC,EACnC,SAA4B;QAD5B,aAAQ,GAAR,QAAQ,CAA2B;QACnC,cAAS,GAAT,SAAS,CAAmB;QAX/C;;;WAGG;QACK,kBAAa,GAAG;YACtB,EAAE,EAAE,KAAK;YACT,UAAU,EAAE,GAAG;SAChB,CAAA;QAOC,4BAA4B;QAC5B,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAE;aACnE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,sBAAsB,CAAC;aACpF,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,EAAE,eAAe,CAAC;aACtE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;QAElF,mFAAmF;QACnF,sDAAsD;QACtD,IAAI,CAAC,OAA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ridgePlatform } from "./platform";
5
-
6
- /**
7
- * This method registers the platform with Homebridge
8
- */
9
- export = (api: API) => {
10
- api.registerPlatform(PLATFORM_NAME, ExampleHomebridgePlatform);
11
- }
package/src/platform.ts DELETED
@@ -1,116 +0,0 @@
1
- import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from "homebridge";
2
-
3
- import { PLATFORM_NAME, PLUGIN_NAME } from "./settings";
4
- import { ExamplePlatformAccessory } from "./platformAccessory";
5
-
6
- /**
7
- * HomebridgePlatform
8
- * This class is the main constructor for your plugin, this is where you should
9
- * parse the user config and discover/register accessories with Homebridge.
10
- */
11
- export class ExampleHomebridgePlatform implements DynamicPlatformPlugin {
12
- public readonly Service: typeof Service = this.api.hap.Service;
13
- public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic;
14
-
15
- // this is used to track restored cached accessories
16
- public readonly accessories: PlatformAccessory[] = [];
17
-
18
- constructor(
19
- public readonly log: Logger,
20
- public readonly config: PlatformConfig,
21
- public readonly api: API
22
- ) {
23
- this.log.debug("Finished initializing platform:", this.config.name);
24
-
25
- // When this event is fired it means Homebridge has restored all cached accessories from disk.
26
- // Dynamic Platform plugins should only register new accessories after this event was fired,
27
- // in order to ensure they weren't added to homebridge already. This event can also be used
28
- // to start discovery of new accessories.
29
- this.api.on("didFinishLaunching", () => {
30
- log.debug("Executed didFinishLaunching callback");
31
- // run the method to discover / register your devices as accessories
32
- this.discoverDevices();
33
- });
34
- }
35
-
36
- /**
37
- * This function is invoked when homebridge restores cached accessories from disk at startup.
38
- * It should be used to setup event handlers for characteristics and update respective values.
39
- */
40
- configureAccessory(accessory: PlatformAccessory) {
41
- this.log.info("Loading accessory from cache:", accessory.displayName);
42
-
43
- // add the restored accessory to the accessories cache so we can track if it has already been registered
44
- this.accessories.push(accessory);
45
- }
46
-
47
- /**
48
- * This is an example method showing how to register discovered accessories.
49
- * Accessories must only be registered once, previously created accessories
50
- * must not be registered again to prevent "duplicate UUID" errors.
51
- */
52
- discoverDevices() {
53
-
54
- // EXAMPLE ONLY
55
- // A real plugin you would discover accessories from the local network, cloud services
56
- // or a user-defined array in the platform config.
57
- const exampleDevices = [
58
- {
59
- exampleUniqueId: "ABCD",
60
- exampleDisplayName: "Bedroom"
61
- },
62
- {
63
- exampleUniqueId: "EFGH",
64
- exampleDisplayName: "Kitchen"
65
- }
66
- ];
67
-
68
- // loop over the discovered devices and register each one if it has not already been registered
69
- for (const device of exampleDevices) {
70
-
71
- // generate a unique id for the accessory this should be generated from
72
- // something globally unique, but constant, for example, the device serial
73
- // number or MAC address
74
- const uuid = this.api.hap.uuid.generate(device.exampleUniqueId);
75
-
76
- // see if an accessory with the same uuid has already been registered and restored from
77
- // the cached devices we stored in the `configureAccessory` method above
78
- const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
79
-
80
- if (existingAccessory) {
81
- // the accessory already exists
82
- this.log.info("Restoring existing accessory from cache:", existingAccessory.displayName);
83
-
84
- // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
85
- // existingAccessory.context.device = device;
86
- // this.api.updatePlatformAccessories([existingAccessory]);
87
-
88
- // create the accessory handler for the restored accessory
89
- // this is imported from `platformAccessory.ts`
90
- new ExamplePlatformAccessory(this, existingAccessory);
91
-
92
- } else {
93
- // the accessory does not yet exist, so we need to create it
94
- this.log.info("Adding new accessory:", device.exampleDisplayName);
95
-
96
- // create a new accessory
97
- const accessory = new this.api.platformAccessory(device.exampleDisplayName, uuid);
98
-
99
- // store a copy of the device object in the `accessory.context`
100
- // the `context` property can be used to store any data about the accessory you may need
101
- accessory.context.device = device;
102
-
103
- // create the accessory handler for the newly create accessory
104
- // this is imported from `platformAccessory.ts`
105
- new ExamplePlatformAccessory(this, accessory);
106
-
107
- // link the accessory to your platform
108
- this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
109
- }
110
-
111
- // it is possible to remove platform accessories at any time using `api.unregisterPlatformAccessories`, eg.:
112
- // this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
113
- }
114
-
115
- }
116
- }
@@ -1,130 +0,0 @@
1
- import { Service, PlatformAccessory, CharacteristicValue, CharacteristicSetCallback, CharacteristicGetCallback } from "homebridge";
2
-
3
- import { ExampleHomebridgePlatform } from "./platform";
4
-
5
- /**
6
- * Platform Accessory
7
- * An instance of this class is created for each accessory your platform registers
8
- * Each accessory may expose multiple services of different service types.
9
- */
10
- export class ExamplePlatformAccessory {
11
- private service: Service;
12
-
13
- /**
14
- * These are just used to create a working example
15
- * You should implement your own code to track the state of your accessory
16
- */
17
- private exampleStates = {
18
- On: false,
19
- Brightness: 100
20
- }
21
-
22
- constructor(
23
- private readonly platform: ExampleHomebridgePlatform,
24
- private readonly accessory: PlatformAccessory
25
- ) {
26
-
27
- // set accessory information
28
- this.accessory.getService(this.platform.Service.AccessoryInformation)!
29
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "Default-Manufacturer")
30
- .setCharacteristic(this.platform.Characteristic.Model, "Default-Model")
31
- .setCharacteristic(this.platform.Characteristic.SerialNumber, "Default-Serial");
32
-
33
- // get the LightBulb service if it exists, otherwise create a new LightBulb service
34
- // you can create multiple services for each accessory
35
- this.service = this.accessory.getService(this.platform.Service.Lightbulb) || this.accessory.addService(this.platform.Service.Lightbulb);
36
-
37
- // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
38
- // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
39
- // this.accessory.getService('NAME') ?? this.accessory.addService(this.platform.Service.Lightbulb, 'NAME', 'USER_DEFINED_SUBTYPE');
40
-
41
- // set the service name, this is what is displayed as the default name on the Home app
42
- // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
43
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.exampleDisplayName);
44
-
45
- // each service must implement at-minimum the "required characteristics" for the given service type
46
- // see https://developers.homebridge.io/#/service/Lightbulb
47
-
48
- // register handlers for the On/Off Characteristic
49
- this.service.getCharacteristic(this.platform.Characteristic.On)
50
- .on("set", this.setOn.bind(this)) // SET - bind to the `setOn` method below
51
- .on("get", this.getOn.bind(this)); // GET - bind to the `getOn` method below
52
-
53
- // register handlers for the Brightness Characteristic
54
- this.service.getCharacteristic(this.platform.Characteristic.Brightness)
55
- .on("set", this.setBrightness.bind(this)); // SET - bind to the 'setBrightness` method below
56
-
57
- // EXAMPLE ONLY
58
- // Example showing how to update the state of a Characteristic asynchronously instead
59
- // of using the `on('get')` handlers.
60
- //
61
- // Here we change update the brightness to a random value every 5 seconds using
62
- // the `updateCharacteristic` method.
63
- setInterval(() => {
64
- // assign the current brightness a random value between 0 and 100
65
- const currentBrightness = Math.floor(Math.random() * 100);
66
-
67
- // push the new value to HomeKit
68
- this.service.updateCharacteristic(this.platform.Characteristic.Brightness, currentBrightness);
69
-
70
- this.platform.log.debug("Pushed updated current Brightness state to HomeKit:", currentBrightness);
71
- }, 10000);
72
- }
73
-
74
- /**
75
- * Handle "SET" requests from HomeKit
76
- * These are sent when the user changes the state of an accessory, for example, turning on a Light bulb.
77
- */
78
- setOn(value: CharacteristicValue, callback: CharacteristicSetCallback) {
79
-
80
- // implement your own code to turn your device on/off
81
- this.exampleStates.On = value as boolean;
82
-
83
- this.platform.log.debug("Set Characteristic On ->", value);
84
-
85
- // you must call the callback function
86
- callback(null);
87
- }
88
-
89
- /**
90
- * Handle the "GET" requests from HomeKit
91
- * These are sent when HomeKit wants to know the current state of the accessory, for example, checking if a Light bulb is on.
92
- *
93
- * GET requests should return as fast as possbile. A long delay here will result in
94
- * HomeKit being unresponsive and a bad user experience in general.
95
- *
96
- * If your device takes time to respond you should update the status of your device
97
- * asynchronously instead using the `updateCharacteristic` method instead.
98
-
99
- * @example
100
- * this.service.updateCharacteristic(this.platform.Characteristic.On, true)
101
- */
102
- getOn(callback: CharacteristicGetCallback) {
103
-
104
- // implement your own code to check if the device is on
105
- const isOn = this.exampleStates.On;
106
-
107
- this.platform.log.debug("Get Characteristic On ->", isOn);
108
-
109
- // you must call the callback function
110
- // the first argument should be null if there were no errors
111
- // the second argument should be the value to return
112
- callback(null, isOn);
113
- }
114
-
115
- /**
116
- * Handle "SET" requests from HomeKit
117
- * These are sent when the user changes the state of an accessory, for example, changing the Brightness
118
- */
119
- setBrightness(value: CharacteristicValue, callback: CharacteristicSetCallback) {
120
-
121
- // implement your own code to set the brightness
122
- this.exampleStates.Brightness = value as number;
123
-
124
- this.platform.log.debug("Set Characteristic Brightness -> ", value);
125
-
126
- // you must call the callback function
127
- callback(null);
128
- }
129
-
130
- }
package/src/settings.ts DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * This is the name of the platform that users will use to register the plugin in the Homebridge config.json
3
- */
4
- export const PLATFORM_NAME = "ExampleHomebridgePlugin";
5
-
6
- /**
7
- * This must match the name of your plugin as defined the package.json
8
- */
9
- export const PLUGIN_NAME = "homebridge-plugin-name";
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2019",
4
- "module": "commonjs",
5
- "lib": [
6
- "ES2019",
7
- "dom"
8
- ],
9
- "sourceMap": true,
10
- "rootDir": "src",
11
- "outDir": "dist",
12
-
13
- "strict": true,
14
- "esModuleInterop": true,
15
- "forceConsistentCasingInFileNames": true
16
- },
17
- "include": [
18
- "src"
19
- ]
20
- }