]> git.basschouten.com Git - openhab-addons.git/blob
fcf7fc27afa799fdc7722d3cd205bf2ff95e4efc
[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.handler;
14
15 import static org.openhab.binding.easee.internal.EaseeBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.easee.internal.EaseeBindingConstants;
19 import org.openhab.binding.easee.internal.Utils;
20 import org.openhab.binding.easee.internal.command.EaseeCommand;
21 import org.openhab.binding.easee.internal.command.circuit.CircuitSettings;
22 import org.openhab.binding.easee.internal.command.circuit.DynamicCircuitCurrent;
23 import org.openhab.binding.easee.internal.command.circuit.SetCircuitSettings;
24 import org.openhab.binding.easee.internal.command.circuit.SetDynamicCircuitCurrents;
25 import org.openhab.binding.easee.internal.command.circuit.SetMaxCircuitCurrents;
26 import org.openhab.binding.easee.internal.command.circuit.SetOfflineMaxCircuitCurrents;
27 import org.openhab.core.thing.Channel;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingStatus;
30 import org.openhab.core.types.Command;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * The {@link EaseeMasterChargerHandler} is responsible for handling commands, which are
36  * sent to one of the channels.
37  *
38  * @author Alexander Friese - initial contribution
39  */
40 @NonNullByDefault
41 public class EaseeMasterChargerHandler extends EaseeChargerHandler {
42     private final Logger logger = LoggerFactory.getLogger(EaseeMasterChargerHandler.class);
43
44     public EaseeMasterChargerHandler(Thing thing) {
45         super(thing);
46     }
47
48     /**
49      * Poll the Easee Cloud API one time.
50      */
51     @Override
52     void pollingRun() {
53         super.pollingRun();
54
55         // proceed if charger is online, otherwise circuit data is not in sync.
56         if (getThing().getStatus() == ThingStatus.ONLINE) {
57             String circuitId = getConfig().get(EaseeBindingConstants.THING_CONFIG_CIRCUIT_ID).toString();
58             logger.debug("polling circuit data for {}", circuitId);
59
60             enqueueCommand(new DynamicCircuitCurrent(this, circuitId));
61             enqueueCommand(new CircuitSettings(this, circuitId));
62         }
63     }
64
65     @Override
66     public EaseeCommand buildEaseeCommand(Command command, Channel channel) {
67         String circuitId = getConfig().get(EaseeBindingConstants.THING_CONFIG_CIRCUIT_ID).toString();
68
69         switch (Utils.getWriteCommand(channel)) {
70             case COMMAND_SET_CIRCUIT_SETTINGS:
71                 return new SetCircuitSettings(this, channel, command, circuitId);
72             case COMMAND_SET_DYNAMIC_CIRCUIT_CURRENTS:
73                 return new SetDynamicCircuitCurrents(this, channel, command, circuitId);
74             case COMMAND_SET_MAX_CIRCUIT_CURRENTS:
75                 return new SetMaxCircuitCurrents(this, channel, command, circuitId);
76             case COMMAND_SET_OFFLINE_MAX_CIRCUIT_CURRENTS:
77                 return new SetOfflineMaxCircuitCurrents(this, channel, command, circuitId);
78             default:
79                 return super.buildEaseeCommand(command, channel);
80         }
81     }
82 }