-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
371 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
<script type="text/javascript"> | ||
RED.nodes.registerType('matterevent',{ | ||
category: 'Matter', | ||
color: '#95cc95', | ||
icon: "font-awesome/fa-bell", | ||
inputs:0, | ||
outputs:1, | ||
defaults: { | ||
name: {value:""}, | ||
controller: { value: "", type: "mattercontroller", required: true }, | ||
device: {value:""}, | ||
deviceName: {value:""}, | ||
endpoint: {value:""}, | ||
cluster: {value:""}, | ||
event: {value:""}, | ||
topic: {value:""} | ||
}, | ||
paletteLabel: "Event", | ||
label: function() { | ||
let defaultName = `${this.deviceName} | ${this.event}` | ||
return this.name || defaultName || "Event"; | ||
}, | ||
oneditprepare: function() { | ||
if (this.device.length != 0){ | ||
setDevice(this.controller, this.device) | ||
} | ||
if (this.cluster.length != 0){ | ||
setCluster(this.controller, this.device, this.cluster) | ||
} | ||
if (this.event.length != 0){ | ||
setEvent(this.controller, this.device, this.cluster, this.event); | ||
} | ||
$('#refresh-devices').on("click", getDevices); | ||
$('#refresh-clusters').on("click", getClusters); | ||
$('#refresh-event').on("click", getEvents); | ||
|
||
}, | ||
oneditsave: function() { | ||
let el = document.getElementById('node-input-device'); | ||
this.deviceName = el.options[el.selectedIndex].innerHTML; | ||
} | ||
}); | ||
</script> | ||
|
||
<script type="text/x-red" data-template-name="matterevent"> | ||
<div class="form-row"> | ||
<label for="node-input-name"><i class="icon-tag"></i> Name</label> | ||
<input type="text" id="node-input-name" placeholder="Name"> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-controller">Controller</label> | ||
<input type="text" id="node-input-controller" style="width:70%;"> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-simpleMode">Simple Mode</label> | ||
<input type="checkbox" id="node-input-simpleMode" value="true" > | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-device">Device</label> | ||
<select type="text" id="node-input-device" style="width:50%;" > | ||
</select> | ||
<a id="refresh-devices" class="btn"><i class="fa fa-refresh"></i></a> | ||
</div> | ||
<!-- | ||
<div class="form-row"> | ||
<label for="node-input-endpoint">Endpoint</label> | ||
<select type="text" id="node-input-endpoint" style="width:50%;" > | ||
</select> | ||
</div> | ||
--> | ||
<div class="form-row"> | ||
<label for="node-input-cluster">Cluster</label> | ||
<select type="text" id="node-input-cluster" style="width:50%;" > | ||
</select> | ||
<a id="refresh-clusters" class="btn"><i class="fa fa-refresh"></i></a> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-event">Event</label> | ||
<select type="text" id="node-input-event" style="width:50%;" > | ||
</select> | ||
<a id="refresh-event" class="btn"><i class="fa fa-refresh"></i></a> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-topic">Topic</label> | ||
<input type="text" id="node-input-topic"> | ||
</div> | ||
</script> | ||
|
||
<script type="text/x-red" data-help-name="matterevent"> | ||
<p>Receive Events from a Device</p> | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const {cap} = require('./utils') | ||
|
||
|
||
|
||
module.exports = function(RED) { | ||
function MatterEvent(config) { | ||
RED.nodes.createNode(this, config); | ||
var node = this; | ||
node.controller = RED.nodes.getNode(config.controller); | ||
node.device = BigInt(config.device) | ||
node.endpoint = config.endpoint || 0 | ||
node.cluster = Number(config.cluster) | ||
node.event = cap(config.event) | ||
node.topic = config.topic | ||
|
||
function subscribe(node){ | ||
node.controller.commissioningController.connectNode(node.device) | ||
.then((device) => { | ||
const ep = device.getDevices() | ||
const clc = ep[Number(node.endpoint)].getClusterClientById(Number(node.cluster)) | ||
let command = eval(`clc.add${node.event}EventListener`) | ||
command(value => { | ||
msg = {topic: node.topic} | ||
msg.payload = value | ||
node.send(msg) | ||
}) | ||
}) | ||
} | ||
|
||
function waitforserver(node) { | ||
if (!node.controller.started) { | ||
setTimeout(waitforserver, 100, node) | ||
} else { | ||
node.log('Setting Event...') | ||
subscribe(node) | ||
} | ||
} | ||
|
||
waitforserver(node) | ||
} | ||
RED.nodes.registerType("matterevent",MatterEvent); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.