Skip to content

Commit

Permalink
Fix for devices which OpenRGB does not provide a name for
Browse files Browse the repository at this point in the history
  • Loading branch information
DallasHoff committed Jan 10, 2024
1 parent 62dfa1c commit 764f740
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/platform.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<RgbDeviceContext>(device.name, uuid);
const accessory = new this.api.platformAccessory<RgbDeviceContext>(device.name || DEFAULT_DEVICE_NAME, uuid);
this.accessories.push(accessory);

// the `context` property can be used to store any data about the accessory
Expand Down
6 changes: 3 additions & 3 deletions src/platformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 764f740

Please sign in to comment.