Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alexa: refactor code structure #606

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/alexa/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

{
"scrypted.debugHost": "127.0.0.1",
"scrypted.debugHost": "10.10.0.50",
}
3,159 changes: 2,906 additions & 253 deletions plugins/alexa/package-lock.json

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions plugins/alexa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/alexa",
"version": "0.1.0",
"version": "0.2.0",
"scripts": {
"scrypted-setup-project": "scrypted-setup-project",
"prescrypted-setup-project": "scrypted-package-json",
Expand All @@ -21,26 +21,24 @@
"amazon"
],
"scrypted": {
"name": "Alexa Plugin",
"name": "Alexa",
"type": "API",
"interfaces": [
"HttpRequestHandler",
"MixinProvider"
"MixinProvider",
"Settings"
],
"pluginDependencies": [
"@scrypted/cloud",
"@scrypted/webrtc"
]
},
"dependencies": {
"@types/node": "^16.6.1",
"alexa-smarthome-ts": "^0.0.1",
"axios": "^1.3.4",
"uuid": "^9.0.0"
},
"devDependencies": {
"@scrypted/common": "file:../../common",
"@scrypted/sdk": "file:../../sdk",
"@scrypted/server": "file:../../server"
"@types/node": "^18.4.2",
"@scrypted/sdk": "^0.2.70"
}
}
221 changes: 221 additions & 0 deletions plugins/alexa/src/alexa.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
export declare type DisplayCategory = 'ACTIVITY_TRIGGER' | 'CAMERA' | 'CONTACT_SENSOR' | 'DOOR' | 'DOORBELL' | 'GARAGE_DOOR' | 'LIGHT' | 'MICROWAVE' | 'MOTION_SENSOR' | 'OTHER' | 'SCENE_TRIGGER' | 'SECURITY_PANEL' | 'SMARTLOCK' | 'SMARTPLUG' | 'SPEAKER' | 'SWITCH' | 'TEMPERATURE_SENSOR' | 'THERMOSTAT' | 'TV';

/*
COMMON DIRECTIVES AND RESPONSES
*/

export interface AddOrUpdateReport {
event: {
header: Header<"Alexa.Discovery", "AddOrUpdateReport">;
payload: AddOrUpdateReportPayload;
}
}

export interface DeleteReport {
event: {
header: Header<"Alexa.Discovery", "DeleteReport">;
payload: DeleteReportPayload;
}
}

export interface StateReport extends Report<"Alexa", "StateReport"> { }

export interface ChangeReport extends Report<"Alexa", "ChangeReport", ChangePayload> { }

export interface Response {
event: Event<"Alexa", "Response">;
context?: Context;
}

export interface DeferredResponse {
event: Event<"Alexa", "DeferredResponse", DeferredPayload>;
}

export interface ErrorResponse {
event: Event<"Alexa", "ErrorResponse", ErrorPayload>;
}

/*
DEVICE EVENTS
*/

export interface WebRTCAnswerGeneratedForSessionEvent extends Report<"Alexa.RTCSessionController", "AnswerGeneratedForSession", WebRTCAnswerGeneratedForSessionPayload> { }

export interface WebRTCSessionConnectedEvent extends Report<"Alexa.RTCSessionController", "SessionConnected", WebRTCSessionPayload> { }

export interface WebRTCSessionDisconnectedEvent extends Report<"Alexa.RTCSessionController", "SessionDisconnected", WebRTCSessionPayload> { }

export interface ObjectDetectionEvent extends Report<"Alexa.SmartVision.ObjectDetectionSensor", "ObjectDetection", ObjectDetectionPayload> { }

export interface DoorbellPressEvent extends Report<"Alexa.DoorbellEventSource", "DoorbellPress", DoorbellPressPayload> { }

/*
IMPLIMENTATION TYPES
*/


export interface Header<NS = string, N = string> {
namespace: NS;
name: N;
messageId: string;
correlationToken?: string;
payloadVersion: string;
}

export interface Scope {
type: string;
token: string;
partition?: string;
userId?: string;
}

export interface Endpoint {
endpointId: string;
scope?: Scope;
cookie?: any;
}

export interface Payload { }

export interface Directive<NS = string, N = string, P = Payload> {
header: Header<NS, N>;
endpoint: Endpoint;
payload: P;
}

export interface Event<NS = string, N = string, P = Payload> {
header: Header<NS, N>;
endpoint: Endpoint;
payload: P;
}

export interface Property {
namespace: string;
instance?: string;
name: string;
value: any;
timeOfSample: string;
uncertaintyInMilliseconds?: number;
}

export interface Context {
properties: Property[];
}

export interface Report<NS = string, N = string, P = Payload> {
event: Event<NS, N, P>;
context: Context;
}

export interface DeferredPayload {
estimatedDeferralInSeconds: number;
}

export interface ErrorPayload {
type: string;
message: string;
}

export interface ChangePayload {
change: {
cause: {
type: "APP_INTERACTION" | "PERIODIC_POLL" | "PHYSICAL_INTERACTION" | "VOICE_INTERACTION" | "RULE_TRIGGER";
},
properties: Property[];
}
}

export interface WebRTCSessionPayload {
sessionId: string;
}

export interface WebRTCAnswerGeneratedForSessionPayload {
answer: {
format: string;
value: string;
}
}

export interface ObjectDetectionPayloadEvent {
eventIdenifier: string;
imageNetClass: string;
timeOfSample: string;
uncertaintyInMilliseconds: number;
objectIdentifier: string;
frameImageUri: string;
croppedImageUri: string;
}

export interface ObjectDetectionPayload {
events: ObjectDetectionPayloadEvent[]
}


export interface DoorbellPressPayload {
cause: {
type: "APP_INTERACTION" | "PERIODIC_POLL" | "PHYSICAL_INTERACTION" | "VOICE_INTERACTION";
},
timestamp: string;
}

export interface DiscoveryProperty {
supported: any[];
proactivelyReported: boolean;
retrievable: boolean;
}

export interface DiscoveryCapability {
type: string;
interface: string;
instance?: string;
version: string;
properties?: DiscoveryProperty;
capabilityResources?: any;
configuration?: any;
semantics?: any;
}

export interface DiscoveryEndpoint {
endpointId: string;
manufacturerName: string;
description: string;
friendlyName: string;
displayCategories: DisplayCategory[];
additionalAttributes?: {
"manufacturer"?: string;
"model"?: string;
"serialNumber"?: string;
"firmwareVersion"? : string;
"softwareVersion"?: string;
"customIdentifier"?: string;
};
capabilities?: DiscoveryCapability[];
connections?: any[];
relationships?: any;
cookie?: any;
}

export interface DiscoverPayload {
endpoints: DiscoveryEndpoint[]
}

export interface Discovery {
event: {
header: Header<"Alexa.Discovery", "Discover.Response">;
payload: DiscoverPayload;
}
}

export interface AddOrUpdateReportPayload {
endpoints: DiscoveryEndpoint[]
scope: Scope;
}

export interface DeleteReportEndpoint {
endpointId: string;
}

export interface DeleteReportPayload {
endpoints: DeleteReportEndpoint[]
scope: Scope;
}
Loading