Skip to content

Commit

Permalink
Add name field functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
bewee committed Mar 23, 2020
1 parent cd5af11 commit 3fc06f6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
10 changes: 5 additions & 5 deletions lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions lib/devices/colourlamp-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions lib/devices/generic-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions lib/devices/lamp-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions lib/devices/plug-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
7 changes: 5 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"manifest_version": 1,
"name": "Tuya Smart Life",
"short_name": "Tuya",
"version": "0.1.2",
"version": "0.1.3",

"options": {
"default": {
Expand All @@ -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"
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 3fc06f6

Please sign in to comment.