diff --git a/backend/lib/miio/MiioDummycloudNotConnectedError.js b/backend/lib/miio/MiioDummycloudNotConnectedError.js new file mode 100644 index 0000000000..02af56b125 --- /dev/null +++ b/backend/lib/miio/MiioDummycloudNotConnectedError.js @@ -0,0 +1,9 @@ +class MiioDummycloudNotConnectedError extends Error { + /** @param {object} msg The request message that was not responded to. */ + constructor(msg) { + super("Dummycloud not connected. Failed to send message:" + JSON.stringify(msg)); + this.name = "MiioDummycloudNotConnectedError"; + } +} + +module.exports = MiioDummycloudNotConnectedError; diff --git a/backend/lib/robots/MiioValetudoRobot.js b/backend/lib/robots/MiioValetudoRobot.js index 4beda33620..0f3a6297e7 100644 --- a/backend/lib/robots/MiioValetudoRobot.js +++ b/backend/lib/robots/MiioValetudoRobot.js @@ -16,6 +16,7 @@ const Tools = require("../utils/Tools"); const ValetudoRobot = require("../core/ValetudoRobot"); const entities = require("../entities"); +const MiioDummycloudNotConnectedError = require("../miio/MiioDummycloudNotConnectedError"); const stateAttrs = entities.state.attributes; class MiioValetudoRobot extends ValetudoRobot { @@ -356,14 +357,26 @@ class MiioValetudoRobot extends ValetudoRobot { * @param {object} options * @param {number=} options.retries * @param {number=} options.timeout custom timeout in milliseconds - * @param {boolean=} options.preferLocalInterface + * @param {"local"|"cloud"=} options.interface * @returns {Promise} */ sendCommand(method, args = [], options = {}) { - if (this.dummyCloud.miioSocket.connected && options.preferLocalInterface !== true) { - return this.sendCloud({"method": method, "params": args}, options); + const msg = {"method": method, "params": args}; + + if (options.interface === "cloud") { + if (this.dummyCloud.miioSocket.connected) { + return this.sendCloud(msg, options); + } else { + throw new MiioDummycloudNotConnectedError(msg); + } + } else if (options.interface === "local") { + return this.localSocket.sendMessage(msg, options); } else { - return this.localSocket.sendMessage({"method": method, "params": args}, options); + if (this.dummyCloud.miioSocket.connected) { + return this.sendCloud(msg, options); + } else { + return this.localSocket.sendMessage(msg, options); + } } } diff --git a/backend/lib/robots/common/miioCapabilities/MiioWifiConfigurationCapability.js b/backend/lib/robots/common/miioCapabilities/MiioWifiConfigurationCapability.js index e4cc64caee..3e110c1f42 100644 --- a/backend/lib/robots/common/miioCapabilities/MiioWifiConfigurationCapability.js +++ b/backend/lib/robots/common/miioCapabilities/MiioWifiConfigurationCapability.js @@ -58,7 +58,7 @@ class MiioWifiConfigurationCapability extends LinuxWifiConfigurationCapability { "config_type": "app" }, { - preferLocalInterface: true + interface: "local" } ); } else { diff --git a/backend/lib/robots/dreame/DreameValetudoRobot.js b/backend/lib/robots/dreame/DreameValetudoRobot.js index 3475e20ce0..25683ae23e 100644 --- a/backend/lib/robots/dreame/DreameValetudoRobot.js +++ b/backend/lib/robots/dreame/DreameValetudoRobot.js @@ -10,6 +10,7 @@ const AttachmentStateAttribute = require("../../entities/state/attributes/Attach const AttributeSubscriber = require("../../entities/AttributeSubscriber"); const CallbackAttributeSubscriber = require("../../entities/CallbackAttributeSubscriber"); const entities = require("../../entities"); +const MiioDummycloudNotConnectedError = require("../../miio/MiioDummycloudNotConnectedError"); const MiioErrorResponseRobotFirmwareError = require("../../miio/MiioErrorResponseRobotFirmwareError"); const MiioValetudoRobot = require("../MiioValetudoRobot"); const PendingMapChangeValetudoEvent = require("../../valetudo_events/events/PendingMapChangeValetudoEvent"); @@ -74,7 +75,10 @@ class DreameValetudoRobot extends MiioValetudoRobot { value: "{\"frame_type\":\"I\", \"force_type\": 1, \"req_type\": 1}" }] }, - {timeout: 7000} // user ack timeout seems to appear after ~6s on the p2028 1156 + { + timeout: 7000, // user ack timeout seems to appear after ~6s on the p2028 1156 + interface: "cloud" + } ); } catch (e) { if (e instanceof MiioErrorResponseRobotFirmwareError && e.response?.message === "user ack timeout") { @@ -84,11 +88,12 @@ class DreameValetudoRobot extends MiioValetudoRobot { As this is expected, we just ignore that error */ + } else if (e instanceof MiioDummycloudNotConnectedError) { + /* intentional */ } else { Logger.warn("Error while polling map", e); } - return; } diff --git a/backend/lib/robots/roborock/RoborockValetudoRobot.js b/backend/lib/robots/roborock/RoborockValetudoRobot.js index 1ea2f62072..3d02c1c944 100644 --- a/backend/lib/robots/roborock/RoborockValetudoRobot.js +++ b/backend/lib/robots/roborock/RoborockValetudoRobot.js @@ -9,6 +9,7 @@ const entities = require("../../entities"); const LinuxTools = require("../../utils/LinuxTools"); const LinuxWifiScanCapability = require("../common/linuxCapabilities/LinuxWifiScanCapability"); const MapLayer = require("../../entities/map/MapLayer"); +const MiioDummycloudNotConnectedError = require("../../miio/MiioDummycloudNotConnectedError"); const MiioValetudoRobot = require("../MiioValetudoRobot"); const PendingMapChangeValetudoEvent = require("../../valetudo_events/events/PendingMapChangeValetudoEvent"); const ValetudoMap = require("../../entities/map/ValetudoMap"); @@ -375,7 +376,16 @@ class RoborockValetudoRobot extends MiioValetudoRobot { } async executeMapPoll() { - return this.sendCloud({"method": "get_map_v1"}); + let result; + try { + result = await this.sendCommand("get_map_v1"); + } catch (e) { + if (!(e instanceof MiioDummycloudNotConnectedError)) { + throw e; + } + } + + return result; } determineNextMapPollInterval(pollResponse) { diff --git a/backend/lib/robots/viomi/ViomiValetudoRobot.js b/backend/lib/robots/viomi/ViomiValetudoRobot.js index b3614d3b5e..d5697190e0 100644 --- a/backend/lib/robots/viomi/ViomiValetudoRobot.js +++ b/backend/lib/robots/viomi/ViomiValetudoRobot.js @@ -177,7 +177,7 @@ class ViomiValetudoRobot extends MiioValetudoRobot { * @param {object} options * @param {number=} options.retries * @param {number=} options.timeout custom timeout in milliseconds - * @param {boolean=} options.preferLocalInterface + * @param {"local"|"cloud"=} options.interface * @returns {Promise} */ sendCommand(method, args = [], options = {}) { @@ -457,7 +457,7 @@ class ViomiValetudoRobot extends MiioValetudoRobot { } async executeMapPoll() { - return this.sendCommand("set_uploadmap", [2], {timeout: 2000}); + return this.sendCommand("set_uploadmap", [2], {timeout: 2000, interface: "cloud"}); } preprocessMap(data) {