device.ts
import { Device } from 'homey';
class MyDevice extends Device {
/**
* onInit is called when the device is initialized.
*/
async onInit() {
this.log('AE - Auto Encoder has been initialized');
this.registerCapabilityListener('onoff', async (value) => {
this.log('AE - Auto Encoder has changed:', value);
});
this.registerCapabilityListener('my_enum_capability', async (value) => {
this.log('Changes to :', value);
});
}
/**
* onAdded is called when the user adds the device, called just after pairing.
*/
async onAdded() {
this.log('AE - Auto Encoder has been added');
}
/**
* onSettings is called when the user updates the device's settings.
* @param {object} event the onSettings event data
* @param {object} event.oldSettings The old settings object
* @param {object} event.newSettings The new settings object
* @param {string[]} event.changedKeys An array of keys changed since the previous version
* @returns {Promise<string|void>} return a custom message that will be displayed
*/
async onSettings({ oldSettings: {}, newSettings: {}, changedKeys: {} }): Promise<string|void> {
this.log('AE - Auto Encoder settings where changed');
}
/**
* onRenamed is called when the user updates the device's name.
* This method can be used this to synchronise the name to the device.
* @param {string} name The new name
*/
async onRenamed(name: string) {
this.log('AE - Auto Encoder was renamed');
}
/**
* onDeleted is called when the user deleted the device.
*/
async onDeleted() {
this.log('AE - Auto Encoder has been deleted');
}
}
module.exports = MyDevice;
Driver.compose.json
{
"name": {
"en": "AE - Auto Encoder",
"nl": "AE - Auto Encoder"
},
"class": "other",
"capabilities": [],
"images": {
"small": "/drivers/p-perceptron/assets/images/small.png",
"large": "/drivers/p-perceptron/assets/images/large.png",
"xlarge": "/drivers/p-perceptron/assets/images/xlarge.png"
},
"pair": [
{
"id": "list_devices",
"template": "list_devices",
"navigation": {
"next": "add_devices"
},
"options": {
"singular": false
}
},
{
"id": "add_devices",
"template": "add_devices"
}
]
}
driver.ts
import { Driver } from 'homey';
class MyDriver extends Driver {
/**
* onInit is called when the driver is initialized.
*/
async onInit() {
this.log('AE - Auto Encoder has been initialized');
}
/**
* onPairListDevic∑es is called when a user is adding a device and the 'list_devices' view is called.
* This should return an array with the data of devices that are available for pairing.
*/
async onPairListDevices() {
return [
// Example device data, note that `store` is optional
// {
// name: 'My Device',
// data: {
// id: 'my-device',
// },
// store: {
// address: '127.0.0.1',
// },
// },
{
name: 'I1 (AE)',
data: {
id: 'AE_I1',
},
capabilities: [
"onoff"
],
energy: {
approximation: {
usageConstant: 0, // in Watt
},
},
},
{
name: 'I2 (AE)',
data: {
id: 'AE_I2',
},
capabilities: [
"onoff"
],
energy: {
approximation: {
usageConstant: 0, // in Watt
},
},
},
{
name: 'I3 (AE)',
data: {
id: 'AE_I3',
},
capabilities: [
"onoff"
],
energy: {
approximation: {
usageConstant: 0, // in Watt
},
},
},
{
name: 'I4 (AE)',
data: {
id: 'AE_I4',
},
capabilities: [
"onoff"
],
energy: {
approximation: {
usageConstant: 0, // in Watt
},
},
},
{
name: 'M1 (AE)',
data: {
id: 'AE_M1',
},
},
{
name: 'M2 (AE)',
data: {
id: 'AE_M2',
},
},
{
name: 'Q1 (AE)',
data: {
id: 'AE_Q1',
},
capabilities: [
"my-enum_no_on_off_capability"
],
energy: {
approximation: {
usageConstant: 0, // in Watt
},
},
},
{
name: 'Q2 (AE)',
data: {
id: 'AE_Q2',
},
capabilities: [
"my-enum_no_on_off_capability"
],
energy: {
approximation: {
usageConstant: 0, // in Watt
},
},
},
{
name: 'Q3 (AE)',
data: {
id: 'AE_Q3',
},
capabilities: [
"my-enum_no_on_off_capability"
],
energy: {
approximation: {
usageConstant: 0, // in Watt
},
},
},
{
name: 'Q4 (AE)',
data: {
id: 'AE_Q4',
},
capabilities: [
"my-enum_no_on_off_capability"
],
energy: {
approximation: {
usageConstant: 0, // in Watt
},
},
},
];
}
}
module.exports = MyDriver;
my_enum_no_on_off_capability.json
{
"type": "boolean",
"uiComponent": null,
"uiQuickAction": true,
"getable": true,
"setable": false,
"insights": false,
"title": {
"en": "ON / OFF",
"nl": "ON / OFF",
"de": "ON / OFF",
"fr": "ON / OFF",
"it": "ON / OFF",
"sv": "ON / OFF",
"no": "ON / OFF",
"es": "ON / OFF",
"da": "ON / OFF"
}
}
App.ts
import sourceMapSupport from 'source-map-support';
sourceMapSupport.install();
import Homey from 'homey';
import { copyFileSync } from 'fs';
class MyApp extends Homey.App {
/**
* onInit is called when the app is initialized.
*/
async onInit(): Promise<void> {
this.log('App has been initialized');
/**
* It is called when homey reboot.
*/
}
}
module.exports = MyApp;