diff --git a/backend/lib/entities/state/attributes/OperationModeStateAttribute.js b/backend/lib/entities/state/attributes/OperationModeStateAttribute.js new file mode 100644 index 00000000..3b457469 --- /dev/null +++ b/backend/lib/entities/state/attributes/OperationModeStateAttribute.js @@ -0,0 +1,40 @@ +const StateAttribute = require("./StateAttribute"); + +class OperationModeStateAttribute extends StateAttribute { + /** + * @param {object} options + * @param {OperationModeAttributeValue} options.value + * @param {object} [options.metaData] + */ + constructor(options) { + super(options); + + this.value = options.value; + } + + /** + * + * @param {OperationModeStateAttribute} otherAttribute + * @return {boolean} + */ + equals(otherAttribute) { + return this.__class === otherAttribute.__class && + this.type === otherAttribute.type && + this.subType === otherAttribute.subType && + this.value === otherAttribute.value; + } +} + +/** + * @typedef {string} OperationModeAttributeValue + * @enum {string} + * + */ +OperationModeStateAttribute.VALUE = Object.freeze({ + VACUUM: "vacuum", + MOP: "mop", + VACUUM_AND_MOP: "vacuum_and_mop" +}); + + +module.exports = OperationModeStateAttribute; diff --git a/backend/lib/entities/state/attributes/index.js b/backend/lib/entities/state/attributes/index.js index 4ff697bb..74c3862e 100644 --- a/backend/lib/entities/state/attributes/index.js +++ b/backend/lib/entities/state/attributes/index.js @@ -3,6 +3,7 @@ module.exports = { BatteryStateAttribute: require("./BatteryStateAttribute"), ConsumableStateAttribute: require("./ConsumableStateAttribute"), DockStatusStateAttribute: require("./DockStatusStateAttribute"), + OperationModeStateAttribute: require("./OperationModeStateAttribute"), PresetSelectionStateAttribute: require("./PresetSelectionStateAttribute"), StatusStateAttribute: require("./StatusStateAttribute") }; diff --git a/util/build_openapi_schema.mjs b/util/build_openapi_schema.mjs index bdc05550..d0c57e99 100644 --- a/util/build_openapi_schema.mjs +++ b/util/build_openapi_schema.mjs @@ -6,9 +6,9 @@ import * as path from "path"; const __dirname = path.resolve(); process.on("uncaughtException", function (err) { - // eslint-disable-next-line no-console - console.log(err); - process.exit(1); + // eslint-disable-next-line no-console + console.log(err); + process.exit(1); }); const options = { @@ -80,161 +80,31 @@ const options = { {BasicAuth: []} ], }, - servers: [{ url: "../" }], - tags: [ - //Swagger UI respects the order of these - { name: "Valetudo", description: "Valetudo management API" }, - { name: "ValetudoEvents", description: "Valetudo Events" }, - { name: "Robot", description: "Robot API" }, - { name: "System", description: "System API" }, - { name: "NTP", description: "NTP Client API" }, - { name: "Timers", description: "Timers API" }, - { name: "Updater", description: "Update Valetudo using Valetudo" }, - - { - name: "BasicControlCapability", - description: "Basic control capability", - }, - { - name: "FanSpeedControlCapability", - description: "Fan speed control capability", - }, - { - name: "WaterUsageControlCapability", - description: "Water usage control capability", - }, - { - name: "WifiConfigurationCapability", - description: "Wi-Fi configuration capability", - }, - { name: "WifiScanCapability", description: "Wi-Fi scan capability" }, - { - name: "ZoneCleaningCapability", - description: "Zone cleaning capability", - }, - { - name: "MapSegmentationCapability", - description: "Map segment cleaning capability", - }, - { - name: "ManualControlCapability", - description: "Manual control capability", - }, - { - name: "DoNotDisturbCapability", - description: "Do-not-disturb configuration capability", - }, - { - name: "ConsumableMonitoringCapability", - description: "Consumable monitoring capability", - }, - { name: "LocateCapability", description: "Robot locate capability" }, - { - name: "GoToLocationCapability", - description: "Go-to location capability", - }, - { - name: "CarpetModeControlCapability", - description: "Carpet mode settings capability", - }, - { name: "MapResetCapability", description: "Map reset capability" }, - { - name: "MapSegmentEditCapability", - description: "Map segment edit capability", - }, - { - name: "MapSegmentRenameCapability", - description: "Map segment rename capability", - }, - { - name: "MapSnapshotCapability", - description: "Map snapshots capability", - }, - { - name: "PersistentMapControlCapability", - description: "Persistent map control capability", - }, - { - name: "SensorCalibrationCapability", - description: "Sensor calibration capability", - }, - { name: "SpeakerTestCapability", description: "Speaker test capability" }, - { - name: "SpeakerVolumeControlCapability", - description: "Speaker volume control capability", - }, - { - name: "VoicePackManagementCapability", - description: "Voice pack management capability", - }, - { - name: "CombinedVirtualRestrictionsCapability", - description: "Combined virtual restrictions capability", - }, - { - name: "PendingMapChangeHandlingCapability", - description: "Pending map change handling capability", - }, - { name: "MappingPassCapability", description: "Mapping pass capability" }, - { name: "KeyLockCapability", description: "Key lock capability" }, - ], - components: { - responses: { - 200: { description: "Ok" }, - 201: { description: "Created" }, - 202: { description: "Accepted" }, - 400: { description: "Bad request" }, - 403: { description: "Forbidden" }, - 404: { description: "Not found" }, - 500: { description: "Internal server error" }, - }, - parameters: {}, - securitySchemes: { - BasicAuth: { - type: "http", - scheme: "basic", - }, - }, - }, - security: [{ BasicAuth: [] }], - }, - apis: [ - path.join(__dirname, "./backend/util/openapi_defs/*.openapi.json"), - path.join(__dirname, "./backend/lib/doc/*.openapi.json"), - path.join(__dirname, "./backend/lib/webserver/doc/*.openapi.json"), - path.join( - __dirname, - "./backend/lib/webserver/capabilityRouters/doc/*.openapi.json" - ), - path.join( - __dirname, - "./backend/lib/webserver/middlewares/doc/*.openapi.json" - ), - path.join(__dirname, "./backend/lib/entities/doc/*.openapi.json"), - path.join(__dirname, "./backend/lib/entities/map/doc/*.openapi.json"), - path.join(__dirname, "./backend/lib/entities/core/doc/*.openapi.json"), - path.join( - __dirname, - "./backend/lib/entities/core/ntpClient/doc/*.openapi.json" - ), - path.join( - __dirname, - "./backend/lib/entities/core/updater/doc/*.openapi.json" - ), - path.join(__dirname, "./backend/lib/entities/state/doc/*.openapi.json"), - path.join( - __dirname, - "./backend/lib/entities/state/attributes/doc/*.openapi.json" - ), - path.join(__dirname, "./backend/lib/core/capabilities/doc/*.openapi.json"), - ], + apis: [ + path.join(__dirname, "./backend/util/openapi_defs/*.openapi.json"), + path.join(__dirname, "./backend/lib/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/webserver/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/webserver/capabilityRouters/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/webserver/middlewares/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/entities/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/entities/map/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/entities/core/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/entities/core/ntpClient/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/entities/core/updater/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/entities/state/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/entities/state/attributes/doc/*.openapi.json"), + path.join(__dirname, "./backend/lib/core/capabilities/doc/*.openapi.json") + ] }; const spec = await swaggerJsdoc(options); await SwaggerParser.validate(spec); + fs.writeFileSync( - path.join(__dirname, "./backend/lib/res/valetudo.openapi.schema.json"), - JSON.stringify(spec) + path.join(__dirname, "./backend/lib/res/valetudo.openapi.schema.json"), + JSON.stringify(spec) ); + +