diff --git a/lib/adapter.js b/lib/adapter.js index e8419bc..ea32e82 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -25,16 +25,16 @@ class TuyaAdapter extends Adapter { let d; switch (conf.type) { case 'Plug': - d = new PlugDevice(this, conf.id, conf.key); + d = new PlugDevice(this, conf.id, conf.key, conf.name&&conf.name!='' ? conf.name : null); break; case 'Lamp': - d = new LampDevice(this, conf.id, conf.key); + d = new LampDevice(this, conf.id, conf.key, conf.name&&conf.name!='' ? conf.name : null); break; case 'Colour Lamp': - d = new ColourLampDevice(this, conf.id, conf.key); + d = new ColourLampDevice(this, conf.id, conf.key, conf.name&&conf.name!='' ? conf.name : null); break; default: - d = new GenericDevice(this, conf.id, conf.key); + d = new GenericDevice(this, conf.id, conf.key, conf.name&&conf.name!='' ? conf.name : null); break; } this.handleDeviceAdded(d); @@ -86,7 +86,7 @@ class TuyaAdapter extends Adapter { removeThing(device) { console.log('removeThing(', device.id, ')'); - const newdevice = new device.__proto__.constructor(this, device.tid, device.key); + const newdevice = new device.__proto__.constructor(this, device.tid, device.key, device.name); this.handleDeviceRemoved(device); if (this.savedDevices.includes(device.id)) diff --git a/lib/devices/colourlamp-device.js b/lib/devices/colourlamp-device.js index 99434b4..a403b92 100644 --- a/lib/devices/colourlamp-device.js +++ b/lib/devices/colourlamp-device.js @@ -12,13 +12,13 @@ const SaturationProperty = require('../properties/colourlamp/saturation-property const LightnessProperty = require('../properties/colourlamp/lightness-property'); class ColourLampDevice extends Device { - constructor(adapter, tid, key) { + constructor(adapter, tid, key, name) { super(adapter, `tuya-${tid}`); this.tid = tid; this.key = key; - this.name = 'Lamp'; + this.name = name ? name : 'Lamp'; this['@type'] = ['Light', 'OnOffSwitch']; this.description = 'tuya colour lamp'; diff --git a/lib/devices/generic-device.js b/lib/devices/generic-device.js index e41c717..5681f7d 100644 --- a/lib/devices/generic-device.js +++ b/lib/devices/generic-device.js @@ -7,13 +7,13 @@ const NumberProperty = require('../properties/number-property'); const BooleanProperty = require('../properties/boolean-property'); class GenericDevice extends Device { - constructor(adapter, tid, key) { + constructor(adapter, tid, key, name) { super(adapter, `tuya-${tid}`); this.tid = tid; this.key = key; - this.name = 'Device'; + this.name = name ? name : 'Device'; this['@type'] = []; this.description = 'tuya generic device'; diff --git a/lib/devices/lamp-device.js b/lib/devices/lamp-device.js index 050cc1d..1a5e97d 100644 --- a/lib/devices/lamp-device.js +++ b/lib/devices/lamp-device.js @@ -7,13 +7,13 @@ const BrightnessProperty = require('../properties/brightness-property'); const LighttemperatureProperty = require('../properties/lighttemperature-property'); class LampDevice extends Device { - constructor(adapter, tid, key) { + constructor(adapter, tid, key, name) { super(adapter, `tuya-${tid}`); this.tid = tid; this.key = key; - this.name = 'Lamp'; + this.name = name ? name : 'Lamp'; this['@type'] = ['Light', 'OnOffSwitch']; this.description = 'tuya lamp'; diff --git a/lib/devices/plug-device.js b/lib/devices/plug-device.js index 40df32b..7bb0a8e 100644 --- a/lib/devices/plug-device.js +++ b/lib/devices/plug-device.js @@ -5,13 +5,13 @@ const TuyAPI = require('tuyapi'); const PowerProperty = require('../properties/power-property'); class PlugDevice extends Device { - constructor(adapter, tid, key) { + constructor(adapter, tid, key, name) { super(adapter, `tuya-${tid}`); this.tid = tid; this.key = key; - this.name = 'Plug'; + this.name = name ? name : 'Plug'; this['@type'] = ['SmartPlug', 'OnOffSwitch']; this.description = 'tuya plug'; diff --git a/manifest.json b/manifest.json index f117a83..e26afc1 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "manifest_version": 1, "name": "Tuya Smart Life", "short_name": "Tuya", - "version": "0.1.2", + "version": "0.1.3", "options": { "default": { @@ -40,17 +40,20 @@ "type": "object", "properties": { "id": { + "title": "id", "type": "string" }, "key": { + "title": "key (aka localKey)", "type": "string" }, "type": { + "title": "Type", "type": "string", "enum": ["Plug", "Lamp", "Colour Lamp"] }, "name": { - "readOnly": true, + "title": "Name", "type": "string" } } diff --git a/package.json b/package.json index 5924907..a3c23c0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tuya-adapter", "display_name": "Tuya Smart Life", - "version": "0.1.2", + "version": "0.1.3", "description": "Tuya Smart Life IoT devices support", "author": "Galveston01", "main": "index.js",