2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ecovacs.internal.api.commands;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.ecovacs.internal.api.impl.ProtocolVersion;
17 import org.openhab.binding.ecovacs.internal.api.impl.dto.response.deviceapi.json.CleanReport;
18 import org.openhab.binding.ecovacs.internal.api.impl.dto.response.deviceapi.json.CleanReportV2;
19 import org.openhab.binding.ecovacs.internal.api.impl.dto.response.deviceapi.xml.CleaningInfo;
20 import org.openhab.binding.ecovacs.internal.api.impl.dto.response.portal.AbstractPortalIotCommandResponse;
21 import org.openhab.binding.ecovacs.internal.api.impl.dto.response.portal.PortalIotCommandJsonResponse;
22 import org.openhab.binding.ecovacs.internal.api.impl.dto.response.portal.PortalIotCommandXmlResponse;
23 import org.openhab.binding.ecovacs.internal.api.model.CleanMode;
24 import org.openhab.binding.ecovacs.internal.api.util.DataParsingException;
26 import com.google.gson.Gson;
29 * @author Danny Baumann - Initial contribution
32 public class GetCleanStateCommand extends IotDeviceCommand<CleanMode> {
33 public GetCleanStateCommand() {
38 public String getName(ProtocolVersion version) {
41 return "GetCleanState";
43 return "getCleanInfo";
45 return "getCleanInfo_V2";
47 throw new AssertionError();
51 public CleanMode convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson)
52 throws DataParsingException {
53 if (response instanceof PortalIotCommandJsonResponse) {
54 final PortalIotCommandJsonResponse jsonResponse = (PortalIotCommandJsonResponse) response;
56 if (version == ProtocolVersion.JSON) {
57 CleanReport resp = jsonResponse.getResponsePayloadAs(gson, CleanReport.class);
58 mode = resp.determineCleanMode(gson);
60 CleanReportV2 resp = jsonResponse.getResponsePayloadAs(gson, CleanReportV2.class);
61 mode = resp.determineCleanMode(gson);
64 throw new DataParsingException("Could not get clean mode from response " + jsonResponse.response);
68 String payload = ((PortalIotCommandXmlResponse) response).getResponsePayloadXml();
69 return CleaningInfo.parseCleanStateInfo(payload, gson).mode;