Add full support for mode controller

This commit is contained in:
David 2025-05-12 18:23:58 +00:00
parent e7a2079ff7
commit 3bcd767127
8 changed files with 198 additions and 6 deletions

3
dist/Alex2Node.js vendored
View file

@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const mqtt_1 = __importDefault(require("mqtt"));
const Device_1 = __importDefault(require("./Device"));
const events_1 = require("events");
const DisplayCategory_1 = require("./DisplayCategory");
class Alex2MQTT extends events_1.EventEmitter {
constructor(username, password, rootTopic, debugLogging) {
super(); // Initialize EventEmitter
@ -114,7 +115,7 @@ class Alex2MQTT extends events_1.EventEmitter {
: Array.isArray(displayCategory)
? displayCategory
: [displayCategory];
const device = new Device_1.default(this.client, this.rootTopic, name, endpointId, normalizedCategory);
const device = new Device_1.default(this.client, this.rootTopic, name, endpointId, normalizedCategory || [DisplayCategory_1.DisplayCategory.LIGHT]);
this.devices.push(device);
return device;
}

View file

@ -82,6 +82,7 @@ class AlexaInterface {
this.instance = instance;
this.friendlyNames = [];
this.actionMappings = [];
this.supportedModes = [];
}
addActionMapping(mapping) {
this.actionMappings.push(mapping);
@ -89,6 +90,9 @@ class AlexaInterface {
addFriendlyName(name, locale) {
this.friendlyNames.push({ text: name, locale });
}
addSupportedModes(modes) {
this.supportedModes = modes;
}
setInstance(name) {
this.instance = name;
}
@ -196,6 +200,8 @@ class AlexaInterface {
return ["connectivity"];
case AlexaInterfaceType.TOGGLE_CONTROLLER:
return ["toggleState"];
case AlexaInterfaceType.MODE_CONTROLLER:
return ["mode"];
case AlexaInterfaceType.TEMPERATURE_SENSOR:
return ["temperature"];
case AlexaInterfaceType.THERMOSTAT_CONTROLLER:
@ -228,7 +234,6 @@ class AlexaInterface {
case AlexaInterfaceType.LOCK_CONTROLLER:
case AlexaInterfaceType.MEDIA_PLAYBACK:
case AlexaInterfaceType.MEDIA_SEARCH:
case AlexaInterfaceType.MODE_CONTROLLER:
case AlexaInterfaceType.MOTION_SENSOR:
case AlexaInterfaceType.PERCENTAGE_CONTROLLER:
case AlexaInterfaceType.PLAYBACK_CONTROLLER:
@ -277,6 +282,12 @@ class AlexaInterface {
"supportsScheduling": false
};
}
else if (this.supportedModes.length > 0) {
doc["configuration"] = {
ordered: true,
supportedModes: this.supportedModes,
};
}
if (this.instance) {
doc.instance = this.instance;
}
@ -291,6 +302,7 @@ class AlexaInterface {
};
friendlyNamesArray.push(friendlyNameObj);
});
capabilityResources.friendlyNames = friendlyNamesArray;
doc["capabilityResources"] = capabilityResources;
}
if (this.actionMappings.length > 0) {

View file

@ -71,6 +71,9 @@ class AlexaStatusMessage {
this.context.properties.push(prop);
return this;
}
addModeControllerProp(instance, value, uncertaintyInMs = 0) {
return this.addProperty(AlexaInterface_1.AlexaInterfaceType.MODE_CONTROLLER, "mode", value, uncertaintyInMs, instance);
}
addThermostatModeProp(mode, uncertaintyInMs = 0) {
return this.addProperty(AlexaInterface_1.AlexaInterfaceType.THERMOSTAT_CONTROLLER, "thermostatMode", mode, uncertaintyInMs);
}