diff --git a/src/platform.ts b/src/platform.ts index 72bad12..02a134a 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -35,6 +35,7 @@ export class OpenSaunaPlatform implements DynamicPlatformPlugin { this.accessories.push(accessory); } + // Modify the discoverDevices method to add a single accessory discoverDevices() { if (!isOpenSaunaConfig(this.config)) { this.log.error( @@ -51,58 +52,40 @@ export class OpenSaunaPlatform implements DynamicPlatformPlugin { devices.saunaTimeout = devices.saunaTimeout ?? 60; // in minutes devices.steamTimeout = devices.steamTimeout ?? 60; // in minutes devices.saunaMaxTemperature = - devices.saunaMaxTemperature ?? (devices.temperatureUnitFahrenheit ? 212 : 100); + devices.saunaMaxTemperature ?? (devices.temperatureUnitFahrenheit ? 212 : 100); devices.steamMaxTemperature = - devices.steamMaxTemperature ?? (devices.temperatureUnitFahrenheit ? 140 : 60); + devices.steamMaxTemperature ?? (devices.temperatureUnitFahrenheit ? 140 : 60); devices.steamMaxHumidity = devices.steamMaxHumidity ?? 60; // in percent devices.saunaSafetyTemperature = devices.saunaSafetyTemperature ?? (devices.temperatureUnitFahrenheit ? 248 : 120); devices.steamSafetyTemperature = devices.steamSafetyTemperature ?? (devices.temperatureUnitFahrenheit ? 140 : 60); devices.controllerSafetyTemperature = devices.controllerSafetyTemperature ?? (devices.temperatureUnitFahrenheit ? 194 : 90); - // Conditionally add Sauna accessory - if (devices.hasSauna) { - this.addAccessory(devices, 'sauna'); - } - - // Conditionally add Steam accessory - if (devices.hasSteam) { - this.addAccessory(devices, 'steam'); - } - - // Add Light and Fan accessories if they exist - if (devices.hasLight) { - this.addAccessory(devices, 'light'); - } - - if (devices.hasFan) { - this.addAccessory(devices, 'fan'); - } + // Add a single accessory for all configured devices + this.addAccessory(devices); } - private addAccessory( - devices: OpenSaunaConfig, - type: 'sauna' | 'steam' | 'light' | 'fan', - ) { - // Generate a unique UUID for each accessory - const uuid = this.api.hap.uuid.generate(`${devices.name}-${type}`); + // Adjust addAccessory to handle a single accessory with all features + private addAccessory(devices: OpenSaunaConfig) { + // Generate a unique UUID for the combined accessory + const uuid = this.api.hap.uuid.generate(devices.name); const existingAccessory = this.accessories.find( (accessory) => accessory.UUID === uuid, ); if (existingAccessory) { - // The accessory already exists, update it + // The accessory already exists, update it this.log.info( 'Restoring existing accessory from cache:', existingAccessory.displayName, ); - new OpenSaunaAccessory(this, existingAccessory, devices, type); + new OpenSaunaAccessory(this, existingAccessory, devices); } else { - // Create a new accessory - this.log.info('Adding new accessory:', devices.name, type); + // Create a new accessory + this.log.info('Adding new accessory:', devices.name); const accessory = new this.api.platformAccessory(devices.name, uuid); // Create the accessory handler - new OpenSaunaAccessory(this, accessory, devices, type); + new OpenSaunaAccessory(this, accessory, devices); // Register the accessory this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [ diff --git a/src/platformAccessory.ts b/src/platformAccessory.ts index 9d9df95..e3c0e3a 100644 --- a/src/platformAccessory.ts +++ b/src/platformAccessory.ts @@ -37,7 +37,6 @@ export class OpenSaunaAccessory { private readonly platform: OpenSaunaPlatform, private readonly accessory: PlatformAccessory, private readonly config: OpenSaunaConfig, - private readonly accessoryType: 'sauna' | 'steam' | 'light' | 'fan', ) { // Set the accessory information this.accessory @@ -52,15 +51,6 @@ export class OpenSaunaAccessory { '58008', ); - // Set the accessory's name - this.accessory.displayName = `${config.name} ${accessoryType}`; - this.accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic( - this.platform.Characteristic.Name, - this.accessory.displayName, - ); - // Initialize RPIO with desired options rpio.init({ mapping: 'gpio', // Use GPIO pin numbering