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.handler;
15 import static org.openhab.binding.easee.internal.EaseeBindingConstants.*;
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;
35 * The {@link EaseeMasterChargerHandler} is responsible for handling commands, which are
36 * sent to one of the channels.
38 * @author Alexander Friese - initial contribution
41 public class EaseeMasterChargerHandler extends EaseeChargerHandler {
42 private final Logger logger = LoggerFactory.getLogger(EaseeMasterChargerHandler.class);
44 public EaseeMasterChargerHandler(Thing thing) {
49 * Poll the Easee Cloud API one time.
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);
60 enqueueCommand(new DynamicCircuitCurrent(this, circuitId));
61 enqueueCommand(new CircuitSettings(this, circuitId));
66 public EaseeCommand buildEaseeCommand(Command command, Channel channel) {
67 String circuitId = getConfig().get(EaseeBindingConstants.THING_CONFIG_CIRCUIT_ID).toString();
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);
79 return super.buildEaseeCommand(command, channel);