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

View file

@ -145,7 +145,7 @@ class Alex2MQTT extends EventEmitter {
this.rootTopic,
name,
endpointId,
normalizedCategory
normalizedCategory|| [DisplayCategory.LIGHT]
);
this.devices.push(device);
return device;

View file

@ -81,6 +81,7 @@ interface FriendlyName {
export class AlexaInterface {
private friendlyNames: FriendlyName[] = [];
private actionMappings: ActionMapping[] = [];
private supportedModes: string[] = [];
constructor(
public type: AlexaInterfaceType,
@ -96,7 +97,9 @@ export class AlexaInterface {
addFriendlyName(name: string, locale: string): void {
this.friendlyNames.push({ text: name, locale });
}
addSupportedModes(modes: string[]): void {
this.supportedModes = modes;
}
setInstance(name: string): void {
this.instance = name;
}
@ -209,6 +212,8 @@ export 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:
@ -241,7 +246,6 @@ export 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:
@ -291,6 +295,11 @@ export class AlexaInterface {
"supportedModes": ["HEAT", "COOL", "AUTO", "OFF"],
"supportsScheduling": false
}
}else if (this.supportedModes.length > 0) {
doc["configuration"] = {
ordered:true,
supportedModes: this.supportedModes,
};
}
if (this.instance) {
doc.instance = this.instance;
@ -306,6 +315,7 @@ export class AlexaInterface {
};
friendlyNamesArray.push(friendlyNameObj);
});
capabilityResources.friendlyNames=friendlyNamesArray
doc["capabilityResources"] = capabilityResources;
}
if (this.actionMappings.length > 0) {

View file

@ -115,6 +115,15 @@ export class AlexaStatusMessage {
this.context.properties.push(prop);
return this;
}
public addModeControllerProp(instance: string, value: string, uncertaintyInMs = 0): this {
return this.addProperty(
AlexaInterfaceType.MODE_CONTROLLER,
"mode",
value,
uncertaintyInMs,
instance
);
}
public addThermostatModeProp(mode: string, uncertaintyInMs = 0): this {
return this.addProperty(
AlexaInterfaceType.THERMOSTAT_CONTROLLER,