From ba64d050446c5bacb3384ff08e7ba745eeeba966 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 24 Oct 2022 19:56:31 -0700 Subject: [PATCH] mqtt: add motion sensor example --- plugins/mqtt/fs/examples/motion-sensor.ts | 13 +++++++++++++ plugins/mqtt/package-lock.json | 4 ++-- plugins/mqtt/package.json | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 plugins/mqtt/fs/examples/motion-sensor.ts diff --git a/plugins/mqtt/fs/examples/motion-sensor.ts b/plugins/mqtt/fs/examples/motion-sensor.ts new file mode 100644 index 000000000..d26b990af --- /dev/null +++ b/plugins/mqtt/fs/examples/motion-sensor.ts @@ -0,0 +1,13 @@ +import { ScriptDevice } from "@scrypted/common/src/eval/monaco/script-device"; // SCRYPTED_FILTER_EXAMPLE_LINE +import { ScryptedDeviceBase, ScryptedInterface } from "@scrypted/sdk"; // SCRYPTED_FILTER_EXAMPLE_LINE +import { MqttClient } from "../../src/api/mqtt-client"; // SCRYPTED_FILTER_EXAMPLE_LINE +declare const device: ScriptDevice & ScryptedDeviceBase; // SCRYPTED_FILTER_EXAMPLE_LINE +declare const mqtt: MqttClient; // SCRYPTED_FILTER_EXAMPLE_LINE + +mqtt.subscribe({ + // this example expects the device to publish either ON or OFF text values + // to the mqtt endpoint. + '/': value => device.motionDetected = value.text === 'ON', +}); + +mqtt.handleTypes(ScryptedInterface.MotionSensor); diff --git a/plugins/mqtt/package-lock.json b/plugins/mqtt/package-lock.json index 58d2be4e0..e288d8f16 100644 --- a/plugins/mqtt/package-lock.json +++ b/plugins/mqtt/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/mqtt", - "version": "0.0.56", + "version": "0.0.57", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/mqtt", - "version": "0.0.56", + "version": "0.0.57", "dependencies": { "@types/node": "^16.6.1", "aedes": "^0.46.1", diff --git a/plugins/mqtt/package.json b/plugins/mqtt/package.json index 7911b33f3..689220515 100644 --- a/plugins/mqtt/package.json +++ b/plugins/mqtt/package.json @@ -41,5 +41,5 @@ "@scrypted/common": "file:../../common", "@types/nunjucks": "^3.2.0" }, - "version": "0.0.56" + "version": "0.0.57" }