]> git.basschouten.com Git - openhab-addons.git/blob
f66ed7216b6214ac3af8cfc40b53f235760c83c1
[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.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;
24
25 /**
26  * implements the settings api call of the circuit.
27  *
28  * @author Alexander Friese - initial contribution
29  */
30 @NonNullByDefault
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";
35
36     public SetMaxCircuitCurrents(EaseeThingHandler handler, Channel channel, Command command, String circuitId,
37             JsonResultProcessor resultProcessor) {
38         super(handler, channel, command, circuitId, resultProcessor);
39     }
40
41     /**
42      * helper that transforms channelId + commandvalue in a JSON string that can be added as content to a POST request.
43      *
44      * @return converted JSON string
45      * @throws ValidationException
46      */
47     @Override
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]);
56         } else {
57             throw new ValidationException(
58                     "malformed command string, expected: '<phase1>;<phase2>;<phase3>', actual: " + rawCommand);
59         }
60         return gson.toJson(content);
61     }
62 }