node-red-contrib-voice-assistant
Version:
一个小度-小爱-猫精音箱控制NODE-RED自定义设备的节点
75 lines (73 loc) • 2.07 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class BaseModel {
constructor(name, domain) {
this.name = name;
this.domain = domain;
this.state = 'off';
this.attributes = {};
this.enable = true;
this.id = '';
}
}
class ClimateModel extends BaseModel {
constructor(name) {
super(name, 'climate');
this.attributes.current_temperature = 25;
this.attributes.temperature = 23;
this.attributes.fan_mode = 'low';
this.attributes.hvac_modes = ['auto', 'off', 'cool', 'heat', 'dry', 'fan_only'];
this.attributes.fan_modes = ['auto', 'low', 'medium', 'high'];
this.state = 'auto';
}
}
class CoverModel extends BaseModel {
constructor(name) {
super(name, 'cover');
this.attributes.current_position = 0;
this.attributes.set_position = 0;
this.state = 'open';
}
}
class SwitchModel extends BaseModel {
constructor(name) {
super(name, 'switch');
}
}
class LightModel extends BaseModel {
constructor(name) {
super(name, 'light');
this.attributes.brightness = 30;
this.attributes.rgb_color = [255, 255, 255];
}
}
class FanModel extends BaseModel {
constructor(name) {
super(name, 'fan');
this.attributes.percentage = 0;
this.attributes.oscillating = false;
this.attributes.preset_mode = [];
}
}
/* const model = new FanModel('123', 'switch');
console.log(model); */
class Model {
static getModel(name, domain) {
switch (domain) {
case 'switch':
return new SwitchModel(name);
case 'light':
return new LightModel(name);
case 'climate':
return new ClimateModel(name);
case 'fan':
return new FanModel(name);
case 'cover':
return new CoverModel(name);
default:
return;
break;
}
}
}
exports.default = Model;