Skip to content

Commit

Permalink
Update config. Conditional initialization of doors and steam i2c sensor.
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-godinez committed Aug 15, 2024
1 parent 8b3b52a commit 30646db
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
15 changes: 8 additions & 7 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"hasSauna": true,
"hasSaunaSplitPhase": true,
"hasSteam": true,
"hasSteamI2C":false,
"hasSteamSplitPhase": false,
"hasLight": true,
"hasFan": true,
"hasLight": false,
"hasFan": false,
"inverseSaunaDoor": false,
"inverseSteamDoor": false,
"temperatureUnitFahrenheit": false,
Expand Down Expand Up @@ -42,16 +43,16 @@
"control": false
}
],
"saunaOnWhileDoorOpen": true,
"steamOnWhileDoorOpen": true,
"saunaOnWhileDoorOpen": false,
"steamOnWhileDoorOpen": false,
"saunaTimeout": 60,
"steamTimeout": 60,
"controllerSafetyTemperature": 90,
"saunaMaxTemperature": 100,
"steamMaxTemperature": 60,
"steamMaxHumidity": 60,
"saunaSafetyTemperature": 120,
"steamMaxTemperature": 60,
"steamSafetyTemperature": 60,
"controllerSafetyTemperature": 90
"steamMaxHumidity": 60
}
]
}
35 changes: 21 additions & 14 deletions src/platformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,20 @@ export class OpenSaunaAccessory {
});

// Initialize I2C Bus
i2c
.openPromisified(1)
.then((bus) => {
this.i2cBus = bus;
})
.catch((err: unknown) => {
if (err instanceof Error) {
this.platform.log.error('Failed to open I2C bus:', err.message);
} else {
this.platform.log.error('Failed to open I2C bus:', String(err));
}
});
if (this.config.hasSteamI2C){
i2c
.openPromisified(1)
.then((bus) => {
this.i2cBus = bus;
})
.catch((err: unknown) => {
if (err instanceof Error) {
this.platform.log.error('Failed to open I2C bus:', err.message);
} else {
this.platform.log.error('Failed to open I2C bus:', String(err));
}
});
}

// Initialize all necessary services based on the config
this.setupAccessory();
Expand Down Expand Up @@ -241,8 +243,13 @@ export class OpenSaunaAccessory {

// Monitor temperatures, humidity, and door states
this.monitorTemperatures();
this.monitorHumidity();
this.monitorDoors();
if (this.config.hasSteamI2C){
this.monitorHumidity();
}
if (!this.config.saunaOnWhileDoorOpen || !this.config.steamOnWhileDoorOpen ){
this.monitorDoors();
}

process.on('exit', this.cleanupGpioPins.bind(this));
}

Expand Down
15 changes: 8 additions & 7 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface OpenSaunaConfig {
hasSauna: boolean; // Indicates if the sauna is present
hasSaunaSplitPhase: boolean; // Indicates if the sauna uses split phase power
hasSteam: boolean; // Indicates if the steam room is present
hasSteamI2C: boolean; // Indicates if the I2C sensor the I2C humidity/temp sensor is available
hasSteamSplitPhase: boolean; // Indicates if the steam room uses split phase power
hasLight: boolean; // Indicates if a light control is available
hasFan: boolean; // Indicates if a fan control is available
Expand All @@ -21,21 +22,21 @@ export interface OpenSaunaConfig {
steamOnWhileDoorOpen: boolean; // Allows the steam room to be on while the door is open
saunaTimeout: number; // Maximum runtime for the sauna in minutes before auto-shutdown
steamTimeout: number; // Maximum runtime for the steam room in minutes before auto-shutdown
controllerSafetyTemperature: number; // Safety limit for the controller board temperature in degrees (hard-coded)
saunaMaxTemperature: number; // Maximum user-configurable temperature for the sauna in degrees
steamMaxTemperature: number; // Maximum user-configurable temperature for the steam room in degrees
steamMaxHumidity: number; // Maximum user-configurable humidity for the steam room in percent
saunaSafetyTemperature: number; // Safety limit for sauna temperature in degrees (hard-coded)
steamMaxTemperature: number; // Maximum user-configurable temperature for the steam room in degrees
steamSafetyTemperature: number; // Safety limit for steam room temperature in degrees (hard-coded)
controllerSafetyTemperature: number; // Safety limit for the controller board temperature in degrees (hard-coded)
steamMaxHumidity: number; // Maximum user-configurable humidity for the steam room in percent
}

export interface GpioConfig {
saunaPowerPins: number[]; // GPIO pins for sauna power control
steamPowerPins: number[]; // GPIO pins for steam room power control
lightPin?: number; // GPIO pin for light control (optional)
fanPin?: number; // GPIO pin for fan control (optional)
saunaDoorPin?: number; // GPIO pin for sauna door sensor (optional)
steamDoorPin?: number; // GPIO pin for steam door sensor (optional)
lightPin: number; // GPIO pin for light control (optional)
fanPin: number; // GPIO pin for fan control (optional)
saunaDoorPin: number; // GPIO pin for sauna door sensor (optional)
steamDoorPin: number; // GPIO pin for steam door sensor (optional)
}

export interface AuxSensorConfig {
Expand Down

0 comments on commit 30646db

Please sign in to comment.