@apocaliss92/scrypted-reolink-native 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.zip CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apocaliss92/scrypted-reolink-native",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Use any reolink camera with Scrypted, even older/unsupported models without HTTP protocol support",
5
5
  "author": "@apocaliss92",
6
6
  "license": "Apache",
package/src/common.ts CHANGED
@@ -6,19 +6,18 @@ import { createBaichuanApi, normalizeUid, type BaichuanTransport } from "./conne
6
6
  import { convertDebugLogsToApiOptions, DebugLogOption, getApiRelevantDebugLogs, getDebugLogChoices } from "./debug-options";
7
7
  import { ReolinkBaichuanIntercom } from "./intercom";
8
8
  import ReolinkNativePlugin from "./main";
9
+ import { ReolinkNativeNvrDevice } from "./nvr";
9
10
  import { ReolinkPtzPresets } from "./presets";
10
11
  import {
11
12
  buildVideoStreamOptionsFromRtspRtmp,
12
13
  createRfc4571MediaObjectFromStreamManager,
13
14
  expectedVideoTypeFromUrlMediaStreamOptions,
14
- fetchVideoStreamOptionsFromApi,
15
15
  isNativeStreamId,
16
16
  parseStreamProfileFromId,
17
17
  selectStreamOption,
18
- StreamManager,
18
+ StreamManager
19
19
  } from "./stream-utils";
20
- import { getDeviceInterfaces } from "./utils";
21
- import { ReolinkNativeNvrDevice } from "./nvr";
20
+ import { getDeviceInterfaces, updateDeviceInfo } from "./utils";
22
21
 
23
22
  export type CameraType = 'battery' | 'regular';
24
23
 
@@ -989,29 +988,18 @@ export abstract class CommonCameraMixin extends ScryptedDeviceBase implements Vi
989
988
  }
990
989
  }
991
990
 
992
- // Device info update
993
991
  async updateDeviceInfo(): Promise<void> {
994
- const ip = this.storageSettings.values.ipAddress;
992
+ const { ipAddress, rtspChannel } = this.storageSettings.values;
995
993
  try {
996
994
  const api = await this.ensureClient();
997
- const deviceData = await api.getInfo(this.storageSettings.values.rtspChannel);
998
- const info = this.info || {};
999
- info.ip = ip;
1000
-
1001
- info.serialNumber = deviceData?.serialNumber || deviceData?.itemNo;
1002
- info.firmware = deviceData?.firmwareVersion || deviceData?.firmVer;
1003
- info.version = deviceData?.hardwareVersion || deviceData?.boardInfo;
1004
- info.model = deviceData?.type || deviceData?.typeInfo;
1005
- info.manufacturer = 'Reolink';
1006
- info.managementUrl = `http://${ip}`;
1007
- this.info = info;
995
+ const deviceData = await api.getInfo(this.nvrDevice ? rtspChannel : undefined);
996
+
997
+ await updateDeviceInfo({
998
+ device: this,
999
+ ipAddress,
1000
+ deviceData,
1001
+ });
1008
1002
  } catch (e) {
1009
- // If API call fails, at least set basic info
1010
- const info = this.info || {};
1011
- info.ip = ip;
1012
- info.manufacturer = 'Reolink native';
1013
- info.managementUrl = `http://${ip}`;
1014
- this.info = info;
1015
1003
  this.getLogger().warn('Failed to fetch device info', e);
1016
1004
  }
1017
1005
  }
package/src/main.ts CHANGED
@@ -76,7 +76,6 @@ class ReolinkNativePlugin extends ScryptedDeviceBase implements DeviceProvider,
76
76
  device.storageSettings.values.ipAddress = ipAddress;
77
77
  device.storageSettings.values.username = username;
78
78
  device.storageSettings.values.password = password;
79
- device.updateDeviceInfo(deviceInfo);
80
79
 
81
80
  return nativeId;
82
81
  }
@@ -144,7 +143,6 @@ class ReolinkNativePlugin extends ScryptedDeviceBase implements DeviceProvider,
144
143
  device.storageSettings.values.ipAddress = ipAddress;
145
144
  device.storageSettings.values.capabilities = capabilities;
146
145
  device.storageSettings.values.uid = detection.uid;
147
- device.updateDeviceInfo();
148
146
 
149
147
  return nativeId;
150
148
  }
package/src/nvr.ts CHANGED
@@ -5,7 +5,7 @@ import { ReolinkNativeCamera } from "./camera";
5
5
  import { ReolinkNativeBatteryCamera } from "./camera-battery";
6
6
  import { normalizeUid } from "./connect";
7
7
  import ReolinkNativePlugin from "./main";
8
- import { getDeviceInterfaces } from "./utils";
8
+ import { getDeviceInterfaces, updateDeviceInfo } from "./utils";
9
9
 
10
10
  export class ReolinkNativeNvrDevice extends ScryptedDeviceBase implements Settings, DeviceDiscovery, DeviceProvider, Reboot {
11
11
  storageSettings = new StorageSettings(this, {
@@ -99,6 +99,7 @@ export class ReolinkNativeNvrDevice extends ScryptedDeviceBase implements Settin
99
99
  async init() {
100
100
  const api = await this.ensureClient();
101
101
  const logger = this.getLogger();
102
+ await this.updateDeviceInfo();
102
103
 
103
104
  setInterval(async () => {
104
105
  if (this.processing || !api) {
@@ -169,16 +170,20 @@ export class ReolinkNativeNvrDevice extends ScryptedDeviceBase implements Settin
169
170
  }, 1000);
170
171
  }
171
172
 
172
- updateDeviceInfo(deviceInfo: Record<string, string>) {
173
- const info = this.info || {};
174
- info.ip = this.storageSettings.values.ipAddress;
175
- info.serialNumber = deviceInfo?.serialNumber || deviceInfo?.itemNo;
176
- info.firmware = deviceInfo?.firmwareVersion || deviceInfo?.firmVer;
177
- info.version = deviceInfo?.hardwareVersion || deviceInfo?.boardInfo;
178
- info.model = deviceInfo?.type || deviceInfo?.typeInfo;
179
- info.manufacturer = 'Reolink native';
180
- info.managementUrl = `http://${info.ip}`;
181
- this.info = info;
173
+ async updateDeviceInfo(): Promise<void> {
174
+ const { ipAddress } = this.storageSettings.values;
175
+ try {
176
+ const api = await this.ensureClient();
177
+ const deviceData = await api.getInfo();
178
+
179
+ await updateDeviceInfo({
180
+ device: this,
181
+ ipAddress,
182
+ deviceData,
183
+ });
184
+ } catch (e) {
185
+ this.getLogger().warn('Failed to fetch device info', e);
186
+ }
182
187
  }
183
188
 
184
189
  async getSettings(): Promise<Setting[]> {
@@ -355,8 +360,6 @@ export class ReolinkNativeNvrDevice extends ScryptedDeviceBase implements Settin
355
360
  device.storageSettings.values.uid = entry.deviceData.channelStatus.uid;
356
361
  device.storageSettings.values.isFromNvr = true;
357
362
 
358
- device.updateDeviceInfo();
359
-
360
363
  this.discoveredDevices.delete(adopt.nativeId);
361
364
  return device?.id;
362
365
  }
package/src/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { DeviceCapabilities } from "@apocaliss92/reolink-baichuan-js" with { "resolution-mode": "import" };
2
- import { ScryptedDeviceType, ScryptedInterface } from "@scrypted/sdk";
1
+ import type { DeviceCapabilities, ReolinkDeviceInfo } from "@apocaliss92/reolink-baichuan-js" with { "resolution-mode": "import" };
2
+ import { DeviceBase, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface } from "@scrypted/sdk";
3
3
 
4
4
  export const getDeviceInterfaces = (props: {
5
5
  capabilities: DeviceCapabilities,
@@ -49,4 +49,33 @@ export const getDeviceInterfaces = (props: {
49
49
  }
50
50
 
51
51
  return { interfaces, type: capabilities.isDoorbell ? ScryptedDeviceType.Doorbell : ScryptedDeviceType.Camera };
52
+ }
53
+
54
+ export const updateDeviceInfo = async (props: {
55
+ device: DeviceBase,
56
+ ipAddress: string,
57
+ deviceData: ReolinkDeviceInfo
58
+ }) => {
59
+ const { device, ipAddress, deviceData } = props;
60
+ try {
61
+ const info = device.info || {};
62
+
63
+ info.ip = ipAddress;
64
+ info.serialNumber = deviceData?.serialNumber || deviceData?.itemNo;
65
+ info.firmware = deviceData?.firmwareVersion;
66
+ info.version = deviceData?.hardwareVersion;
67
+ info.model = deviceData?.type;
68
+ info.manufacturer = 'Reolink';
69
+ info.managementUrl = `http://${ipAddress}`;
70
+ device.info = info;
71
+ } catch (e) {
72
+ // If API call fails, at least set basic info
73
+ const info = device.info || {};
74
+ info.ip = ipAddress;
75
+ info.manufacturer = 'Reolink native';
76
+ info.managementUrl = `http://${ipAddress}`;
77
+ device.info = info;
78
+
79
+ throw e;
80
+ }
52
81
  }