Skip to content

Commit

Permalink
feat: model name for cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreif committed Jun 24, 2019
1 parent e2278c7 commit 2b9f397
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 14 deletions.
2 changes: 2 additions & 0 deletions api/ring-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CameraData,
CameraHealth,
HistoricalDingGlobal,
RingCameraModel,
SnapshotTimestamp
} from './ring-types'
import { clientApi, RingRestClient } from './rest-client'
Expand All @@ -23,6 +24,7 @@ const maxSnapshotRefreshAttempts = 60,
export class RingCamera {
id = this.initialData.id
deviceType = this.initialData.kind
model = RingCameraModel[this.initialData.kind] || 'Unknown Model'
hasLight = this.initialData.led_status !== undefined
hasSiren = this.initialData.siren_status !== undefined

Expand Down
48 changes: 43 additions & 5 deletions api/ring-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,48 @@ export enum RingDeviceType {
BeamsTransformerSwitch = 'switch.transformer.beams'
}

// TODO: get all camera kinds
export enum RingCameraKind {
DoorbellPro = 'lpd_v2',
Floodlight = 'hp_cam_v1'
doorbot = 'doorbot',
doorbell = 'doorbell',
doorbell_v3 = 'doorbell_v3',
doorbell_v4 = 'doorbell_v4',
doorbell_v5 = 'doorbell_v5',
doorbell_portal = 'doorbell_portal',
lpd_v1 = 'lpd_v1',
lpd_v2 = 'lpd_v2',
jbox_v1 = 'jbox_v1',
stickup_cam = 'stickup_cam',
stickup_cam_v3 = 'stickup_cam_v3',
stickup_cam_elite = 'stickup_cam_elite',
stickup_cam_lunar = 'stickup_cam_lunar',
spotlightw_v2 = 'spotlightw_v2',
hp_cam_v1 = 'hp_cam_v1',
hp_cam_v2 = 'hp_cam_v2',
stickup_cam_v4 = 'stickup_cam_v4',
floodlight_v1 = 'floodlight_v1',
floodlight_v2 = 'floodlight_v2'
}

export const RingCameraModel: { readonly [P in RingCameraKind]: string } = {
doorbot: 'Doorbell',
doorbell: 'Doorbell',
doorbell_v3: 'Doorbell',
doorbell_v4: 'Doorbell 2',
doorbell_v5: 'Doorbell 2',
doorbell_portal: 'Door View Cam',
lpd_v1: 'Doorbell Pro',
lpd_v2: 'Doorbell Pro',
jbox_v1: 'Doorbell Elite',
stickup_cam: 'Stick Up Cam',
stickup_cam_v3: 'Stick Up Cam',
stickup_cam_elite: 'Stick Up Cam',
stickup_cam_lunar: 'Stick Up Cam',
spotlightw_v2: 'Spotlight Cam',
hp_cam_v1: 'Floodlight Cam',
hp_cam_v2: 'Spotlight Cam',
stickup_cam_v4: 'Spotlight Cam',
floodlight_v1: 'Floodlight Cam',
floodlight_v2: 'Floodlight Cam'
}

export type AlarmMode = 'all' | 'some' | 'none'
Expand Down Expand Up @@ -190,7 +228,7 @@ export interface CameraData {
battery_life: number | string // 4003 or "100"
external_connection: boolean
firmware_version: Firmware
kind: RingCameraKind | string
kind: RingCameraKind
latitude: number
longitude: number
address: string
Expand Down Expand Up @@ -338,7 +376,7 @@ export interface ActiveDing {
protocol: 'sip'
doorbot_id: number
doorbot_description: string
device_kind: RingCameraKind | string
device_kind: RingCameraKind
motion: boolean
snapshot_url: ''
kind: DingKind
Expand Down
4 changes: 4 additions & 0 deletions homebridge/base-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export abstract class BaseAccessory<T extends RingDevice | RingCamera> {
abstract readonly config: RingAlarmPlatformConfig

getService(serviceType: HAP.Service, name = this.device.name) {
if (process.env.RING_DEBUG) {
name = 'TEST ' + name
}

return (
this.accessory.getService(serviceType) ||
this.accessory.addService(serviceType, name)
Expand Down
4 changes: 2 additions & 2 deletions homebridge/base-device-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export abstract class BaseDeviceAccessory extends BaseAccessory<RingDevice> {
this.registerCharacteristic(
Characteristic.Manufacturer,
Service.AccessoryInformation,
data => data.manufacturerName || 'ring'
data => data.manufacturerName || 'Ring'
)
this.registerCharacteristic(
Characteristic.Model,
Expand All @@ -78,7 +78,7 @@ export abstract class BaseDeviceAccessory extends BaseAccessory<RingDevice> {
this.registerCharacteristic(
Characteristic.SerialNumber,
Service.AccessoryInformation,
data => data.serialNumber || 'unknown'
data => data.serialNumber || 'Unknown'
)

if ('volume' in initialData && 'setVolume' in device) {
Expand Down
4 changes: 2 additions & 2 deletions homebridge/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export class Camera extends BaseAccessory<RingCamera> {
this.registerCharacteristic(
Characteristic.Manufacturer,
Service.AccessoryInformation,
() => 'ring'
() => 'Ring'
)
this.registerCharacteristic(
Characteristic.Model,
Service.AccessoryInformation,
data => data.kind
data => `${device.model} (${data.kind})`
)
this.registerCharacteristic(
Characteristic.SerialNumber,
Expand Down
15 changes: 10 additions & 5 deletions homebridge/ring-alarm-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { MultiLevelSwitch } from './multi-level-switch'
import { Camera } from './camera'

const pluginName = 'homebridge-ring-alarm',
platformName = 'RingAlarm'
platformName = 'RingAlarm',
debug = false

process.env.RING_DEBUG = debug ? 'true' : ''

function getAccessoryClass(device: RingDevice | RingCamera) {
const { deviceType } = device
Expand Down Expand Up @@ -109,9 +112,10 @@ export class RingAlarmPlatform {
allDevices.forEach(device => {
const isCamera = device instanceof RingCamera,
AccessoryClass = isCamera ? Camera : getAccessoryClass(device),
id = device.id,
debugPrefix = debug ? 'TEST ' : '',
cameraIdDifferentiator = isCamera ? 'camera' : '', // this forces bridged cameras from old version of the plugin to be seen as "stale"
uuid = hap.UUIDGen.generate(id.toString() + cameraIdDifferentiator)
id = debugPrefix + device.id.toString() + cameraIdDifferentiator,
uuid = hap.UUIDGen.generate(id)

if (
!AccessoryClass ||
Expand All @@ -123,15 +127,16 @@ export class RingAlarmPlatform {

const createHomebridgeAccessory = () => {
const accessory = new hap.PlatformAccessory(
device.name,
debugPrefix + device.name,
uuid,
isCamera
? hap.AccessoryCategories.CAMERA
: hap.AccessoryCategories.SECURITY_SYSTEM
)

this.log.info(
`Adding new accessory ${device.deviceType} ${device.name}`
`Adding new accessory ${device.deviceType} ${debugPrefix +
device.name}`
)

if (isCamera) {
Expand Down

0 comments on commit 2b9f397

Please sign in to comment.