Skip to content

fix: restore Battery service for water detector#1387

Merged
donavanbecker merged 2 commits into
OpenWonderLabs:latestfrom
joshjohanning:feat/water-detector-battery-service
Jul 1, 2026
Merged

fix: restore Battery service for water detector#1387
donavanbecker merged 2 commits into
OpenWonderLabs:latestfrom
joshjohanning:feat/water-detector-battery-service

Conversation

@joshjohanning

@joshjohanning joshjohanning commented May 27, 2026

Copy link
Copy Markdown
Contributor

♻️ Current situation

The v5.0.0 rewrite (#1357) replaced the dedicated per-device files with a single declarative genericDevice.ts. In that rewrite, only the primary service for each device was re-wired. The Water Detector's Battery service from v4 was dropped.

The SwitchBot Water Leak Detector reports battery via the OpenAPI 'battery' state field, so HomeKit low-battery alerts are useful and were expected behavior in v4.

💡 Proposed solution

  1. Restores BatteryLevel, StatusLowBattery (threshold <20%), and ChargingState (not chargeable) characteristics on the LeakSensor accessory.

  2. Also avoids Homebridge slow-read warnings for the Battery characteristics by caching the battery level and returning it synchronously from BatteryLevel / StatusLowBattery.

[26/05/2026, 18:22:51] [@switchbot/homebridge-switchbot] This plugin slows down Homebridge. The read handler for the characteristic 'Battery Level' was slow to respond! See https://homebridge.io/w/JtMGR for more info.
[26/05/2026, 18:22:51] [@switchbot/homebridge-switchbot] This plugin slows down Homebridge. The read handler for the characteristic 'Status Low Battery' was slow to respond! See https://homebridge.io/w/JtMGR for more info.

The cache is warmed from the SwitchBot OpenAPI status endpoint during device init and refreshed in the background, so HomeKit reads do not block on a live API call.

image

⚙️ Release Notes

fix(battery-regression): restore Battery service for leak sensor

➕ Additional Information

n/a

Testing

  • Added unit coverage for the WaterDetector Battery service descriptor
  • Verified BatteryLevel / StatusLowBattery read from the cached OpenAPI battery value
  • Verified missing battery does not fabricate a fake value
  • Manually tested on Homebridge v2.0.2: Fridge Water Detector reports 100% battery and no Battery slow-read warnings

Reviewer Nudging

review the battery fetching logic

The v5.0.0 rewrite (OpenWonderLabs#1357) replaced the dedicated per-device files with
a single declarative genericDevice.ts. In that rewrite, only the primary
service for each device was re-wired. The Water Detector's Battery
service from v4 was dropped.

The SwitchBot Water Leak Detector reports battery via the OpenAPI
'battery' state field, so HomeKit low-battery alerts are useful and were
expected behavior in v4.

Restores BatteryLevel, StatusLowBattery (threshold <20%), and
ChargingState (not chargeable) characteristics on the LeakSensor
accessory.
@joshjohanning joshjohanning changed the title feat: restore Battery service for water detector fix: restore Battery service for water detector May 27, 2026
@donavanbecker

Copy link
Copy Markdown
Contributor

need to resolve conflicts

…or-battery-service

# Conflicts:
#	src/devices/genericDevice.ts
@joshjohanning

Copy link
Copy Markdown
Contributor Author

@donavanbecker this is mergeable now! Thank you so much for merging #1386 🙇

@donavanbecker donavanbecker merged commit 1c5caaa into OpenWonderLabs:latest Jul 1, 2026
2 checks passed
@joshjohanning

Copy link
Copy Markdown
Contributor Author

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants