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