diff --git a/controller/boards/IntelliCenterBoard.ts b/controller/boards/IntelliCenterBoard.ts index 99f23ab1..2c4f076e 100644 --- a/controller/boards/IntelliCenterBoard.ts +++ b/controller/boards/IntelliCenterBoard.ts @@ -3412,7 +3412,7 @@ export class IntelliCenterChemControllerCommands extends ChemControllerCommands id = sys.chemControllers.nextAvailableChemController(); isAdd = true; } - if (typeof id === 'undefined' || id > sys.equipment.maxChemControllers) return Promise.reject(new InvalidEquipmentIdError(`Max chem controller id exceeded`, id, 'chemController')); + if (isAdd && sys.chemControllers.length >= sys.equipment.maxChemControllers) return Promise.reject(new InvalidEquipmentIdError(`Max chem controller id exceeded`, id, 'chemController')); chem = sys.chemControllers.getItemById(id, false); // Don't add it yet if it doesn't exist we will commit later after the OCP responds. if (isVirtual || chem.isVirtual || type !== 2) return super.setChemControllerAsync(data); // Fall back to the world of the virtual chem controller. if (isNaN(id)) return Promise.reject(new InvalidEquipmentIdError(`Invalid chemController id: ${data.id}`, data.id, 'ChemController')); diff --git a/controller/boards/SystemBoard.ts b/controller/boards/SystemBoard.ts index ad9ddfb3..f07fd387 100644 --- a/controller/boards/SystemBoard.ts +++ b/controller/boards/SystemBoard.ts @@ -2814,11 +2814,13 @@ export class ChemControllerCommands extends BoardCommands { // this is a combined chem config/state setter. let address = typeof data.address !== 'undefined' ? parseInt(data.address, 10) : undefined; let id = typeof data.id !== 'undefined' ? parseInt(data.id, 10) : -1; + let isAdd = false; if (typeof address === 'undefined' && id <= 0) { // adding a chem controller id = sys.chemControllers.nextAvailableChemController(); + isAdd = true; } - if (typeof id === 'undefined' || id > sys.equipment.maxChemControllers) return Promise.reject(new InvalidEquipmentIdError(`Max chem controller id exceeded`, id, 'chemController')); + if (isAdd && sys.chemControllers.length >= sys.equipment.maxChemControllers) return Promise.reject(new InvalidEquipmentIdError(`Max chem controller id exceeded`, id, 'chemController')); if (typeof address !== 'undefined' && address < 144 || address > 158) return Promise.reject(new InvalidEquipmentIdError(`Max chem controller id exceeded`, id, 'chemController')); if (isNaN(id)) return Promise.reject(new InvalidEquipmentIdError(`Invalid chemController id: ${data.id}`, data.id, 'ChemController')); let chem: ChemController;