Skip to content

Commit

Permalink
Merge branch 'main' of github.com:koush/scrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Oct 20, 2024
2 parents 63b7616 + 2905969 commit 3f4409e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
5 changes: 2 additions & 3 deletions plugins/alexa/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/alexa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/alexa",
"version": "0.3.3",
"version": "0.3.4",
"scripts": {
"scrypted-setup-project": "scrypted-setup-project",
"prescrypted-setup-project": "scrypted-package-json",
Expand Down
13 changes: 12 additions & 1 deletion plugins/alexa/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class AlexaPlugin extends ScryptedDeviceBase implements HttpRequestHandler, Mixi
title: "Pairing Key",
description: "The pairing key used to validate requests from Alexa. Clear this key or delete the plugin to allow pairing with a different Alexa login.",
},
disableAutoAdd: {
title: "Disable auto add",
description: "Disable automatic enablement of devices.",
type: 'boolean',
defaultValue: false,
},
});

accessToken: Promise<string>;
Expand Down Expand Up @@ -116,6 +122,10 @@ class AlexaPlugin extends ScryptedDeviceBase implements HttpRequestHandler, Mixi
if (!supportedTypes.has(device.type))
return DeviceMixinStatus.NotSupported;

if (this.storageSettings.values.disableAutoAdd) {
return DeviceMixinStatus.Skip;
}

mixins.push(this.id);

const plugins = await systemManager.getComponent('plugins');
Expand Down Expand Up @@ -671,7 +681,8 @@ class AlexaPlugin extends ScryptedDeviceBase implements HttpRequestHandler, Mixi
enum DeviceMixinStatus {
NotSupported = 0,
Setup = 1,
AlreadySetup = 2
AlreadySetup = 2,
Skip = 3,
}

class HttpResponseLoggingImpl implements AlexaHttpResponse {
Expand Down
7 changes: 7 additions & 0 deletions plugins/reolink/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ReolinkCameraSiren extends ScryptedDeviceBase implements OnOff {

class ReolinkCamera extends RtspSmartCamera implements Camera, DeviceProvider, Reboot, Intercom, ObjectDetector, PanTiltZoom {
client: ReolinkCameraClient;
clientWithToken: ReolinkCameraClient;
onvifClient: OnvifCameraAPI;
onvifIntercom = new OnvifIntercom(this);
videoStreamOptions: Promise<UrlMediaStreamOptions[]>;
Expand Down Expand Up @@ -341,6 +342,12 @@ class ReolinkCamera extends RtspSmartCamera implements Camera, DeviceProvider, R
return this.client;
}

getClientWithToken() {
if (!this.clientWithToken)
this.clientWithToken = new ReolinkCameraClient(this.getHttpAddress(), this.getUsername(), this.getPassword(), this.getRtspChannel(), this.console, true);
return this.clientWithToken;
}

async getOnvifClient() {
if (!this.onvifClient)
this.onvifClient = await this.createOnvifClient();
Expand Down
28 changes: 15 additions & 13 deletions plugins/reolink/src/probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,27 @@ async function getDeviceInfo(host: string, username: string, password: string):
return response.body?.[0]?.value?.DevInfo;
}

export async function getLoginParameters(host: string, username: string, password: string) {
try {
await getDeviceInfo(host, username, password);
return {
parameters: {
user: username,
password,
},
leaseTimeSeconds: Infinity,
export async function getLoginParameters(host: string, username: string, password: string, forceToken?: boolean) {
if (!forceToken) {
try {
await getDeviceInfo(host, username, password);
return {
parameters: {
user: username,
password,
},
leaseTimeSeconds: Infinity,
}
}
catch (e) {
}
}
catch (e) {
}

try {
const url = new URL(`http://${host}/api.cgi`);
const params = url.searchParams;
params.set('cmd', 'Login');

const response = await httpFetch({
url,
method: 'POST',
Expand All @@ -83,7 +85,7 @@ export async function getLoginParameters(host: string, username: string, passwor
},
],
});

const token = response.body?.[0]?.value?.Token?.name || response.body?.value?.Token?.name;
if (!token)
throw new Error('unable to login');
Expand Down
4 changes: 2 additions & 2 deletions plugins/reolink/src/reolink-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ReolinkCameraClient {
parameters: Record<string, string>;
tokenLease: number;

constructor(public host: string, public username: string, public password: string, public channelId: number, public console: Console) {
constructor(public host: string, public username: string, public password: string, public channelId: number, public console: Console, public readonly forceToken?: boolean) {
this.credential = {
username,
password,
Expand Down Expand Up @@ -80,7 +80,7 @@ export class ReolinkCameraClient {

this.console.log(`token expired at ${this.tokenLease}, renewing...`);

const { parameters, leaseTimeSeconds } = await getLoginParameters(this.host, this.username, this.password);
const { parameters, leaseTimeSeconds } = await getLoginParameters(this.host, this.username, this.password, this.forceToken);
this.parameters = parameters
this.tokenLease = Date.now() + 1000 * leaseTimeSeconds;
}
Expand Down

0 comments on commit 3f4409e

Please sign in to comment.