Skip to content

Commit

Permalink
fix(homebridge): correct charging and battery level for base station
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreif committed Jul 15, 2019
1 parent 32b8b36 commit e7beb8b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
20 changes: 10 additions & 10 deletions api/location.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { connect as connectSocketIo } from 'socket.io-client'
import { BehaviorSubject, Subject } from 'rxjs'
import {
filter,
take,
map,
concatMap,
distinctUntilChanged,
filter,
map,
publishReplay,
refCount,
scan,
refCount
take
} from 'rxjs/operators'
import { delay, logError, logInfo } from './util'
import {
AlarmMode,
RingDeviceData,
AssetSession,
deviceTypesWithVolume,
LocationEvent,
MessageDataType,
MessageType,
RingDeviceData,
RingDeviceType,
SocketIoMessage,
MessageType,
UserLocation,
TicketAsset,
MessageDataType,
AssetSession,
LocationEvent
UserLocation
} from './ring-types'
import { clientApi, RingRestClient } from './rest-client'
import { RingCamera } from './ring-camera'
Expand Down
5 changes: 3 additions & 2 deletions api/ring-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ export interface RingDeviceData {
name: string
deviceType: RingDeviceType
batteryLevel?: number
batteryStatus: 'full' | 'ok' | 'low' | 'none' | 'charging'
batteryBackup?: 'charged' | 'charging'
batteryStatus: 'full' | 'charged' | 'ok' | 'low' | 'none' | 'charging'
batteryBackup?: 'charged' | 'charging' | 'inUse'
acStatus?: 'error' | 'ok'
manufacturerName?: string
serialNumber?: string
tamperStatus: 'ok' | 'tamper'
Expand Down
16 changes: 10 additions & 6 deletions homebridge/base-device-accessory.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { RingDevice, RingDeviceData } from '../api'
import { HAP, hap } from './hap'
import Service = HAP.Service
import { debounceTime, distinctUntilChanged, map } from 'rxjs/operators'
import { Subject } from 'rxjs'
import { RingPlatformConfig } from './config'
import { BaseAccessory } from './base-accessory'

function getBatteryLevel({ batteryLevel, batteryStatus }: RingDeviceData) {
if (batteryLevel !== undefined) {
return batteryLevel
} else if (batteryStatus === 'full') {
} else if (batteryStatus === 'full' || batteryStatus === 'charged') {
return 100
} else if (batteryStatus === 'ok') {
return 50
Expand All @@ -28,18 +25,25 @@ function getStatusLowBattery(data: RingDeviceData) {

function getBatteryChargingState({
batteryStatus,
batteryBackup
batteryBackup,
acStatus
}: RingDeviceData) {
const { ChargingState } = hap.Characteristic

if (
batteryStatus === 'charging' ||
batteryStatus === 'charged' ||
batteryBackup === 'charged' ||
batteryBackup === 'charging'
batteryBackup === 'charging' ||
acStatus === 'ok'
) {
return ChargingState.CHARGING
}

if (batteryBackup === 'inUse' || acStatus === 'error') {
return ChargingState.NOT_CHARGING
}

return ChargingState.NOT_CHARGEABLE
}

Expand Down

0 comments on commit e7beb8b

Please sign in to comment.