@apocaliss92/scrypted-reolink-native 0.5.6 → 0.5.7

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.5.6",
3
+ "version": "0.5.7",
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",
@@ -13,7 +13,8 @@
13
13
  "scrypted-setup-project": "scrypted-setup-project",
14
14
  "prescrypted-setup-project": "scrypted-package-json",
15
15
  "build": "scrypted-webpack",
16
- "prepublishOnly": "NODE_ENV=production scrypted-webpack",
16
+ "prepublish-patch": "./prepublish-patch.sh",
17
+ "prepublishOnly": "./prepublish-patch.sh && NODE_ENV=production scrypted-webpack",
17
18
  "prescrypted-vscode-launch": "scrypted-webpack",
18
19
  "scrypted-vscode-launch": "scrypted-deploy-debug",
19
20
  "scrypted-deploy-debug": "scrypted-deploy-debug",
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+ #
3
+ # Prepublish: build linked library, reinstall, bump plugin patch version.
4
+ # Runs automatically before npm publish via prepublishOnly.
5
+ #
6
+
7
+ set -e
8
+
9
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10
+ LIB_DIR="${SCRIPT_DIR}/../reolink-baichuan-js"
11
+
12
+ # ── Step 1: Build the library ───────────────────────────────────
13
+ echo "Building reolink-baichuan-js..."
14
+ cd "${LIB_DIR}"
15
+ npm run build
16
+ echo "Library built."
17
+
18
+ # ── Step 2: Reinstall in plugin (picks up fresh dist/) ──────────
19
+ echo "Installing dependencies..."
20
+ cd "${SCRIPT_DIR}"
21
+ npm install
22
+ echo "Dependencies installed."
23
+
24
+ # ── Step 3: Bump plugin patch version ───────────────────────────
25
+ echo "Bumping plugin patch version..."
26
+ npm version patch --no-git-tag-version
27
+ NEW_VERSION=$(node -p "require('./package.json').version")
28
+ echo "Plugin version: ${NEW_VERSION}"
package/src/camera.ts CHANGED
@@ -1989,6 +1989,14 @@ export class ReolinkCamera
1989
1989
  });
1990
1990
  return;
1991
1991
 
1992
+ case "battery":
1993
+ if (ev.battery) {
1994
+ this.updateBatteryInfo(ev.battery as any).catch((e) => {
1995
+ logger.debug("Error updating battery from push", e?.message || String(e));
1996
+ });
1997
+ }
1998
+ return;
1999
+
1992
2000
  case "offline":
1993
2001
  case "online":
1994
2002
  this.updateOnlineState(ev.type === "online").catch((e) => {
@@ -3279,7 +3287,6 @@ export class ReolinkCamera
3279
3287
  );
3280
3288
  }
3281
3289
 
3282
- logger.log(`Refreshed device capabilities`);
3283
3290
  logger.log(
3284
3291
  `Refreshed device capabilities: ${JSON.stringify({ capabilities, abilities, support, presets, objects })}`,
3285
3292
  );
@@ -3530,6 +3537,7 @@ export class ReolinkCamera
3530
3537
  }
3531
3538
 
