matterbridge-eve-motion 1.0.2
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.
- package/README.md +22 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.d.ts +14 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +54 -0
- package/dist/platform.js.map +1 -0
- package/link-matterbridge-script.js +14 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# <img src="https://github.com/Luligu/matterbridge/blob/main/frontend/public/matterbridge%2064x64.png" alt="Matterbridge Logo" width="64px" height="64px"> Matterbridge eve motion with history
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/matterbridge-eve-motion)
|
|
4
|
+
[](https://www.npmjs.com/package/matterbridge-eve-motion)
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/matterbridge)
|
|
7
|
+
[](https://www.npmjs.com/package/matter-history)
|
|
8
|
+
[](https://www.npmjs.com/package/node-ansi-logger)
|
|
9
|
+
[](https://www.npmjs.com/package/node-persist-manager)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
This plugin shows how to use the Matter history and how to create passive device in matter.js.
|
|
14
|
+
|
|
15
|
+
It create a motion sensor with a light sensor device that continuously changes state.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
### Matterbridge
|
|
20
|
+
|
|
21
|
+
See the guidelines on [Matterbridge](https://github.com/Luligu/matterbridge/blob/main/README.md) for more information.
|
|
22
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Matterbridge, PlatformConfig } from 'matterbridge';
|
|
2
|
+
import { AnsiLogger } from 'node-ansi-logger';
|
|
3
|
+
import { EveMotionPlatform } from './platform.js';
|
|
4
|
+
/**
|
|
5
|
+
* This is the standard interface for MatterBridge plugins.
|
|
6
|
+
* Each plugin should export a default function that follows this signature.
|
|
7
|
+
*
|
|
8
|
+
* @param matterbridge - An instance of MatterBridge
|
|
9
|
+
*/
|
|
10
|
+
export default function initializePlugin(matterbridge: Matterbridge, log: AnsiLogger, config: PlatformConfig): EveMotionPlatform;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,YAAY,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,qBAE3G"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EveMotionPlatform } from './platform.js';
|
|
2
|
+
/**
|
|
3
|
+
* This is the standard interface for MatterBridge plugins.
|
|
4
|
+
* Each plugin should export a default function that follows this signature.
|
|
5
|
+
*
|
|
6
|
+
* @param matterbridge - An instance of MatterBridge
|
|
7
|
+
*/
|
|
8
|
+
export default function initializePlugin(matterbridge, log, config) {
|
|
9
|
+
return new EveMotionPlatform(matterbridge, log, config);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,YAA0B,EAAE,GAAe,EAAE,MAAsB;IAC1G,OAAO,IAAI,iBAAiB,CAAC,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { PlatformConfig } from 'matterbridge';
|
|
3
|
+
import { Matterbridge, MatterbridgeDevice, MatterbridgeAccessoryPlatform, MatterHistory } from 'matterbridge';
|
|
4
|
+
import { AnsiLogger } from 'node-ansi-logger';
|
|
5
|
+
export declare class EveMotionPlatform extends MatterbridgeAccessoryPlatform {
|
|
6
|
+
motion: MatterbridgeDevice | undefined;
|
|
7
|
+
history: MatterHistory | undefined;
|
|
8
|
+
interval: NodeJS.Timeout | undefined;
|
|
9
|
+
constructor(matterbridge: Matterbridge, log: AnsiLogger, config: PlatformConfig);
|
|
10
|
+
onStart(reason?: string): Promise<void>;
|
|
11
|
+
onConfigure(): Promise<void>;
|
|
12
|
+
onShutdown(reason?: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";AAAA,OAAO,EAAyD,cAAc,EAAE,MAAM,cAAc,CAAC;AAErG,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,qBAAa,iBAAkB,SAAQ,6BAA6B;IAClE,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACvC,OAAO,EAAE,aAAa,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;gBAEzB,YAAY,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc;IAIhE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM;IA4BvB,WAAW;IAqBX,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM;CAM1C"}
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DeviceTypes, IlluminanceMeasurement, OccupancySensing } from 'matterbridge';
|
|
2
|
+
import { MatterbridgeDevice, MatterbridgeAccessoryPlatform, MatterHistory } from 'matterbridge';
|
|
3
|
+
export class EveMotionPlatform extends MatterbridgeAccessoryPlatform {
|
|
4
|
+
motion;
|
|
5
|
+
history;
|
|
6
|
+
interval;
|
|
7
|
+
constructor(matterbridge, log, config) {
|
|
8
|
+
super(matterbridge, log, config);
|
|
9
|
+
}
|
|
10
|
+
async onStart(reason) {
|
|
11
|
+
this.log.info('onStart called with reason:', reason ?? 'none');
|
|
12
|
+
this.history = new MatterHistory(this.log, 'Eve motion', { filePath: this.matterbridge.matterbridgeDirectory });
|
|
13
|
+
this.motion = new MatterbridgeDevice(DeviceTypes.OCCUPANCY_SENSOR);
|
|
14
|
+
this.motion.createDefaultIdentifyClusterServer();
|
|
15
|
+
this.motion.createDefaultBasicInformationClusterServer('Eve motion', '0x85483499', 4874, 'Eve Systems', 89, 'Eve Motion 20EBY9901', 6650, '3.2.1');
|
|
16
|
+
this.motion.createDefaultOccupancySensingClusterServer();
|
|
17
|
+
this.motion.addDeviceType(DeviceTypes.LIGHT_SENSOR);
|
|
18
|
+
this.motion.createDefaultIlluminanceMeasurementClusterServer();
|
|
19
|
+
this.motion.createDefaultPowerSourceReplaceableBatteryClusterServer();
|
|
20
|
+
this.motion.createDefaultPowerSourceConfigurationClusterServer(1);
|
|
21
|
+
// Add the EveHistory cluster to the device as last cluster!
|
|
22
|
+
this.motion.createMotionEveHistoryClusterServer(this.history, this.log);
|
|
23
|
+
this.history.autoPilot(this.motion);
|
|
24
|
+
await this.registerDevice(this.motion);
|
|
25
|
+
this.motion.addCommandHandler('identify', async ({ request: { identifyTime } }) => {
|
|
26
|
+
this.log.warn(`Command identify called identifyTime:${identifyTime}`);
|
|
27
|
+
this.history?.logHistory(false);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async onConfigure() {
|
|
31
|
+
this.log.info('onConfigure called');
|
|
32
|
+
this.interval = setInterval(() => {
|
|
33
|
+
if (!this.motion || !this.history)
|
|
34
|
+
return;
|
|
35
|
+
const occupancy = this.motion.getClusterServerById(OccupancySensing.Cluster.id)?.getOccupancyAttribute();
|
|
36
|
+
if (!occupancy)
|
|
37
|
+
return;
|
|
38
|
+
occupancy.occupied = !occupancy.occupied;
|
|
39
|
+
const lux = this.history.getFakeLevel(0, 1000, 0);
|
|
40
|
+
this.motion.getClusterServerById(OccupancySensing.Cluster.id)?.setOccupancyAttribute(occupancy);
|
|
41
|
+
this.motion.getClusterServerById(IlluminanceMeasurement.Cluster.id)?.setMeasuredValueAttribute(Math.round(Math.max(Math.min(10000 * Math.log10(lux) + 1, 0xfffe), 0)));
|
|
42
|
+
this.history.setLastEvent();
|
|
43
|
+
this.history.addEntry({ time: this.history.now(), motion: occupancy.occupied === true ? 0 : 1, lux });
|
|
44
|
+
this.log.info(`Set motion to ${occupancy.occupied} and lux to ${lux}`);
|
|
45
|
+
}, 60 * 1000 + 200);
|
|
46
|
+
}
|
|
47
|
+
async onShutdown(reason) {
|
|
48
|
+
this.log.info('onShutdown called with reason:', reason ?? 'none');
|
|
49
|
+
await this.history?.close();
|
|
50
|
+
clearInterval(this.interval);
|
|
51
|
+
await this.unregisterAllDevices();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,gBAAgB,EAAkB,MAAM,cAAc,CAAC;AAErG,OAAO,EAAgB,kBAAkB,EAAE,6BAA6B,EAAE,aAAa,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,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAEvK,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;YAC5B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;YACtG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,SAAS,CAAC,QAAQ,eAAe,GAAG,EAAE,CAAC,CAAC;QACzE,CAAC,EACD,EAAE,GAAG,IAAI,GAAG,GAAG,CAChB,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,UAAU,CAAC,MAAe;QACvC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,gCAAgC,EAAE,MAAM,IAAI,MAAM,CAAC,CAAC;QAClE,MAAM,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QAC5B,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
|
|
3
|
+
const command = process.platform === 'win32' ? 'npm link matterbridge' : 'sudo npm link matterbridge';
|
|
4
|
+
|
|
5
|
+
exec(command, (error, stdout, stderr) => {
|
|
6
|
+
if (error) {
|
|
7
|
+
console.error(`exec error: ${error}`);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
console.log(`stdout: ${stdout}`);
|
|
11
|
+
if (stderr) {
|
|
12
|
+
console.error(`stderr: ${stderr}`);
|
|
13
|
+
}
|
|
14
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "matterbridge-eve-motion",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Matterbridge eve motion with history",
|
|
5
|
+
"author": "https://github.com/Luligu",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.js",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/Luligu/matterbridge-eve-motion"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Luligu/matterbridge-eve-motion/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"matterbridge",
|
|
19
|
+
"homebridge",
|
|
20
|
+
"matter",
|
|
21
|
+
"matter.js",
|
|
22
|
+
"plugin",
|
|
23
|
+
"eve",
|
|
24
|
+
"motion",
|
|
25
|
+
"history"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^18.19.0 || ^20.11.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"watch": "tsc --watch",
|
|
33
|
+
"start:bridge": "matterbridge -bridge",
|
|
34
|
+
"start:childbridge": "matterbridge -childbridge",
|
|
35
|
+
"test": "jest",
|
|
36
|
+
"test:verbose": "jest --verbose",
|
|
37
|
+
"test:watch": "jest --watch",
|
|
38
|
+
"lint": "eslint src/**.ts",
|
|
39
|
+
"lint:fix": "eslint src/**.ts --fix",
|
|
40
|
+
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,md}\"",
|
|
41
|
+
"format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx,json,css,md}\"",
|
|
42
|
+
"clean": "rimraf tsconfig.tsbuildinfo ./dist",
|
|
43
|
+
"cleanBuild": "npm run clean && tsc",
|
|
44
|
+
"deepClean": "rimraf tsconfig.tsbuildinfo package-lock.json ./dist ./node_modules",
|
|
45
|
+
"prepublishOnly": "npm run lint && npm run cleanBuild",
|
|
46
|
+
"checkDependencies": "npx npm-check-updates",
|
|
47
|
+
"updateDependencies": "npx npm-check-updates -u",
|
|
48
|
+
"matterbridge:add": "matterbridge -add .\\",
|
|
49
|
+
"matterbridge:remove": "matterbridge -remove .\\",
|
|
50
|
+
"matterbridge:enable": "matterbridge -enable .\\",
|
|
51
|
+
"matterbridge:disable": "matterbridge -disable .\\",
|
|
52
|
+
"matterbridge:list": "matterbridge -list",
|
|
53
|
+
"dev:link": "npm link --save-dev matterbridge",
|
|
54
|
+
"dev:install": "npm install --save-dev matterbridge",
|
|
55
|
+
"dev:uninstall": "npm uninstall matterbridge && npm unlink matterbridge",
|
|
56
|
+
"install": "node link-matterbridge-script.js"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@stylistic/eslint-plugin": "^1.7.0",
|
|
60
|
+
"@tsconfig/node-lts": "^20.1.2",
|
|
61
|
+
"@types/node": "^20.11.30",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
63
|
+
"@typescript-eslint/parser": "^7.3.1",
|
|
64
|
+
"eslint-config-prettier": "^9.1.0",
|
|
65
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
66
|
+
"prettier": "^3.2.5",
|
|
67
|
+
"typescript": "^5.4.3"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"node-ansi-logger": "^1.9.2"
|
|
71
|
+
}
|
|
72
|
+
}
|