discovery: generate capability JSON from the registry
A capability is a descriptor plus what the endpoint declares (device/Capability.ts), and its discovery object is
generated from the two. The new API is bridge.addDevice({ endpointId, name, categories, ... }) and
device.add(PowerController, options): both throw a DeclarationError that names the endpoint, the interface and
the instance (device/validate.ts), and leave the bridge and the device as they were. AlexaInterface is the same
Capability with the 1.x methods on it; it, ActionMapping and the enums moved to src/compat/, Device to src/device/.
What a 1.x caller can observe:
- every endpoint ends with { type: "AlexaInterface", interface: "Alexa", version: "3" } (alexa-interface.html);
new Alex2MQTT(..., { alexaInterface: false }) leaves it out
- the fields of a capability object come in the order of Amazon's examples; their content is unchanged
- addCapability() with a name that is not an interface throws (1.5.2 announced it with the version "UNKNOWN")
- ActionMapping takes the payload as an object; a JSON string is parsed (1.5.2 sent the string), any other throws
- what Alexa would reject in a 1.x declaration is not refused: device.check() lists it and the bridge logs each
line once, as "warning: ..." through the log hook, when it answers a discovery
- a device whose JSON cannot be built is left out of the answer and reported as an error event
- PowerController and EndpointHealth are the descriptors and keep ON/OFF and OK/UNREACHABLE; PowerState is new
Tests: six zoo devices declared the 1.x way give the JSON that Alexa accepted from 1.5.2 on 2026-09-28, plus the
Alexa capability. npm test: 85 pass (was 57) in 10-12 s, also on Node 18.20.8 and 20.20.2.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
aa0ffd64ea
commit
c492ef74d1
90 changed files with 5539 additions and 1760 deletions
20
dist/types/ActionMapping.d.ts
vendored
20
dist/types/ActionMapping.d.ts
vendored
|
|
@ -1,20 +0,0 @@
|
|||
export declare enum AlexaActions {
|
||||
Open = "Alexa.Actions.Open",
|
||||
Close = "Alexa.Actions.Close",
|
||||
Raise = "Alexa.Actions.Raise",
|
||||
Lower = "Alexa.Actions.Lower",
|
||||
SetEcoOn = "Alexa.Actions.SetEcoOn",
|
||||
SetEcoOff = "Alexa.Actions.SetEcoOff"
|
||||
}
|
||||
interface Directive {
|
||||
name: string;
|
||||
payload?: string;
|
||||
}
|
||||
export declare class ActionMapping {
|
||||
type: string;
|
||||
actions: AlexaActions[];
|
||||
directive: Directive;
|
||||
constructor(actions: AlexaActions[], directiveName: string, directivePayload?: string);
|
||||
toJSON(): object;
|
||||
}
|
||||
export {};
|
||||
26
dist/types/Alex2Node.d.ts
vendored
26
dist/types/Alex2Node.d.ts
vendored
|
|
@ -1,7 +1,8 @@
|
|||
import type { IClientOptions } from "mqtt";
|
||||
import Device from "./Device.js";
|
||||
import Device from "./device/Device.js";
|
||||
import type { EndpointDefinition } from "./device/Device.js";
|
||||
import { EventEmitter } from "events";
|
||||
import { DisplayCategory } from "./DisplayCategory.js";
|
||||
import { DisplayCategory } from "./compat/enums.js";
|
||||
/** Optional settings for the bridge (1.5.1). Everything has the 1.4.0 behaviour as its default. */
|
||||
export interface Alex2MQTTOptions {
|
||||
/** The broker URL. Default: the public Alex2MQTT broker, mqtt://Alex2MQTT.stormysdream.club:1883. */
|
||||
|
|
@ -10,6 +11,11 @@ export interface Alex2MQTTOptions {
|
|||
mqtt?: IClientOptions;
|
||||
/** Where log lines go. Default: console (only when debugLogging is on). */
|
||||
log?: (message: string, detail?: unknown) => void;
|
||||
/**
|
||||
* false: discovery does not list the Alexa interface on the endpoints. Default: every endpoint ends with
|
||||
* { type: "AlexaInterface", interface: "Alexa", version: "3" }, which Amazon requires and 1.x left out.
|
||||
*/
|
||||
alexaInterface?: boolean;
|
||||
}
|
||||
export declare const DEFAULT_HOST = "mqtt://Alex2MQTT.stormysdream.club:1883";
|
||||
/**
|
||||
|
|
@ -35,6 +41,7 @@ declare class Alex2MQTT extends EventEmitter {
|
|||
private devices;
|
||||
private MqttHost;
|
||||
private options;
|
||||
private logged;
|
||||
/** true while the broker connection is up. */
|
||||
connected: boolean;
|
||||
/** ISO time of the last discovery request answered, null before the first. */
|
||||
|
|
@ -44,9 +51,22 @@ declare class Alex2MQTT extends EventEmitter {
|
|||
/** Emit "error" only when somebody listens: an unhandled "error" event would crash the host process. */
|
||||
private fail;
|
||||
connect(): void;
|
||||
private describeDevices;
|
||||
/** Close the broker connection (resolves once closed). The devices stay registered; connect() again reuses them. */
|
||||
disconnect(): Promise<void>;
|
||||
registerDevice(name: string, endpointId: string, displayCategory: DisplayCategory | DisplayCategory[] | null): Device;
|
||||
/**
|
||||
* Declare a device:
|
||||
*
|
||||
* const blinds = bridge.addDevice({ endpointId: "bedroom-blinds", name: "Bedroom Blinds",
|
||||
* categories: ["INTERIOR_BLIND"], manufacturerName: "Acme", description: "Roller blind by Acme" });
|
||||
*
|
||||
* Throws a DeclarationError when Alexa would reject the endpoint (an endpointId with a slash, a name with
|
||||
* punctuation) or when the endpointId is registered already. Discovery lists Alexa.EndpointHealth for the device
|
||||
* unless endpointHealth is false.
|
||||
*/
|
||||
addDevice(definition: EndpointDefinition): Device;
|
||||
registerDevice(name: string, endpointId: string, displayCategory?: DisplayCategory | DisplayCategory[] | null): Device;
|
||||
private register;
|
||||
/** Forget a device (its listeners with it). Returns false when there was none. */
|
||||
unregisterDevice(endpointId: string): boolean;
|
||||
/** Forget every device. */
|
||||
|
|
|
|||
109
dist/types/AlexaInterface.d.ts
vendored
109
dist/types/AlexaInterface.d.ts
vendored
|
|
@ -1,109 +0,0 @@
|
|||
import type { ActionMapping } from "./ActionMapping.js";
|
||||
export declare enum AlexaInterfaceType {
|
||||
APPLICATION_STATE_REPORTER = "Alexa.ApplicationStateReporter",
|
||||
AUDIO_PLAY_QUEUE = "Alexa.Audio.PlayQueue",
|
||||
AUTHORIZATION_CONTROLLER = "Alexa.AuthorizationController",
|
||||
AUTOMATION_MANAGEMENT = "Alexa.AutomationManagement",
|
||||
AUTOMOTIVE_VEHICLE_DATA = "Alexa.Automotive.VehicleData",
|
||||
BRIGHTNESS_CONTROLLER = "Alexa.BrightnessController",
|
||||
CAMERA_LIVE_VIEW_CONTROLLER = "Alexa.Camera.LiveViewController",
|
||||
CAMERA_STREAM_CONTROLLER = "Alexa.CameraStreamController",
|
||||
CHANNEL_CONTROLLER = "Alexa.ChannelController",
|
||||
COLOR_CONTROLLER = "Alexa.ColorController",
|
||||
COLOR_TEMPERATURE_CONTROLLER = "Alexa.ColorTemperatureController",
|
||||
COMMISSIONABLE = "Alexa.Commissionable",
|
||||
CONSENT_MANAGEMENT_CONSENT_REQUIRED_REPORTER = "Alexa.ConsentManagement.ConsentRequiredReporter",
|
||||
CONTACT_SENSOR = "Alexa.ContactSensor",
|
||||
COOKING = "Alexa.Cooking",
|
||||
COOKING_FOOD_TEMPERATURE_CONTROLLER = "Alexa.Cooking.FoodTemperatureController",
|
||||
COOKING_FOOD_TEMPERATURE_SENSOR = "Alexa.Cooking.FoodTemperatureSensor",
|
||||
COOKING_PRESET_CONTROLLER = "Alexa.Cooking.PresetController",
|
||||
COOKING_TEMPERATURE_CONTROLLER = "Alexa.Cooking.TemperatureController",
|
||||
COOKING_TEMPERATURE_SENSOR = "Alexa.Cooking.TemperatureSensor",
|
||||
COOKING_TIME_CONTROLLER = "Alexa.Cooking.TimeController",
|
||||
DATA_CONTROLLER = "Alexa.DataController",
|
||||
DEVICE_USAGE_ESTIMATION = "Alexa.DeviceUsage.Estimation",
|
||||
DEVICE_USAGE_METER = "Alexa.DeviceUsage.Meter",
|
||||
DOORBELL_EVENT_SOURCE = "Alexa.DoorbellEventSource",
|
||||
ENDPOINT_HEALTH = "Alexa.EndpointHealth",
|
||||
EQUALIZER_CONTROLLER = "Alexa.EqualizerController",
|
||||
INPUT_CONTROLLER = "Alexa.InputController",
|
||||
INVENTORY_LEVEL_SENSOR = "Alexa.InventoryLevelSensor",
|
||||
INVENTORY_LEVEL_USAGE_SENSOR = "Alexa.InventoryLevelUsageSensor",
|
||||
INVENTORY_USAGE_SENSOR = "Alexa.InventoryUsageSensor",
|
||||
KEYPAD_CONTROLLER = "Alexa.KeypadController",
|
||||
LAUNCHER = "Alexa.Launcher",
|
||||
LOCK_CONTROLLER = "Alexa.LockController",
|
||||
MEDIA_PLAYBACK = "Alexa.Media.Playback",
|
||||
MEDIA_PLAY_QUEUE = "Alexa.Media.PlayQueue",
|
||||
MEDIA_SEARCH = "Alexa.Media.Search",
|
||||
MODE_CONTROLLER = "Alexa.ModeController",
|
||||
MOTION_SENSOR = "Alexa.MotionSensor",
|
||||
PERCENTAGE_CONTROLLER = "Alexa.PercentageController",
|
||||
PLAYBACK_CONTROLLER = "Alexa.PlaybackController",
|
||||
PLAYBACK_STATE_REPORTER = "Alexa.PlaybackStateReporter",
|
||||
POWER_CONTROLLER = "Alexa.PowerController",
|
||||
POWER_LEVEL_CONTROLLER = "Alexa.PowerLevelController",
|
||||
PROACTIVE_NOTIFICATION_SOURCE = "Alexa.ProactiveNotificationSource",
|
||||
RANGE_CONTROLLER = "Alexa.RangeController",
|
||||
RECORD_CONTROLLER = "Alexa.RecordController",
|
||||
REMOTE_VIDEO_PLAYER = "Alexa.RemoteVideoPlayer",
|
||||
RTC_SESSION_CONTROLLER = "Alexa.RTCSessionController",
|
||||
SCENE_CONTROLLER = "Alexa.SceneController",
|
||||
SECURITY_PANEL_CONTROLLER = "Alexa.SecurityPanelController",
|
||||
SECURITY_PANEL_CONTROLLER_ALERT = "Alexa.SecurityPanelController.Alert",
|
||||
SEEK_CONTROLLER = "Alexa.SeekController",
|
||||
SIMPLE_EVENT_SOURCE = "Alexa.SimpleEventSource",
|
||||
SMART_VISION_OBJECT_DETECTION_SENSOR = "Alexa.SmartVision.ObjectDetectionSensor",
|
||||
SMART_VISION_SNAPSHOT_PROVIDER = "Alexa.SmartVision.SnapshotProvider",
|
||||
SPEAKER = "Alexa.Speaker",
|
||||
STEP_SPEAKER = "Alexa.StepSpeaker",
|
||||
TEMPERATURE_SENSOR = "Alexa.TemperatureSensor",
|
||||
THERMOSTAT_CONTROLLER = "Alexa.ThermostatController",
|
||||
THERMOSTAT_CONTROLLER_CONFIGURATION = "Alexa.ThermostatController.Configuration",
|
||||
THERMOSTAT_CONTROLLER_HVAC_COMPONENTS = "Alexa.ThermostatController.HVAC.Components",
|
||||
THERMOSTAT_CONTROLLER_SCHEDULE = "Alexa.ThermostatController.Schedule",
|
||||
TIME_HOLD_CONTROLLER = "Alexa.TimeHoldController",
|
||||
TOGGLE_CONTROLLER = "Alexa.ToggleController",
|
||||
UI_CONTROLLER = "Alexa.UIController",
|
||||
USER_PREFERENCE = "Alexa.UserPreference",
|
||||
VIDEO_RECORDER = "Alexa.VideoRecorder",
|
||||
WAKE_ON_LAN_CONTROLLER = "Alexa.WakeOnLANController",
|
||||
UNKNOWN = "UNKNOWN"
|
||||
}
|
||||
/** One ModeController mode as discovery lists it (configuration.supportedModes): the value plus its friendly names. */
|
||||
export interface SupportedMode {
|
||||
value: string;
|
||||
modeResources?: {
|
||||
friendlyNames: Array<{
|
||||
"@type": string;
|
||||
value: {
|
||||
text?: string;
|
||||
locale?: string;
|
||||
assetId?: string;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
}
|
||||
export declare class AlexaInterface {
|
||||
type: AlexaInterfaceType;
|
||||
retrievable: boolean;
|
||||
proactivelyReported: boolean;
|
||||
instance: string;
|
||||
private friendlyNames;
|
||||
private actionMappings;
|
||||
private supportedModes;
|
||||
constructor(type: AlexaInterfaceType, retrievable?: boolean, proactivelyReported?: boolean, instance?: string);
|
||||
addActionMapping(mapping: ActionMapping): void;
|
||||
addFriendlyName(name: string, locale: string): void;
|
||||
/** The modes of a ModeController: { value, modeResources } objects as Alexa wants them (plain strings pass through as given). */
|
||||
addSupportedModes(modes: Array<string | SupportedMode>): void;
|
||||
setInstance(name: string): void;
|
||||
getType(): AlexaInterfaceType;
|
||||
getTypeString(): string;
|
||||
/** The version of the interface, from its descriptor. "UNKNOWN" for a name the registry does not have. */
|
||||
getVersion(): string;
|
||||
/** The names of the properties the interface reports, from its descriptor. */
|
||||
getProps(): string[];
|
||||
getJSON(): object;
|
||||
}
|
||||
9
dist/types/AlexaStatusMessage.d.ts
vendored
9
dist/types/AlexaStatusMessage.d.ts
vendored
|
|
@ -1,8 +1,5 @@
|
|||
import type { EndpointHealth, PowerController } from "./compat/enums.js";
|
||||
import type { MqttClient } from "mqtt";
|
||||
export declare enum EndpointHealth {
|
||||
OK = "OK",
|
||||
UNREACHABLE = "UNREACHABLE"
|
||||
}
|
||||
export declare enum ThermostatMode {
|
||||
OFF = "OFF",
|
||||
HEAT = "HEAT",
|
||||
|
|
@ -11,10 +8,6 @@ export declare enum ThermostatMode {
|
|||
ECO = "ECO",
|
||||
CUSTOM = "CUSTOM"
|
||||
}
|
||||
export declare enum PowerController {
|
||||
ON = "ON",
|
||||
OFF = "OFF"
|
||||
}
|
||||
export declare enum TemperatureSensorScale {
|
||||
CELSIUS = "CELSIUS",
|
||||
FAHRENHEIT = "FAHRENHEIT"
|
||||
|
|
|
|||
62
dist/types/Device.d.ts
vendored
62
dist/types/Device.d.ts
vendored
|
|
@ -1,62 +0,0 @@
|
|||
import { AlexaInterface } from "./AlexaInterface.js";
|
||||
import type { AlexaInterfaceType } from "./AlexaInterface.js";
|
||||
import { DisplayCategory } from "./DisplayCategory.js";
|
||||
import { EventEmitter } from "events";
|
||||
import type { MqttClient } from "mqtt";
|
||||
import { AlexaStatusMessage } from "./AlexaStatusMessage.js";
|
||||
import type { ChangeCause } from "./AlexaStatusMessage.js";
|
||||
import { AlexaErrorResponse } from "./AlexaErrorResponse.js";
|
||||
declare class Device extends EventEmitter {
|
||||
private mqttClient;
|
||||
private rootTopic;
|
||||
name: string;
|
||||
endpointId: string;
|
||||
displayCategory: Array<DisplayCategory> | null;
|
||||
description: string;
|
||||
manufacturerName: string;
|
||||
manufacturer: string;
|
||||
model: string;
|
||||
protected softwareVersion: string;
|
||||
private capabilities;
|
||||
/** Where a failed publish from this device or a message it built is reported; Alex2MQTT sets it (1.5.2). */
|
||||
onPublishError?: (err: Error) => void;
|
||||
constructor(mqttClient: MqttClient, rootTopic: string, name: string, endpointId: string, displayCategory: Array<DisplayCategory> | null, description?: string, manufacturerName?: string, manufacturer?: string, model?: string);
|
||||
/** Internal (1.5.2): Alex2MQTT.connect() re-binds every registered device to its new broker client after a disconnect(). */
|
||||
setMqttClient(client: MqttClient): void;
|
||||
getName(): string;
|
||||
setName(name: string): void;
|
||||
getEndpointId(): string;
|
||||
setDisplayCategory(category: DisplayCategory | DisplayCategory[]): void;
|
||||
getDisplayCategory(): Array<DisplayCategory>;
|
||||
setDescription(description: string): void;
|
||||
getDescription(): string;
|
||||
getErrorMessage(correlationToken: string): AlexaErrorResponse;
|
||||
getStatusMessage(correlationToken: string, isResponse?: boolean, isDeferred?: boolean): AlexaStatusMessage;
|
||||
/**
|
||||
* A proactive Alexa.ChangeReport (1.5.1): add the changed properties (the default target), optionally
|
||||
* .unchanged() then the others, and .send() - it goes to <root>/changeReport, which Alex2MQTT forwards to the Alexa
|
||||
* event gateway with the user's token. Alexa only accepts it for capabilities registered with proactivelyReported.
|
||||
*/
|
||||
getChangeReport(cause?: ChangeCause): AlexaStatusMessage;
|
||||
/**
|
||||
* Alexa.SceneController: answer an Activate / Deactivate directive with ActivationStarted / DeactivationStarted
|
||||
* (1.5.1). Resolves with the topic published to, or "" when the publish failed (never rejects, 1.5.2).
|
||||
*/
|
||||
sendSceneResponse(correlationToken: string, activated: boolean, cause?: ChangeCause, sendAsync?: boolean): Promise<string>;
|
||||
getCapabilities(): AlexaInterface[];
|
||||
setManufacturerName(name: string): void;
|
||||
getManufacturerName(): string;
|
||||
setManufacturer(manufacturer: string): void;
|
||||
getManufacturer(): string;
|
||||
setModel(model: string): void;
|
||||
getModel(): string;
|
||||
getSoftwareVersion(): string;
|
||||
/** Add a capability. 1.5.1: options.retrievable / proactivelyReported / instance (a change report needs proactivelyReported). */
|
||||
addCapability(type: AlexaInterfaceType, options?: {
|
||||
retrievable?: boolean;
|
||||
proactivelyReported?: boolean;
|
||||
instance?: string;
|
||||
}): AlexaInterface;
|
||||
getJSON(): Record<string, any>;
|
||||
}
|
||||
export default Device;
|
||||
60
dist/types/DisplayCategory.d.ts
vendored
60
dist/types/DisplayCategory.d.ts
vendored
|
|
@ -1,60 +0,0 @@
|
|||
export declare enum DisplayCategory {
|
||||
ACTIVITY_TRIGGER = "ACTIVITY_TRIGGER",
|
||||
AIR_CONDITIONER = "AIR_CONDITIONER",
|
||||
AIR_FRESHENER = "AIR_FRESHENER",
|
||||
AIR_PURIFIER = "AIR_PURIFIER",
|
||||
AIR_QUALITY_MONITOR = "AIR_QUALITY_MONITOR",
|
||||
ALEXA_VOICE_ENABLED = "ALEXA_VOICE_ENABLED",
|
||||
AUTO_ACCESSORY = "AUTO_ACCESSORY",
|
||||
BLUETOOTH_SPEAKER = "BLUETOOTH_SPEAKER",
|
||||
CAMERA = "CAMERA",
|
||||
CHRISTMAS_TREE = "CHRISTMAS_TREE",
|
||||
COFFEE_MAKER = "COFFEE_MAKER",
|
||||
COMPUTER = "COMPUTER",
|
||||
CONTACT_SENSOR = "CONTACT_SENSOR",
|
||||
DISHWASHER = "DISHWASHER",
|
||||
DOOR = "DOOR",
|
||||
DOORBELL = "DOORBELL",
|
||||
DRYER = "DRYER",
|
||||
EXTERIOR_BLIND = "EXTERIOR_BLIND",
|
||||
FAN = "FAN",
|
||||
GAME_CONSOLE = "GAME_CONSOLE",
|
||||
GARAGE_DOOR = "GARAGE_DOOR",
|
||||
HEADPHONES = "HEADPHONES",
|
||||
HUB = "HUB",
|
||||
INTERIOR_BLIND = "INTERIOR_BLIND",
|
||||
LAPTOP = "LAPTOP",
|
||||
LIGHT = "LIGHT",
|
||||
MICROWAVE = "MICROWAVE",
|
||||
MOBILE_PHONE = "MOBILE_PHONE",
|
||||
MOTION_SENSOR = "MOTION_SENSOR",
|
||||
MUSIC_SYSTEM = "MUSIC_SYSTEM",
|
||||
NETWORK_HARDWARE = "NETWORK_HARDWARE",
|
||||
OTHER = "OTHER",
|
||||
OVEN = "OVEN",
|
||||
PHONE = "PHONE",
|
||||
PRINTER = "PRINTER",
|
||||
REMOTE = "REMOTE",
|
||||
ROUTER = "ROUTER",
|
||||
SCENE_TRIGGER = "SCENE_TRIGGER",
|
||||
SCREEN = "SCREEN",
|
||||
SECURITY_PANEL = "SECURITY_PANEL",
|
||||
SECURITY_SYSTEM = "SECURITY_SYSTEM",
|
||||
SLOW_COOKER = "SLOW_COOKER",
|
||||
SMARTLOCK = "SMARTLOCK",
|
||||
SMARTPLUG = "SMARTPLUG",
|
||||
SPEAKER = "SPEAKER",
|
||||
STREAMING_DEVICE = "STREAMING_DEVICE",
|
||||
SWITCH = "SWITCH",
|
||||
TABLET = "TABLET",
|
||||
TEMPERATURE_SENSOR = "TEMPERATURE_SENSOR",
|
||||
THERMOSTAT = "THERMOSTAT",
|
||||
TV = "TV",
|
||||
VACUUM_CLEANER = "VACUUM_CLEANER",
|
||||
VACUUM = "VACUUM",
|
||||
/** Not on the list of display categories any more; kept for 1.x callers. */
|
||||
VEHICLE = "VEHICLE",
|
||||
WASHER = "WASHER",
|
||||
WATER_HEATER = "WATER_HEATER",
|
||||
WEARABLE = "WEARABLE"
|
||||
}
|
||||
23
dist/types/compat/ActionMapping.d.ts
vendored
Normal file
23
dist/types/compat/ActionMapping.d.ts
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import type { ActionsToDirective } from "../registry/types.js";
|
||||
import type { AlexaActions } from "./enums.js";
|
||||
/**
|
||||
* A semantics action mapping of 1.x: the phrases "open", "close", "raise", "lower" for one directive of the
|
||||
* capability it is added to.
|
||||
*
|
||||
* toggle.addActionMapping(new ActionMapping([AlexaActions.Close], "TurnOff"));
|
||||
* lift.addActionMapping(new ActionMapping([AlexaActions.Open], "SetRangeValue", { rangeValue: 100 }));
|
||||
*/
|
||||
export declare class ActionMapping {
|
||||
type: "ActionsToDirective";
|
||||
actions: AlexaActions[];
|
||||
directive: ActionsToDirective["directive"];
|
||||
/** Set when the mapping was built in a way that 3.0 will refuse; the bridge logs it at the next discovery. */
|
||||
readonly deprecation?: string;
|
||||
/**
|
||||
* directivePayload is the payload object of the directive (alexa-discovery-objects.html, "ActionMappings object").
|
||||
* 1.x took a string and put it into discovery as one. A string that holds a JSON object is parsed; any other
|
||||
* string throws a DeclarationError.
|
||||
*/
|
||||
constructor(actions: AlexaActions[], directiveName: string, directivePayload?: Record<string, unknown> | string);
|
||||
toJSON(): ActionsToDirective;
|
||||
}
|
||||
49
dist/types/compat/AlexaInterface.d.ts
vendored
Normal file
49
dist/types/compat/AlexaInterface.d.ts
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { Capability } from "../device/Capability.js";
|
||||
import type { CapabilityJson } from "../device/Capability.js";
|
||||
import type { Semantics } from "../registry/types.js";
|
||||
import type { ActionMapping } from "./ActionMapping.js";
|
||||
import type { AlexaInterfaceType } from "./enums.js";
|
||||
/** One ModeController mode as discovery lists it (configuration.supportedModes): the value plus its friendly names. */
|
||||
export interface SupportedMode {
|
||||
value: string;
|
||||
modeResources?: {
|
||||
friendlyNames: Array<{
|
||||
"@type": string;
|
||||
value: {
|
||||
text?: string;
|
||||
locale?: string;
|
||||
assetId?: string;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
}
|
||||
interface Options {
|
||||
semantics?: Semantics;
|
||||
supportedModes?: Array<string | SupportedMode>;
|
||||
}
|
||||
/**
|
||||
* A capability as 1.x declares it: device.addCapability(type, options), then the add and set methods below. It is a
|
||||
* Capability, so what the methods set reaches discovery the same way as the options of device.add(). Nothing is
|
||||
* refused here except an interface name the registry does not have: what Alexa would reject is logged by the bridge
|
||||
* when it answers a discovery.
|
||||
*/
|
||||
export declare class AlexaInterface extends Capability<any, any, Options> {
|
||||
constructor(type: AlexaInterfaceType | string, retrievable?: boolean, proactivelyReported?: boolean, instance?: string);
|
||||
/** The namespace of the interface, which is the value of its AlexaInterfaceType member. */
|
||||
get type(): AlexaInterfaceType;
|
||||
addActionMapping(mapping: ActionMapping): void;
|
||||
addFriendlyName(name: string, locale: string): void;
|
||||
/** The modes of a ModeController, as { value, modeResources } objects. */
|
||||
addSupportedModes(modes: Array<string | SupportedMode>): void;
|
||||
setInstance(name: string): void;
|
||||
getType(): AlexaInterfaceType;
|
||||
/** @deprecated The same as getType(). */
|
||||
getTypeString(): string;
|
||||
/** @deprecated Read descriptor.version. */
|
||||
getVersion(): string;
|
||||
/** @deprecated Read the keys of descriptor.properties. */
|
||||
getProps(): string[];
|
||||
getJSON(): CapabilityJson;
|
||||
toJSON(): CapabilityJson;
|
||||
}
|
||||
export {};
|
||||
193
dist/types/compat/enums.d.ts
vendored
Normal file
193
dist/types/compat/enums.d.ts
vendored
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
/** Every interface name of 1.x. registry.get() takes a member as it takes the namespace, which is its value. */
|
||||
export declare enum AlexaInterfaceType {
|
||||
APPLICATION_STATE_REPORTER = "Alexa.ApplicationStateReporter",
|
||||
AUDIO_PLAY_QUEUE = "Alexa.Audio.PlayQueue",
|
||||
AUTHORIZATION_CONTROLLER = "Alexa.AuthorizationController",
|
||||
AUTOMATION_MANAGEMENT = "Alexa.AutomationManagement",
|
||||
AUTOMOTIVE_VEHICLE_DATA = "Alexa.Automotive.VehicleData",
|
||||
BRIGHTNESS_CONTROLLER = "Alexa.BrightnessController",
|
||||
CAMERA_LIVE_VIEW_CONTROLLER = "Alexa.Camera.LiveViewController",
|
||||
CAMERA_STREAM_CONTROLLER = "Alexa.CameraStreamController",
|
||||
CHANNEL_CONTROLLER = "Alexa.ChannelController",
|
||||
COLOR_CONTROLLER = "Alexa.ColorController",
|
||||
COLOR_TEMPERATURE_CONTROLLER = "Alexa.ColorTemperatureController",
|
||||
COMMISSIONABLE = "Alexa.Commissionable",
|
||||
CONSENT_MANAGEMENT_CONSENT_REQUIRED_REPORTER = "Alexa.ConsentManagement.ConsentRequiredReporter",
|
||||
CONTACT_SENSOR = "Alexa.ContactSensor",
|
||||
COOKING = "Alexa.Cooking",
|
||||
COOKING_FOOD_TEMPERATURE_CONTROLLER = "Alexa.Cooking.FoodTemperatureController",
|
||||
COOKING_FOOD_TEMPERATURE_SENSOR = "Alexa.Cooking.FoodTemperatureSensor",
|
||||
COOKING_PRESET_CONTROLLER = "Alexa.Cooking.PresetController",
|
||||
COOKING_TEMPERATURE_CONTROLLER = "Alexa.Cooking.TemperatureController",
|
||||
COOKING_TEMPERATURE_SENSOR = "Alexa.Cooking.TemperatureSensor",
|
||||
COOKING_TIME_CONTROLLER = "Alexa.Cooking.TimeController",
|
||||
DATA_CONTROLLER = "Alexa.DataController",
|
||||
DEVICE_USAGE_ESTIMATION = "Alexa.DeviceUsage.Estimation",
|
||||
DEVICE_USAGE_METER = "Alexa.DeviceUsage.Meter",
|
||||
DOORBELL_EVENT_SOURCE = "Alexa.DoorbellEventSource",
|
||||
ENDPOINT_HEALTH = "Alexa.EndpointHealth",
|
||||
EQUALIZER_CONTROLLER = "Alexa.EqualizerController",
|
||||
INPUT_CONTROLLER = "Alexa.InputController",
|
||||
INVENTORY_LEVEL_SENSOR = "Alexa.InventoryLevelSensor",
|
||||
INVENTORY_LEVEL_USAGE_SENSOR = "Alexa.InventoryLevelUsageSensor",
|
||||
INVENTORY_USAGE_SENSOR = "Alexa.InventoryUsageSensor",
|
||||
KEYPAD_CONTROLLER = "Alexa.KeypadController",
|
||||
LAUNCHER = "Alexa.Launcher",
|
||||
LOCK_CONTROLLER = "Alexa.LockController",
|
||||
MEDIA_PLAYBACK = "Alexa.Media.Playback",
|
||||
MEDIA_PLAY_QUEUE = "Alexa.Media.PlayQueue",
|
||||
MEDIA_SEARCH = "Alexa.Media.Search",
|
||||
MODE_CONTROLLER = "Alexa.ModeController",
|
||||
MOTION_SENSOR = "Alexa.MotionSensor",
|
||||
PERCENTAGE_CONTROLLER = "Alexa.PercentageController",
|
||||
PLAYBACK_CONTROLLER = "Alexa.PlaybackController",
|
||||
PLAYBACK_STATE_REPORTER = "Alexa.PlaybackStateReporter",
|
||||
POWER_CONTROLLER = "Alexa.PowerController",
|
||||
POWER_LEVEL_CONTROLLER = "Alexa.PowerLevelController",
|
||||
PROACTIVE_NOTIFICATION_SOURCE = "Alexa.ProactiveNotificationSource",
|
||||
RANGE_CONTROLLER = "Alexa.RangeController",
|
||||
RECORD_CONTROLLER = "Alexa.RecordController",
|
||||
REMOTE_VIDEO_PLAYER = "Alexa.RemoteVideoPlayer",
|
||||
RTC_SESSION_CONTROLLER = "Alexa.RTCSessionController",
|
||||
SCENE_CONTROLLER = "Alexa.SceneController",
|
||||
SECURITY_PANEL_CONTROLLER = "Alexa.SecurityPanelController",
|
||||
SECURITY_PANEL_CONTROLLER_ALERT = "Alexa.SecurityPanelController.Alert",
|
||||
SEEK_CONTROLLER = "Alexa.SeekController",
|
||||
SIMPLE_EVENT_SOURCE = "Alexa.SimpleEventSource",
|
||||
SMART_VISION_OBJECT_DETECTION_SENSOR = "Alexa.SmartVision.ObjectDetectionSensor",
|
||||
SMART_VISION_SNAPSHOT_PROVIDER = "Alexa.SmartVision.SnapshotProvider",
|
||||
SPEAKER = "Alexa.Speaker",
|
||||
STEP_SPEAKER = "Alexa.StepSpeaker",
|
||||
TEMPERATURE_SENSOR = "Alexa.TemperatureSensor",
|
||||
THERMOSTAT_CONTROLLER = "Alexa.ThermostatController",
|
||||
THERMOSTAT_CONTROLLER_CONFIGURATION = "Alexa.ThermostatController.Configuration",
|
||||
THERMOSTAT_CONTROLLER_HVAC_COMPONENTS = "Alexa.ThermostatController.HVAC.Components",
|
||||
THERMOSTAT_CONTROLLER_SCHEDULE = "Alexa.ThermostatController.Schedule",
|
||||
TIME_HOLD_CONTROLLER = "Alexa.TimeHoldController",
|
||||
TOGGLE_CONTROLLER = "Alexa.ToggleController",
|
||||
UI_CONTROLLER = "Alexa.UIController",
|
||||
USER_PREFERENCE = "Alexa.UserPreference",
|
||||
VIDEO_RECORDER = "Alexa.VideoRecorder",
|
||||
WAKE_ON_LAN_CONTROLLER = "Alexa.WakeOnLANController",
|
||||
/** Not an interface: declaring it throws a DeclarationError. Kept because 1.x had it. */
|
||||
UNKNOWN = "UNKNOWN"
|
||||
}
|
||||
export declare enum DisplayCategory {
|
||||
ACTIVITY_TRIGGER = "ACTIVITY_TRIGGER",
|
||||
AIR_CONDITIONER = "AIR_CONDITIONER",
|
||||
AIR_FRESHENER = "AIR_FRESHENER",
|
||||
AIR_PURIFIER = "AIR_PURIFIER",
|
||||
AIR_QUALITY_MONITOR = "AIR_QUALITY_MONITOR",
|
||||
ALEXA_VOICE_ENABLED = "ALEXA_VOICE_ENABLED",
|
||||
AUTO_ACCESSORY = "AUTO_ACCESSORY",
|
||||
BLUETOOTH_SPEAKER = "BLUETOOTH_SPEAKER",
|
||||
CAMERA = "CAMERA",
|
||||
CHRISTMAS_TREE = "CHRISTMAS_TREE",
|
||||
COFFEE_MAKER = "COFFEE_MAKER",
|
||||
COMPUTER = "COMPUTER",
|
||||
CONTACT_SENSOR = "CONTACT_SENSOR",
|
||||
DISHWASHER = "DISHWASHER",
|
||||
DOOR = "DOOR",
|
||||
DOORBELL = "DOORBELL",
|
||||
DRYER = "DRYER",
|
||||
EXTERIOR_BLIND = "EXTERIOR_BLIND",
|
||||
FAN = "FAN",
|
||||
GAME_CONSOLE = "GAME_CONSOLE",
|
||||
GARAGE_DOOR = "GARAGE_DOOR",
|
||||
HEADPHONES = "HEADPHONES",
|
||||
HUB = "HUB",
|
||||
INTERIOR_BLIND = "INTERIOR_BLIND",
|
||||
LAPTOP = "LAPTOP",
|
||||
LIGHT = "LIGHT",
|
||||
MICROWAVE = "MICROWAVE",
|
||||
MOBILE_PHONE = "MOBILE_PHONE",
|
||||
MOTION_SENSOR = "MOTION_SENSOR",
|
||||
MUSIC_SYSTEM = "MUSIC_SYSTEM",
|
||||
NETWORK_HARDWARE = "NETWORK_HARDWARE",
|
||||
OTHER = "OTHER",
|
||||
OVEN = "OVEN",
|
||||
PHONE = "PHONE",
|
||||
PRINTER = "PRINTER",
|
||||
REMOTE = "REMOTE",
|
||||
ROUTER = "ROUTER",
|
||||
SCENE_TRIGGER = "SCENE_TRIGGER",
|
||||
SCREEN = "SCREEN",
|
||||
SECURITY_PANEL = "SECURITY_PANEL",
|
||||
SECURITY_SYSTEM = "SECURITY_SYSTEM",
|
||||
SLOW_COOKER = "SLOW_COOKER",
|
||||
SMARTLOCK = "SMARTLOCK",
|
||||
SMARTPLUG = "SMARTPLUG",
|
||||
SPEAKER = "SPEAKER",
|
||||
STREAMING_DEVICE = "STREAMING_DEVICE",
|
||||
SWITCH = "SWITCH",
|
||||
TABLET = "TABLET",
|
||||
TEMPERATURE_SENSOR = "TEMPERATURE_SENSOR",
|
||||
THERMOSTAT = "THERMOSTAT",
|
||||
TV = "TV",
|
||||
VACUUM_CLEANER = "VACUUM_CLEANER",
|
||||
VACUUM = "VACUUM",
|
||||
/** Not on the list of display categories any more; kept for 1.x callers. */
|
||||
VEHICLE = "VEHICLE",
|
||||
WASHER = "WASHER",
|
||||
WATER_HEATER = "WATER_HEATER",
|
||||
WEARABLE = "WEARABLE"
|
||||
}
|
||||
export declare enum AlexaActions {
|
||||
Open = "Alexa.Actions.Open",
|
||||
Close = "Alexa.Actions.Close",
|
||||
Raise = "Alexa.Actions.Raise",
|
||||
Lower = "Alexa.Actions.Lower",
|
||||
SetEcoOn = "Alexa.Actions.SetEcoOn",
|
||||
SetEcoOff = "Alexa.Actions.SetEcoOff"
|
||||
}
|
||||
/** The values of powerState and toggleState. */
|
||||
export declare const PowerState: {
|
||||
readonly ON: "ON";
|
||||
readonly OFF: "OFF";
|
||||
};
|
||||
export type PowerState = (typeof PowerState)[keyof typeof PowerState];
|
||||
declare const Connectivity: {
|
||||
readonly OK: "OK";
|
||||
readonly UNREACHABLE: "UNREACHABLE";
|
||||
};
|
||||
/**
|
||||
* The Alexa.PowerController interface, for device.add(). PowerController.ON and PowerController.OFF are the 1.x enum
|
||||
* of power states and stay until 3.0: PowerState has the same two members.
|
||||
*/
|
||||
export declare const PowerController: import("../index.js").InterfaceDescriptor<{
|
||||
powerState: {
|
||||
name: string;
|
||||
value: import("../registry/schema.js").EnumSchema<"ON" | "OFF">;
|
||||
};
|
||||
}, {
|
||||
TurnOn: {
|
||||
name: string;
|
||||
payload: import("../index.js").Schema<import("../registry/schema.js").InferShape<{}>>;
|
||||
};
|
||||
TurnOff: {
|
||||
name: string;
|
||||
payload: import("../index.js").Schema<import("../registry/schema.js").InferShape<{}>>;
|
||||
};
|
||||
}, import("../registry/schema.js").InferShape<{
|
||||
verificationsRequired: import("../registry/schema.js").OptionalSchema<("TurnOn" | "TurnOff")[]>;
|
||||
}>, false> & {
|
||||
readonly ON: "ON";
|
||||
readonly OFF: "OFF";
|
||||
};
|
||||
export type PowerController = PowerState;
|
||||
/** The Alexa.EndpointHealth interface, for device.add(). EndpointHealth.OK and EndpointHealth.UNREACHABLE are the 1.x enum of connectivity values. */
|
||||
export declare const EndpointHealth: import("../index.js").InterfaceDescriptor<{
|
||||
connectivity: {
|
||||
name: string;
|
||||
value: import("../index.js").Schema<import("../registry/schema.js").InferShape<{
|
||||
value: import("../registry/schema.js").EnumSchema<"OK" | "UNREACHABLE">;
|
||||
reason: import("../registry/schema.js").OptionalSchema<"WIFI_BAD_PASSWORD" | "WIFI_AP_NOT_FOUND" | "WIFI_ROUTER_UNREACHABLE" | "WIFI_AP_CHANNEL_QUALITY_LOW" | "INTERNET_UNREACHABLE" | "CAPTIVE_PORTAL_CHECK_FAILED" | "UNKNOWN">;
|
||||
}>>;
|
||||
note: string;
|
||||
};
|
||||
}, {}, {}, false> & {
|
||||
readonly OK: "OK";
|
||||
readonly UNREACHABLE: "UNREACHABLE";
|
||||
};
|
||||
export type EndpointHealth = (typeof Connectivity)[keyof typeof Connectivity];
|
||||
export {};
|
||||
79
dist/types/device/Capability.d.ts
vendored
Normal file
79
dist/types/device/Capability.d.ts
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import type { Declared, Directives, InterfaceDescriptor, Label, Properties, Semantics } from "../registry/types.js";
|
||||
/** What a declaration can set for any interface. */
|
||||
export interface CommonOptions {
|
||||
/** The name of the instance of a generic controller: "Blind.Lift", "Fan.Speed". */
|
||||
instance?: string;
|
||||
/** What the user calls the instance; the first name is the one the Alexa app shows. */
|
||||
friendlyNames?: Label[];
|
||||
/** The properties are in the answer to ReportState. Default: true. */
|
||||
retrievable?: boolean;
|
||||
/** A change of the properties is sent to Alexa as a ChangeReport. Default: false. */
|
||||
proactivelyReported?: boolean;
|
||||
/** The user can ask for the properties and cannot set them. Left out of discovery when not given. */
|
||||
nonControllable?: boolean;
|
||||
}
|
||||
/** The same as a schema. The friendly names are checked with the instance, by the rules of the interface. */
|
||||
export declare const commonOptions: import("../registry/schema.js").Schema<import("../registry/schema.js").InferShape<{
|
||||
instance: import("../registry/schema.js").OptionalSchema<string>;
|
||||
friendlyNames: import("../registry/schema.js").OptionalSchema<unknown[]>;
|
||||
retrievable: import("../registry/schema.js").OptionalSchema<boolean>;
|
||||
proactivelyReported: import("../registry/schema.js").OptionalSchema<boolean>;
|
||||
nonControllable: import("../registry/schema.js").OptionalSchema<boolean>;
|
||||
}>>;
|
||||
type Naming<I extends boolean> = I extends true ? {
|
||||
instance: string;
|
||||
friendlyNames: Label[];
|
||||
} : {
|
||||
instance?: string;
|
||||
friendlyNames?: Label[];
|
||||
};
|
||||
/** The options of device.add() for one interface: its own, and the ones every interface has. */
|
||||
export type Declaration<O, I extends boolean> = O & Omit<CommonOptions, "instance" | "friendlyNames"> & Naming<I>;
|
||||
/** A capability object of a discovery answer (alexa-discovery-objects.html, "Capability object"). */
|
||||
export interface CapabilityJson {
|
||||
type: "AlexaInterface";
|
||||
interface: string;
|
||||
instance?: string;
|
||||
version: string;
|
||||
properties?: {
|
||||
supported: Array<{
|
||||
name: string;
|
||||
}>;
|
||||
proactivelyReported: boolean;
|
||||
retrievable: boolean;
|
||||
nonControllable?: boolean;
|
||||
};
|
||||
capabilityResources?: {
|
||||
friendlyNames: Label[];
|
||||
};
|
||||
configuration?: Record<string, unknown>;
|
||||
configurations?: Record<string, unknown>;
|
||||
semantics?: Semantics;
|
||||
[field: string]: unknown;
|
||||
}
|
||||
/** One interface as an endpoint declares it: the descriptor, and what the declaration says about this endpoint. */
|
||||
export declare class Capability<P extends Properties = Properties, D extends Directives = Directives, O = {}> implements Declared<O> {
|
||||
readonly descriptor: InterfaceDescriptor<P, D, O, boolean>;
|
||||
/** The endpoint the capability is declared on; the device sets it. */
|
||||
endpointId: string;
|
||||
/** "" for an interface without instances. */
|
||||
instance: string;
|
||||
friendlyNames: Label[];
|
||||
retrievable: boolean;
|
||||
proactivelyReported: boolean;
|
||||
nonControllable?: boolean;
|
||||
/** The options of the interface: a range, the supported modes, the semantics. */
|
||||
options: O;
|
||||
/** What the bridge logs about the declaration, once, when it answers a discovery. */
|
||||
readonly notes: string[];
|
||||
constructor(descriptor: InterfaceDescriptor<P, D, O, boolean>, declared: CommonOptions & {
|
||||
options: O;
|
||||
});
|
||||
get namespace(): string;
|
||||
/** Mappings of "open", "close", "raise", "lower" and of states, when the declaration has any. */
|
||||
get semantics(): Semantics | undefined;
|
||||
/** The capability object for discovery, its fields in the order of the example on alexa-discovery-objects.html. */
|
||||
toJSON(): CapabilityJson;
|
||||
}
|
||||
export type AnyCapability = Capability<any, any, any>;
|
||||
export {};
|
||||
135
dist/types/device/Device.d.ts
vendored
Normal file
135
dist/types/device/Device.d.ts
vendored
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
import { EventEmitter } from "events";
|
||||
import type { MqttClient } from "mqtt";
|
||||
import { AlexaErrorResponse } from "../AlexaErrorResponse.js";
|
||||
import { AlexaStatusMessage } from "../AlexaStatusMessage.js";
|
||||
import type { ChangeCause } from "../AlexaStatusMessage.js";
|
||||
import { AlexaInterface } from "../compat/AlexaInterface.js";
|
||||
import { DisplayCategory } from "../compat/enums.js";
|
||||
import type { AlexaInterfaceType } from "../compat/enums.js";
|
||||
import type { DisplayCategoryName } from "../registry/catalog.js";
|
||||
import type { Directives, InterfaceDescriptor, Properties } from "../registry/types.js";
|
||||
import { Capability } from "./Capability.js";
|
||||
import type { AnyCapability, CapabilityJson, Declaration } from "./Capability.js";
|
||||
import type { EndpointFields } from "./validate.js";
|
||||
/** An endpoint as bridge.addDevice() takes it. */
|
||||
export interface EndpointDefinition {
|
||||
/** Up to 256 letters, digits, spaces and _ - = # ; : ? @ &. The same id at every discovery. */
|
||||
endpointId: string;
|
||||
/** What the user calls the device: letters, digits and spaces. */
|
||||
name: string;
|
||||
/** The first one is the category the Alexa app shows the device under. */
|
||||
categories: Array<DisplayCategoryName | DisplayCategory>;
|
||||
/** Shown in the Alexa app, up to 128 characters. Default: "Alexa to Node.js bridge". */
|
||||
description?: string;
|
||||
/** Up to 128 characters. Default: "Alex2Node". */
|
||||
manufacturerName?: string;
|
||||
manufacturer?: string;
|
||||
model?: string;
|
||||
serialNumber?: string;
|
||||
firmwareVersion?: string;
|
||||
softwareVersion?: string;
|
||||
customIdentifier?: string;
|
||||
/** Returned with every directive to the endpoint. Up to 5000 bytes; not a place for state. */
|
||||
cookie?: Record<string, string>;
|
||||
/** false: the device gets no Alexa.EndpointHealth unless it declares one. */
|
||||
endpointHealth?: boolean;
|
||||
}
|
||||
/** An endpoint object of a discovery answer (alexa-discovery-objects.html, "Endpoint object"). */
|
||||
export interface EndpointJson extends EndpointFields {
|
||||
capabilities: CapabilityJson[];
|
||||
}
|
||||
type DeclarationArguments<O, I extends boolean> = {} extends Declaration<O, I> ? [options?: Declaration<O, I>] : [options: Declaration<O, I>];
|
||||
declare class Device extends EventEmitter {
|
||||
private mqttClient;
|
||||
private rootTopic;
|
||||
name: string;
|
||||
endpointId: string;
|
||||
displayCategory: Array<DisplayCategory> | null;
|
||||
description: string;
|
||||
manufacturerName: string;
|
||||
manufacturer: string;
|
||||
model: string;
|
||||
softwareVersion: string;
|
||||
serialNumber: string;
|
||||
firmwareVersion: string;
|
||||
customIdentifier: string;
|
||||
cookie?: Record<string, string>;
|
||||
/**
|
||||
* Discovery lists the Alexa interface on the endpoint (alexa-interface.html: "You must explicitly identify your
|
||||
* support for the Alexa interface"). The bridge sets it from its alexaInterface option.
|
||||
*/
|
||||
alexaInterface: boolean;
|
||||
/**
|
||||
* Discovery lists Alexa.EndpointHealth when the device did not declare it and is not a scene. On for a device of
|
||||
* bridge.addDevice(), off for one of registerDevice(), which is announced as 1.x announced it.
|
||||
*/
|
||||
endpointHealth: boolean;
|
||||
private capabilities;
|
||||
/** Where a failed publish from this device or a message it built is reported; Alex2MQTT sets it (1.5.2). */
|
||||
onPublishError?: (err: Error) => void;
|
||||
constructor(mqttClient: MqttClient, rootTopic: string, name: string, endpointId: string, displayCategory: Array<DisplayCategory> | null, description?: string, manufacturerName?: string, manufacturer?: string, model?: string);
|
||||
/** Internal (1.5.2): Alex2MQTT.connect() re-binds every registered device to its new broker client after a disconnect(). */
|
||||
setMqttClient(client: MqttClient): void;
|
||||
getName(): string;
|
||||
setName(name: string): void;
|
||||
getEndpointId(): string;
|
||||
setDisplayCategory(category: DisplayCategory | DisplayCategory[]): void;
|
||||
getDisplayCategory(): Array<DisplayCategory>;
|
||||
setDescription(description: string): void;
|
||||
getDescription(): string;
|
||||
getErrorMessage(correlationToken: string): AlexaErrorResponse;
|
||||
getStatusMessage(correlationToken: string, isResponse?: boolean, isDeferred?: boolean): AlexaStatusMessage;
|
||||
/**
|
||||
* A proactive Alexa.ChangeReport (1.5.1): add the changed properties (the default target), optionally
|
||||
* .unchanged() then the others, and .send() - it goes to <root>/changeReport, which Alex2MQTT forwards to the Alexa
|
||||
* event gateway with the user's token. Alexa only accepts it for capabilities registered with proactivelyReported.
|
||||
*/
|
||||
getChangeReport(cause?: ChangeCause): AlexaStatusMessage;
|
||||
/**
|
||||
* Alexa.SceneController: answer an Activate / Deactivate directive with ActivationStarted / DeactivationStarted
|
||||
* (1.5.1). Resolves with the topic published to, or "" when the publish failed (never rejects, 1.5.2).
|
||||
*/
|
||||
sendSceneResponse(correlationToken: string, activated: boolean, cause?: ChangeCause, sendAsync?: boolean): Promise<string>;
|
||||
/** The capabilities the device declared, in the order it declared them. */
|
||||
getCapabilities(): AnyCapability[];
|
||||
setManufacturerName(name: string): void;
|
||||
getManufacturerName(): string;
|
||||
setManufacturer(manufacturer: string): void;
|
||||
getManufacturer(): string;
|
||||
setModel(model: string): void;
|
||||
getModel(): string;
|
||||
getSoftwareVersion(): string;
|
||||
/**
|
||||
* Declare an interface of the device:
|
||||
*
|
||||
* lamp.add(PowerController, { proactivelyReported: true });
|
||||
* blinds.add(RangeController, { instance: "Blind.Lift", friendlyNames: [asset("Alexa.Setting.Opening")],
|
||||
* range: { min: 0, max: 100, precision: 1 } });
|
||||
*
|
||||
* Throws a DeclarationError that names the endpoint, the interface and the instance when Alexa would reject the
|
||||
* capability; the device is then as it was before the call.
|
||||
*/
|
||||
add<P extends Properties, D extends Directives, O, I extends boolean>(descriptor: InterfaceDescriptor<P, D, O, I>, ...[options]: DeclarationArguments<O, I>): Capability<P, D, O>;
|
||||
/**
|
||||
* Declare an interface the 1.x way, by its name: options.retrievable / proactivelyReported / instance, then the
|
||||
* add and set methods of the capability that is returned. Throws for a name that is not an interface. Anything
|
||||
* else Alexa would reject is not refused here: check() lists it.
|
||||
*/
|
||||
addCapability(type: AlexaInterfaceType | string, options?: {
|
||||
retrievable?: boolean;
|
||||
proactivelyReported?: boolean;
|
||||
instance?: string;
|
||||
}): AlexaInterface;
|
||||
/**
|
||||
* What Alexa would reject in the device as it is declared now, one line for each: a name with punctuation, an
|
||||
* interface declared twice. Also what a capability noted about its declaration. Empty when there is nothing.
|
||||
* The bridge logs the lines when it answers a discovery.
|
||||
*/
|
||||
check(): string[];
|
||||
/** The endpoint object for discovery. */
|
||||
getJSON(): EndpointJson;
|
||||
private fields;
|
||||
private view;
|
||||
private announced;
|
||||
}
|
||||
export default Device;
|
||||
20
dist/types/device/validate.d.ts
vendored
Normal file
20
dist/types/device/validate.d.ts
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import type { AnyDescriptor, Declared, EndpointView } from "../registry/types.js";
|
||||
/** An endpoint as discovery sends it, without its capabilities. */
|
||||
export interface EndpointFields {
|
||||
endpointId: string;
|
||||
friendlyName: string;
|
||||
description: string;
|
||||
manufacturerName: string;
|
||||
displayCategories: readonly string[];
|
||||
additionalAttributes: Readonly<Record<string, string>>;
|
||||
cookie?: Readonly<Record<string, string>>;
|
||||
}
|
||||
/** Throws the first rule of the Endpoint object that the fields break. */
|
||||
export declare function checkEndpoint(endpoint: EndpointFields): void;
|
||||
/** alexa-discovery.html, "Interface limits". count includes the capabilities the library adds. */
|
||||
export declare function checkCapabilityCount(endpointId: string, count: number): void;
|
||||
/**
|
||||
* Throws the first rule that a capability breaks on its endpoint. endpoint.capabilities are the ones declared
|
||||
* before it. A stub is checked for being declared twice and for nothing else: the library does not know its rules.
|
||||
*/
|
||||
export declare function checkCapability(capability: Declared<unknown>, descriptor: AnyDescriptor, endpoint: EndpointView): void;
|
||||
24
dist/types/index.d.ts
vendored
24
dist/types/index.d.ts
vendored
|
|
@ -1,13 +1,19 @@
|
|||
export { default as Alex2MQTT, DEFAULT_HOST } from "./Alex2Node.js";
|
||||
export type { Alex2MQTTOptions } from "./Alex2Node.js";
|
||||
export { default as Device } from "./Device.js";
|
||||
export { AlexaInterface, AlexaInterfaceType } from "./AlexaInterface.js";
|
||||
export type { SupportedMode } from "./AlexaInterface.js";
|
||||
export { ActionMapping, AlexaActions } from "./ActionMapping.js";
|
||||
export { DisplayCategory } from "./DisplayCategory.js";
|
||||
export { AlexaStatusMessage, PowerController, EndpointHealth, TemperatureSensorScale, ThermostatMode } from "./AlexaStatusMessage.js";
|
||||
export { default as Device } from "./device/Device.js";
|
||||
export type { EndpointDefinition, EndpointJson } from "./device/Device.js";
|
||||
export { Capability } from "./device/Capability.js";
|
||||
export type { CapabilityJson, CommonOptions, Declaration } from "./device/Capability.js";
|
||||
export { registry, DeclarationError, SchemaError } from "./registry/index.js";
|
||||
export { Alexa, BrightnessController, TemperatureSensor } from "./registry/index.js";
|
||||
export { PowerController, EndpointHealth } from "./compat/enums.js";
|
||||
export { asset, text } from "./registry/resources.js";
|
||||
export { ASSETS as Assets, UNITS_OF_MEASURE as Units, ACTIONS as Actions, STATES as States, DISPLAY_CATEGORIES as DisplayCategories, } from "./registry/index.js";
|
||||
export type { ActionId, AssetId, DisplayCategoryName, StateId, UnitOfMeasure, ActionsToDirective, AnyDescriptor, CapabilityExtras, Declared, DirectiveDescriptor, EndpointView, EventDescriptor, InterfaceDescriptor, Label, PropertyDescriptor, Semantics, StatesToRange, StatesToValue, Infer, Schema, Temperature, TimeInterval, } from "./registry/index.js";
|
||||
export { AlexaInterface } from "./compat/AlexaInterface.js";
|
||||
export type { SupportedMode } from "./compat/AlexaInterface.js";
|
||||
export { ActionMapping } from "./compat/ActionMapping.js";
|
||||
export { AlexaActions, AlexaInterfaceType, DisplayCategory, PowerState } from "./compat/enums.js";
|
||||
export { AlexaStatusMessage, TemperatureSensorScale, ThermostatMode } from "./AlexaStatusMessage.js";
|
||||
export type { ChangeCause } from "./AlexaStatusMessage.js";
|
||||
export { AlexaErrorType, AlexaErrorResponse } from "./AlexaErrorResponse.js";
|
||||
export { registry, DeclarationError, SchemaError } from "./registry/index.js";
|
||||
export { ASSETS as Assets, UNITS_OF_MEASURE as Units, ACTIONS as Actions, STATES as States, DISPLAY_CATEGORIES as DisplayCategories, } from "./registry/index.js";
|
||||
export type { ActionId, AssetId, DisplayCategoryName, StateId, UnitOfMeasure, AnyDescriptor, CapabilityExtras, Declared, DirectiveDescriptor, EndpointView, EventDescriptor, InterfaceDescriptor, Label, PropertyDescriptor, Infer, Schema, Temperature, TimeInterval, } from "./registry/index.js";
|
||||
|
|
|
|||
2
dist/types/registry/index.d.ts
vendored
2
dist/types/registry/index.d.ts
vendored
|
|
@ -14,7 +14,7 @@ export declare const registry: {
|
|||
};
|
||||
export { Alexa, BrightnessController, EndpointHealth, PowerController, TemperatureSensor };
|
||||
export { DeclarationError, defineInterface } from "./types.js";
|
||||
export type { AnyDescriptor, CapabilityExtras, Declared, DirectiveDescriptor, EndpointView, EventDescriptor, InterfaceDescriptor, Label, PropertyDescriptor, } from "./types.js";
|
||||
export type { ActionsToDirective, AnyDescriptor, CapabilityExtras, Declared, DirectiveDescriptor, EndpointView, EventDescriptor, InterfaceDescriptor, Label, PropertyDescriptor, Semantics, StatesToRange, StatesToValue, } from "./types.js";
|
||||
export { s, SchemaError } from "./schema.js";
|
||||
export type { Infer, Schema, Temperature, TimeInterval } from "./schema.js";
|
||||
export * from "./catalog.js";
|
||||
|
|
|
|||
13
dist/types/registry/resources.d.ts
vendored
Normal file
13
dist/types/registry/resources.d.ts
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import type { AssetId } from "./catalog.js";
|
||||
import type { Schema } from "./schema.js";
|
||||
import type { Label } from "./types.js";
|
||||
/** A friendly name as text, in one locale. */
|
||||
export declare function text(name: string, locale?: string): Label;
|
||||
/** A friendly name from the global Alexa catalog: one id, several names, every language Alexa speaks. */
|
||||
export declare function asset(assetId: AssetId): Label;
|
||||
/** One friendly name. An asset has to be in the catalog, a text must not be a word Alexa keeps for itself. */
|
||||
export declare const label: Schema<Label>;
|
||||
/** The friendly names of an instance, a mode or a preset: at least one. */
|
||||
export declare const labels: Schema<Label[]>;
|
||||
/** What the user is shown for a friendly name: the text, or the id of the asset. */
|
||||
export declare function shownAs(name: Label): string;
|
||||
7
dist/types/registry/schema.d.ts
vendored
7
dist/types/registry/schema.d.ts
vendored
|
|
@ -44,6 +44,10 @@ export interface TimeInterval {
|
|||
end?: string;
|
||||
duration?: string;
|
||||
}
|
||||
/** The error of a value that is not what a schema expects. */
|
||||
export declare function mismatch(path: string, expects: string, input: unknown): SchemaError;
|
||||
/** The path of a key of the object at path. */
|
||||
export declare const at: (path: string, key: string) => string;
|
||||
declare function number(rules?: NumberRules): Schema<number>;
|
||||
declare function string(rules?: {
|
||||
min?: number;
|
||||
|
|
@ -54,6 +58,8 @@ declare function string(rules?: {
|
|||
declare function boolean(): Schema<boolean>;
|
||||
declare function literal<V extends string | number | boolean | null>(value: V): Schema<V>;
|
||||
declare function enumeration<V extends readonly string[]>(...values: V): EnumSchema<V[number]>;
|
||||
/** One of a list too long to print in an error message: expects says what the list is. */
|
||||
declare function oneOf<V extends string>(values: readonly V[], expects: string): EnumSchema<V>;
|
||||
declare function unknown(): Schema<unknown>;
|
||||
declare function optional<T>(inner: Schema<T>): OptionalSchema<T>;
|
||||
declare function nullable<T>(inner: Schema<T>): Schema<T | null>;
|
||||
|
|
@ -78,6 +84,7 @@ export declare const s: {
|
|||
boolean: typeof boolean;
|
||||
literal: typeof literal;
|
||||
enum: typeof enumeration;
|
||||
oneOf: typeof oneOf;
|
||||
unknown: typeof unknown;
|
||||
optional: typeof optional;
|
||||
nullable: typeof nullable;
|
||||
|
|
|
|||
33
dist/types/registry/types.d.ts
vendored
33
dist/types/registry/types.d.ts
vendored
|
|
@ -15,6 +15,35 @@ export type Label = {
|
|||
assetId: string;
|
||||
};
|
||||
};
|
||||
/** Phrases ("open", "lower") mapped to one directive (alexa-discovery-objects.html, "ActionMappings object"). */
|
||||
export interface ActionsToDirective {
|
||||
"@type": "ActionsToDirective";
|
||||
actions: string[];
|
||||
directive: {
|
||||
name: string;
|
||||
payload?: Record<string, unknown>;
|
||||
};
|
||||
}
|
||||
/** States ("open", "closed") mapped to a value of the property (same page, "StateMappings object"). */
|
||||
export interface StatesToValue {
|
||||
"@type": "StatesToValue";
|
||||
states: string[];
|
||||
value: unknown;
|
||||
}
|
||||
/** States mapped to a range of values of the property. */
|
||||
export interface StatesToRange {
|
||||
"@type": "StatesToRange";
|
||||
states: string[];
|
||||
range: {
|
||||
minimumValue: number;
|
||||
maximumValue: number;
|
||||
};
|
||||
}
|
||||
/** The semantics object of a generic controller: at least one of the two lists. */
|
||||
export interface Semantics {
|
||||
actionMappings?: ActionsToDirective[];
|
||||
stateMappings?: Array<StatesToValue | StatesToRange>;
|
||||
}
|
||||
export interface PropertyDescriptor<V> {
|
||||
name: string;
|
||||
value: Schema<V>;
|
||||
|
|
@ -49,7 +78,7 @@ export interface CapabilityExtras {
|
|||
properties?: false;
|
||||
}
|
||||
/** A capability as declared on an endpoint: what discovery() and validate() of its descriptor are given. */
|
||||
export interface Declared<O = Record<string, unknown>> {
|
||||
export interface Declared<O = unknown> {
|
||||
readonly endpointId: string;
|
||||
readonly namespace: string;
|
||||
/** "" when the interface is declared without an instance. */
|
||||
|
|
@ -67,7 +96,7 @@ export interface EndpointView {
|
|||
readonly friendlyName: string;
|
||||
readonly description: string;
|
||||
readonly displayCategories: readonly string[];
|
||||
/** The other capabilities of the endpoint. */
|
||||
/** The capabilities declared on the endpoint before this one. */
|
||||
readonly capabilities: readonly Declared[];
|
||||
}
|
||||
export type Properties = Record<string, PropertyDescriptor<any>>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue