Skip to content

Commit

Permalink
Housekeeping.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdhjd committed Sep 30, 2024
1 parent 6a02a29 commit 74ca8dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 42 deletions.
41 changes: 1 addition & 40 deletions src/devices/protect-chime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) => {

Expand Down Expand Up @@ -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());
}
}
}
4 changes: 2 additions & 2 deletions src/protect-nvr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 74ca8dc

Please sign in to comment.