From 74ca8dc32d6a7a5f4700841eb561ea87beef4bf4 Mon Sep 17 00:00:00 2001 From: HJD Date: Sun, 29 Sep 2024 19:53:06 -0500 Subject: [PATCH] Housekeeping. --- src/devices/protect-chime.ts | 41 +----------------------------------- src/protect-nvr.ts | 4 ++-- 2 files changed, 3 insertions(+), 42 deletions(-) diff --git a/src/devices/protect-chime.ts b/src/devices/protect-chime.ts index 3dea808..a788c80 100644 --- a/src/devices/protect-chime.ts +++ b/src/devices/protect-chime.ts @@ -3,9 +3,9 @@ * protect-chime.ts: Chime device class for UniFi Protect. */ import { CharacteristicValue, PlatformAccessory } from "homebridge"; -import { ProtectChimeConfig, ProtectChimeConfigPayload, ProtectEventPacket } from "unifi-protect"; import { ProtectReservedNames, toCamelCase } from "../protect-types.js"; import { PROTECT_DOORBELL_CHIME_SPEAKER_DURATION } from "../settings.js"; +import { ProtectChimeConfig } from "unifi-protect"; import { ProtectDevice } from "./protect-device.js"; import { ProtectNvr } from "../protect-nvr.js"; @@ -62,9 +62,6 @@ export class ProtectChime extends ProtectDevice { // Configure MQTT services. this.configureMqtt(); - // Listen for events. - this.nvr.events.on("updateEvent." + this.ufp.id, this.listeners["updateEvent." + this.ufp.id] = this.eventHandler.bind(this)); - return true; } @@ -188,27 +185,6 @@ export class ProtectChime extends ProtectDevice { // Configure MQTT capabilities of this chime. private configureMqtt(): boolean { - // Get and set the chime volume. - this.subscribeGet("chime", "chime volume", (): string => { - - return this.ufp.volume.toString(); - }); - - this.subscribeSet("chime", "chime volume", (value: string) => { - - const volume = parseInt(value.toString()); - - // Unknown message - ignore it. - if(isNaN(volume) || (volume < 0) || (volume > 100)) { - - return; - } - - // We explicitly want to trigger our set event handler, which will complete this action. - this.accessory.getService(this.hap.Service.Lightbulb)?.getCharacteristic(this.hap.Characteristic.Brightness)?.setValue(volume); - this.accessory.getService(this.hap.Service.Lightbulb)?.getCharacteristic(this.hap.Characteristic.On)?.setValue(volume > 0); - }); - // Play a tone on the chime. this.subscribeSet("tone", "chime tone", (value: string) => { @@ -242,19 +218,4 @@ export class ProtectChime extends ProtectDevice { this.configureRingtoneSwitches(); } - - // Handle chime-related events. - private eventHandler(packet: ProtectEventPacket): void { - - const payload = packet.payload as ProtectChimeConfigPayload; - - // It's a volume setting event - process it accordingly. - if("volume" in payload) { - - // Update our volume setting. - this.accessory.getService(this.hap.Service.Lightbulb)?.updateCharacteristic(this.hap.Characteristic.Brightness, payload.volume as number); - this.accessory.getService(this.hap.Service.Lightbulb)?.updateCharacteristic(this.hap.Characteristic.On, (payload.volume as number) > 0); - this.publish("chime", (payload.volume ?? 0).toString()); - } - } } diff --git a/src/protect-nvr.ts b/src/protect-nvr.ts index 0e8e2c5..28de895 100644 --- a/src/protect-nvr.ts +++ b/src/protect-nvr.ts @@ -134,9 +134,9 @@ export class ProtectNvr { this.name = this.config.name ?? (this.ufp.name ?? this.ufp.marketName); // If we are running an unsupported version of UniFi Protect, we're done. - if((!this.ufp.version.startsWith("4.") && !this.ufp.version.startsWith("5.")) || this.ufp.version.split(".").map(Number).slice(0, 2).join(".") < "4.1") { + if(!this.ufp.version.startsWith("5.") || this.ufp.version.split(".").map(Number).slice(0, 2).join(".") < "5.0") { - this.log.error("This version of HBUP requires running UniFi Protect v4.1 or above using the official Protect release channel only."); + this.log.error("This version of HBUP requires running UniFi Protect v5.0 or above using the official Protect release channel only."); this.ufpApi.logout(); return;