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.solaredge.internal.model;
15 import static org.openhab.binding.solaredge.internal.SolarEdgeBindingConstants.*;
17 import java.util.HashMap;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.solaredge.internal.handler.ChannelProvider;
22 import org.openhab.binding.solaredge.internal.model.AggregateDataResponsePrivateApi.UtilizationMeasures;
23 import org.openhab.binding.solaredge.internal.model.AggregateDataResponsePrivateApi.Value;
24 import org.openhab.binding.solaredge.internal.model.AggregateDataResponsePrivateApi.ValueAndPercent;
25 import org.openhab.core.thing.Channel;
26 import org.openhab.core.types.State;
29 * transforms the http response into the openhab datamodel (instances of State)
31 * @author Alexander Friese - initial contribution
34 public class AggregateDataResponseTransformerPrivateApi extends AbstractDataResponseTransformer {
35 private final ChannelProvider channelProvider;
37 public AggregateDataResponseTransformerPrivateApi(ChannelProvider channelProvider) {
38 this.channelProvider = channelProvider;
41 public Map<Channel, State> transform(AggregateDataResponsePrivateApi response, AggregatePeriod period) {
42 Map<Channel, State> result = new HashMap<>(20);
43 UtilizationMeasures utilizationMeasures = response.getUtilizationMeasures();
45 String group = convertPeriodToGroup(period);
47 if (utilizationMeasures != null) {
48 Value production = utilizationMeasures.production;
49 if (production != null) {
50 putEnergyType(result, channelProvider.getChannel(group, CHANNEL_ID_PRODUCTION), production);
53 Value consumption = utilizationMeasures.consumption;
54 if (consumption != null) {
55 putEnergyType(result, channelProvider.getChannel(group, CHANNEL_ID_CONSUMPTION), consumption);
58 ValueAndPercent selfConsumptionForConsumption = utilizationMeasures.selfConsumptionForConsumption;
59 if (selfConsumptionForConsumption != null) {
60 putEnergyType(result, channelProvider.getChannel(group, CHANNEL_ID_SELF_CONSUMPTION_FOR_CONSUMPTION),
61 selfConsumptionForConsumption);
62 putPercentType(result, channelProvider.getChannel(group, CHANNEL_ID_SELF_CONSUMPTION_COVERAGE),
63 selfConsumptionForConsumption);
66 Value batterySelfConsumption = utilizationMeasures.batterySelfConsumption;
67 if (batterySelfConsumption != null) {
68 putEnergyType(result, channelProvider.getChannel(group, CHANNEL_ID_BATTERY_SELF_CONSUMPTION),
69 batterySelfConsumption);
72 Value imported = utilizationMeasures.imported;
73 if (imported != null) {
74 putEnergyType(result, channelProvider.getChannel(group, CHANNEL_ID_IMPORT), imported);
77 Value export = utilizationMeasures.export;
79 putEnergyType(result, channelProvider.getChannel(group, CHANNEL_ID_EXPORT), export);