UNPKG

homebridge-nest-accfactory

Version:

Homebridge support for Nest/Google devices including HomeKit Secure Video (HKSV) support for doorbells and cameras

92 lines (76 loc) 3.17 kB
// Nest Cam with Floodlight // Part of homebridge-nest-accfactory // // Mark Hulskamp 'use strict'; // Define external module requirements import NestCamera from './camera.js'; export default class NestFloodlight extends NestCamera { static TYPE = 'FloodlightCamera'; static VERSION = '2025.06.11'; lightService = undefined; // HomeKit light constructor(accessory, api, log, eventEmitter, deviceData) { super(accessory, api, log, eventEmitter, deviceData); } // Class functions setupDevice() { // Call parent to setup the common camera things. Once we return, we can add in the specifics for our floodlight super.setupDevice(); if (this.deviceData.has_light === true) { // Add service to for a light, including brightness control this.lightService = this.addHKService(this.hap.Service.Lightbulb, '', 1); this.addHKCharacteristic(this.lightService, this.hap.Characteristic.Brightness, { props: { minStep: 10 }, // Light only goes in 10% increments onSet: (value) => { if (value !== this.deviceData.light_brightness) { this.set({ uuid: this.deviceData.nest_google_uuid, light_brightness: value }); this?.log?.info?.('Floodlight brightness on "%s" was set to "%s %"', this.deviceData.description, value); } }, onGet: () => { return this.deviceData.light_brightness; }, }); this.addHKCharacteristic(this.lightService, this.hap.Characteristic.On, { onSet: (value) => { if (value !== this.deviceData.light_enabled) { this.set({ uuid: this.deviceData.nest_google_uuid, light_enabled: value }); this?.log?.info?.('Floodlight on "%s" was turned', this.deviceData.description, value === true ? 'on' : 'off'); } }, onGet: () => { return this.deviceData.light_enabled === true; }, }); } if (this.deviceData.has_light !== true) { // No longer required to have the light service this.lightService = this.accessory.getService(this.hap.Service.Lightbulb); if (this.lightService !== undefined) { this.accessory.removeService(this.lightService); } this.lightService === undefined; } // Extra setup details for output this.lightService !== undefined && this.postSetupDetails('Light support'); } removeDevice() { super.removeDevice(); if (this.lightService !== undefined) { this.accessory.removeService(this.lightService); } this.lightService = undefined; } updateDevice(deviceData) { if (typeof deviceData !== 'object' || this.controller === undefined) { return; } // Get the camera class todo all its updates first, then we'll handle the doorbell specific stuff super.updateDevice(deviceData); if (this.lightService !== undefined) { // Update status of light, including brightness this.lightService.updateCharacteristic(this.hap.Characteristic.On, deviceData.light_enabled); this.lightService.updateCharacteristic(this.hap.Characteristic.Brightness, deviceData.light_brightness); } } }