Skip to content

Commit e7beb8b

Browse files
committed
fix(homebridge): correct charging and battery level for base station
#65
1 parent 32b8b36 commit e7beb8b

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

api/location.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import { connect as connectSocketIo } from 'socket.io-client'
22
import { BehaviorSubject, Subject } from 'rxjs'
33
import {
4-
filter,
5-
take,
6-
map,
74
concatMap,
85
distinctUntilChanged,
6+
filter,
7+
map,
98
publishReplay,
9+
refCount,
1010
scan,
11-
refCount
11+
take
1212
} from 'rxjs/operators'
1313
import { delay, logError, logInfo } from './util'
1414
import {
1515
AlarmMode,
16-
RingDeviceData,
16+
AssetSession,
1717
deviceTypesWithVolume,
18+
LocationEvent,
19+
MessageDataType,
20+
MessageType,
21+
RingDeviceData,
1822
RingDeviceType,
1923
SocketIoMessage,
20-
MessageType,
21-
UserLocation,
2224
TicketAsset,
23-
MessageDataType,
24-
AssetSession,
25-
LocationEvent
25+
UserLocation
2626
} from './ring-types'
2727
import { clientApi, RingRestClient } from './rest-client'
2828
import { RingCamera } from './ring-camera'

api/ring-types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ export interface RingDeviceData {
122122
name: string
123123
deviceType: RingDeviceType
124124
batteryLevel?: number
125-
batteryStatus: 'full' | 'ok' | 'low' | 'none' | 'charging'
126-
batteryBackup?: 'charged' | 'charging'
125+
batteryStatus: 'full' | 'charged' | 'ok' | 'low' | 'none' | 'charging'
126+
batteryBackup?: 'charged' | 'charging' | 'inUse'
127+
acStatus?: 'error' | 'ok'
127128
manufacturerName?: string
128129
serialNumber?: string
129130
tamperStatus: 'ok' | 'tamper'

homebridge/base-device-accessory.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { RingDevice, RingDeviceData } from '../api'
22
import { HAP, hap } from './hap'
3-
import Service = HAP.Service
4-
import { debounceTime, distinctUntilChanged, map } from 'rxjs/operators'
5-
import { Subject } from 'rxjs'
63
import { RingPlatformConfig } from './config'
74
import { BaseAccessory } from './base-accessory'
85

96
function getBatteryLevel({ batteryLevel, batteryStatus }: RingDeviceData) {
107
if (batteryLevel !== undefined) {
118
return batteryLevel
12-
} else if (batteryStatus === 'full') {
9+
} else if (batteryStatus === 'full' || batteryStatus === 'charged') {
1310
return 100
1411
} else if (batteryStatus === 'ok') {
1512
return 50
@@ -28,18 +25,25 @@ function getStatusLowBattery(data: RingDeviceData) {
2825

2926
function getBatteryChargingState({
3027
batteryStatus,
31-
batteryBackup
28+
batteryBackup,
29+
acStatus
3230
}: RingDeviceData) {
3331
const { ChargingState } = hap.Characteristic
3432

3533
if (
3634
batteryStatus === 'charging' ||
35+
batteryStatus === 'charged' ||
3736
batteryBackup === 'charged' ||
38-
batteryBackup === 'charging'
37+
batteryBackup === 'charging' ||
38+
acStatus === 'ok'
3939
) {
4040
return ChargingState.CHARGING
4141
}
4242

43+
if (batteryBackup === 'inUse' || acStatus === 'error') {
44+
return ChargingState.NOT_CHARGING
45+
}
46+
4347
return ChargingState.NOT_CHARGEABLE
4448
}
4549

0 commit comments

Comments
 (0)