3532
3539
  if (wasSleeping) {
3540
+ this.updateBatteryInfo().catch(() => {});
3533
3541
  this.alignAuxDevicesState().catch(() => {});
3534
3542
  if (this.forceNewSnapshot) {
3535
3543
  this.takePicture().catch(() => {});
@@ -3611,42 +3619,26 @@ export class ReolinkCamera
3611
3619
  if (batteryInfo.batteryPercent !== undefined) {
3612
3620
  const oldLevel = this.batteryLevel;
3613
3621
  const oldChargeState = this.chargeState;
3614
- // adapterStatus: "adapter" | "solarPanel" | "none" sotto carica se adapter collegato (anche con chargeComplete)
3615
- const isSottoCarica =
3622
+ // adapterStatus: "adapter" | "solarPanel" = charging, "none" = not charging
3623
+ const isCharging =
3616
3624
  batteryInfo.adapterStatus === "adapter" ||
3617
3625
  batteryInfo.adapterStatus === "solarPanel";
3618
- const newChargeState =
3619
- batteryInfo.adapterStatus !== undefined
3620
- ? isSottoCarica
3621
- ? ChargeState.Charging
3622
- : ChargeState.NotCharging
3623
- : undefined;
3626
+ const newChargeState = isCharging
3627
+ ? ChargeState.Charging
3628
+ : ChargeState.NotCharging;
3624
3629
 
3625
3630
  this.batteryLevel = batteryInfo.batteryPercent;
3626
- if (newChargeState !== undefined) {
3627
- this.chargeState = newChargeState;
3628
- }
3631
+ this.chargeState = newChargeState;
3629
3632
 
3630
3633
  // Log only if battery level changed
3631
3634
  if (oldLevel !== batteryInfo.batteryPercent) {
3632
- if (batteryInfo.adapterStatus !== undefined) {
3633
- logger.log(
3634
- `Battery level changed: ${oldLevel}% → ${batteryInfo.batteryPercent}% (sotto carica: ${isSottoCarica}, adapterStatus: ${batteryInfo.adapterStatus}, chargeStatus: ${batteryInfo.chargeStatus ?? "—"})`,
3635
- );
3636
- } else {
3637
- logger.log(
3638
- `Battery level changed: ${oldLevel}% → ${batteryInfo.batteryPercent}%`,
3639
- );
3640
- }
3635
+ logger.log(
3636
+ `Battery level changed: ${oldLevel}% → ${batteryInfo.batteryPercent}% (charging: ${isCharging}, adapter: ${batteryInfo.adapterStatus ?? "unknown"}, status: ${batteryInfo.chargeStatus ?? "unknown"})`,
3637
+ );
3641
3638
  } else if (oldLevel === undefined) {
3642
- // First time setting battery level
3643
- if (batteryInfo.adapterStatus !== undefined) {
3644
- logger.log(
3645
- `Battery level set: ${batteryInfo.batteryPercent}% (sotto carica: ${isSottoCarica}, adapterStatus: ${batteryInfo.adapterStatus})`,
3646
- );
3647
- } else {
3648
- logger.log(`Battery level set: ${batteryInfo.batteryPercent}%`);
3649
- }
3639
+ logger.log(
3640
+ `Battery level set: ${batteryInfo.batteryPercent}% (charging: ${isCharging}, adapter: ${batteryInfo.adapterStatus ?? "unknown"})`,
3641
+ );
3650
3642
  }
3651
3643
 
3652
3644
  // Forward battery/charge state changes to Scrypted (plugin, HomeKit, etc.)
@@ -3694,49 +3686,16 @@ export class ReolinkCamera
3694
3686
  return;
3695
3687
  }
3696
3688
 
3697
- // Check current sleep status
3698
- let sleepStatus = api.getSleepStatus({ channel });
3689
+ // Check current sleep status — only update if already awake
3690
+ const sleepStatus = api.getSleepStatus({ channel });
3699
3691
 
3700
- // If camera is sleeping, wake it up
3701
3692
  if (sleepStatus.state === "sleeping") {
3702
- logger.log("Camera is sleeping, waking up for periodic update...");
3703
- try {
3704
- await api.wakeUp(channel, { waitAfterWakeMs: 2000 });
3705
- logger.log("Wake command sent, waiting for camera to wake up...");
3706
- } catch (wakeError) {
3707
- logger.error(
3708
- "Failed to wake up camera:",
3709
- wakeError?.message || String(wakeError),
3710
- );
3711
- return;
3712
- }
3713
-
3714
- // Poll until camera is awake (with timeout)
3715
- const wakeTimeoutMs = 30000; // 30 seconds max
3716
- const startWakePoll = Date.now();
3717
- let awake = false;
3718
-
3719
- while (Date.now() - startWakePoll < wakeTimeoutMs) {
3720
- await new Promise((resolve) => setTimeout(resolve, 1000)); // Check every second
3721
- sleepStatus = api.getSleepStatus({ channel });
3722
- if (sleepStatus.state === "awake") {
3723
- awake = true;
3724
- logger.log("Camera is now awake");
3725
- this.sleeping = false;
3726
- break;
3727
- }
3728
- }
3729
-
3730
- if (!awake) {
3731
- logger.error(
3732
- "Camera did not wake up within timeout, skipping update",
3733
- );
3734
- return;
3735
- }
3736
- } else if (sleepStatus.state === "awake") {
3737
- this.sleeping = false;
3693
+ logger.debug("Camera is sleeping, skipping periodic battery update");
3694
+ return;
3738
3695
  }
3739
3696
 
3697
+ this.sleeping = false;
3698
+
3740
3699
  // Now that camera is awake, update all states
3741
3700
  // 1. Update battery info
3742
3701
  try {