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.easee.internal.command.circuit;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.easee.internal.command.JsonResultProcessor;
20 import org.openhab.binding.easee.internal.handler.EaseeThingHandler;
21 import org.openhab.binding.easee.internal.model.ValidationException;
22 import org.openhab.core.thing.Channel;
23 import org.openhab.core.types.Command;
26 * implements the settings api call of the circuit.
28 * @author Alexander Friese - initial contribution
31 public class SetMaxCircuitCurrents extends SetCircuitSettings {
32 private static final String PHASE1 = "maxCircuitCurrentP1";
33 private static final String PHASE2 = "maxCircuitCurrentP2";
34 private static final String PHASE3 = "maxCircuitCurrentP3";
36 public SetMaxCircuitCurrents(EaseeThingHandler handler, Channel channel, Command command, String circuitId,
37 JsonResultProcessor resultProcessor) {
38 super(handler, channel, command, circuitId, resultProcessor);
42 * helper that transforms channelId + commandvalue in a JSON string that can be added as content to a POST request.
44 * @return converted JSON string
45 * @throws ValidationException
48 protected String getJsonContent() throws ValidationException {
49 Map<String, String> content = new HashMap<String, String>(3);
50 String rawCommand = getCommandValue();
51 String[] tokens = rawCommand.split(";");
52 if (tokens.length == 3) {
53 content.put(PHASE1, tokens[0]);
54 content.put(PHASE2, tokens[1]);
55 content.put(PHASE3, tokens[2]);
57 throw new ValidationException(
58 "malformed command string, expected: '<phase1>;<phase2>;<phase3>', actual: " + rawCommand);
60 return gson.toJson(content);