]> git.basschouten.com Git - openhab-addons.git/blob
ea386ed1dc83f19269aee7e94a1c433fd82fe820
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.easee.internal.command.circuit;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
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;
23
24 /**
25  * implements the settings api call of the circuit.
26  *
27  * @author Alexander Friese - initial contribution
28  */
29 @NonNullByDefault
30 public class SetOfflineMaxCircuitCurrents extends SetCircuitSettings {
31     private static final String PHASE1 = "offlineMaxCircuitCurrentP1";
32     private static final String PHASE2 = "offlineMaxCircuitCurrentP2";
33     private static final String PHASE3 = "offlineMaxCircuitCurrentP3";
34
35     public SetOfflineMaxCircuitCurrents(EaseeThingHandler handler, Channel channel, Command command, String circuitId) {
36         super(handler, channel, command, circuitId);
37     }
38
39     /**
40      * helper that transforms channelId + commandvalue in a JSON string that can be added as content to a POST request.
41      *
42      * @return converted JSON string
43      * @throws ValidationException
44      */
45     @Override
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]);
54         } else {
55             throw new ValidationException(
56                     "malformed command string, expected: '<phase1>;<phase2>;<phase3>', actual: " + rawCommand);
57         }
58         return gson.toJson(content);
59     }
60 }