From 764f740a8efc8eccaf2a6fcad6d0921af7b3be58 Mon Sep 17 00:00:00 2001 From: Dallas Hoffman Date: Tue, 9 Jan 2024 22:43:26 -0500 Subject: [PATCH] Fix for devices which OpenRGB does not provide a name for --- src/platform.ts | 4 ++-- src/platformAccessory.ts | 6 +++--- src/settings.ts | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/platform.ts b/src/platform.ts index b3f58eb..aa7fdd1 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -1,6 +1,6 @@ import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from 'homebridge'; -import { PLATFORM_NAME, PLUGIN_NAME, DEFAULT_DISCOVERY_INTERVAL, SERVER_CONNECTION_TIMEOUT } from './settings'; +import { PLATFORM_NAME, PLUGIN_NAME, DEFAULT_DISCOVERY_INTERVAL, SERVER_CONNECTION_TIMEOUT, DEFAULT_DEVICE_NAME } from './settings'; import { OpenRgbPlatformAccessory } from './platformAccessory'; import { RgbServer, RgbDevice, RgbDeviceContext } from './rgb'; @@ -152,7 +152,7 @@ export class OpenRgbPlatform implements DynamicPlatformPlugin { this.log.info('Adding new accessory:', device.name); // create a new accessory - const accessory = new this.api.platformAccessory(device.name, uuid); + const accessory = new this.api.platformAccessory(device.name || DEFAULT_DEVICE_NAME, uuid); this.accessories.push(accessory); // the `context` property can be used to store any data about the accessory diff --git a/src/platformAccessory.ts b/src/platformAccessory.ts index ede6123..757a5cb 100644 --- a/src/platformAccessory.ts +++ b/src/platformAccessory.ts @@ -5,7 +5,7 @@ import { OpenRgbPlatform } from './platform'; import { Color, OpenRgbColor, RgbDeviceContext, RgbDeviceStates } from './rgb'; import * as ColorConvert from 'color-convert'; import { getDeviceLedRgbColor, findDeviceModeId, isLedOff, createDeviceLedConfig, getStateHsvColor } from './utils'; -import { CHARACTERISTIC_UPDATE_DELAY } from './settings'; +import { CHARACTERISTIC_UPDATE_DELAY, DEFAULT_DEVICE_NAME } from './settings'; /** * Platform Accessory @@ -30,14 +30,14 @@ export class OpenRgbPlatformAccessory { // set accessory information this.accessory.getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.context.device?.description?.split?.(' ')?.[0] || 'OpenRGB') - .setCharacteristic(this.platform.Characteristic.Model, accessory.context.device.name || 'RGB Device') + .setCharacteristic(this.platform.Characteristic.Model, accessory.context.device.name || DEFAULT_DEVICE_NAME) .setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.context.device.serial || '9876543210'); // get the LightBulb service if it exists, otherwise create a new LightBulb service this.service = this.accessory.getService(this.platform.Service.Lightbulb) || this.accessory.addService(this.platform.Service.Lightbulb); // set the service name, this is what is displayed as the default name on the Home app - this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name || 'RGB Device'); + this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name || DEFAULT_DEVICE_NAME); // each service must implement at-minimum the "required characteristics" for the given service type // see https://developers.homebridge.io/#/service/Lightbulb diff --git a/src/settings.ts b/src/settings.ts index 6620df1..b9482c8 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -4,6 +4,9 @@ export const PLATFORM_NAME = 'OpenRgbPlatform'; /** This must match the name of the plugin as defined in package.json */ export const PLUGIN_NAME = 'homebridge-openrgb'; +/** Name used for devices when OpenRGB does not provide a name for them */ +export const DEFAULT_DEVICE_NAME = 'RGB Device'; + /** Fallback value to use if config.discoveryInterval is left empty */ export const DEFAULT_DISCOVERY_INTERVAL = 60;