]> git.basschouten.com Git - openhab-addons.git/blob
7241dafe13afa525a974b0a74c35066ae48bb88f
[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.mybmw.internal.dto.vehicle;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
19 import org.openhab.binding.mybmw.internal.dto.charge.RemoteChargingCommands;
20 import org.openhab.binding.mybmw.internal.utils.Constants;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * The {@link VehicleCapabilities} Data Transfer Object
26  *
27  * @author Bernd Weymann - Initial contribution
28  * @author Martin Grassl - refactored to Java Bean
29  */
30
31 public class VehicleCapabilities {
32     private final Logger logger = LoggerFactory.getLogger(VehicleCapabilities.class);
33
34     private static final String PREFIX_IS = "is";
35     public static final String SUPPORTED_SUFFIX = "Supported";
36     public static final String ENABLED_SUFFIX = "Enabled";
37
38     private boolean checkSustainabilityDPP = false;
39     private boolean climateNow = false;
40     private boolean horn = false;
41     private boolean isBmwChargingSupported = false;
42     private boolean isCarSharingSupported = false;
43     private boolean isChargeNowForBusinessSupported = false;
44     private boolean isChargingHistorySupported = false;
45     private boolean isChargingHospitalityEnabled = false;
46     private boolean isChargingLoudnessEnabled = false;
47     private boolean isChargingPlanSupported = false;
48     private boolean isChargingPowerLimitEnabled = false;
49     private boolean isChargingSettingsEnabled = false;
50     private boolean isChargingTargetSocEnabled = false;
51     private boolean isClimateTimerSupported = false;
52     private boolean isClimateTimerWeeklyActive = false;
53     private boolean isCustomerEsimSupported = false;
54     private boolean isDataPrivacyEnabled = false;
55     private boolean isDCSContractManagementSupported = false;
56     private boolean isEasyChargeEnabled = false;
57     private boolean isEvGoChargingSupported = false;
58     private boolean isMiniChargingSupported = false;
59     private boolean isNonLscFeatureEnabled = false;
60     private boolean isRemoteEngineStartSupported = false;
61     private boolean isRemoteHistoryDeletionSupported = false;
62     private boolean isRemoteHistorySupported = false;
63     private boolean isRemoteParkingSupported = false;
64     private boolean isRemoteServicesActivationRequired = false;
65     private boolean isRemoteServicesBookingRequired = false;
66     private boolean isScanAndChargeSupported = false;
67     private boolean isSustainabilityAccumulatedViewEnabled = false;
68     private boolean isSustainabilitySupported = false;
69     private boolean isWifiHotspotServiceSupported = false;
70     private boolean lights = false;
71     private boolean lock = false;
72     private boolean remote360 = false;
73     private RemoteChargingCommands remoteChargingCommands = new RemoteChargingCommands();
74     private boolean remoteSoftwareUpgrade = false;
75     private boolean sendPoi = false;
76     private boolean speechThirdPartyAlexa = false;
77     private boolean speechThirdPartyAlexaSDK = false;
78     private boolean unlock = false;
79     private boolean vehicleFinder = false;
80     private DigitalKey digitalKey = new DigitalKey();
81     private String a4aType = ""; // NOT_SUPPORTED,
82     private String climateFunction = ""; // VENTILATION,
83     private String climateTimerTrigger = ""; // DEPARTURE_TIMER,
84     private String lastStateCallState = ""; // ACTIVATED,
85     private String vehicleStateSource = ""; // LAST_STATE_CALL,
86
87     /**
88      * @return the climateNow
89      */
90     public boolean isClimateNow() {
91         return climateNow;
92     }
93
94     /**
95      * @return the horn
96      */
97     public boolean isHorn() {
98         return horn;
99     }
100
101     /**
102      * @return the lights
103      */
104     public boolean isLights() {
105         return lights;
106     }
107
108     /**
109      * @return the lock
110      */
111     public boolean isLock() {
112         return lock;
113     }
114
115     /**
116      * @return the remote360
117      */
118     public boolean isRemote360() {
119         return remote360;
120     }
121
122     /**
123      * @return the sendPoi
124      */
125     public boolean isSendPoi() {
126         return sendPoi;
127     }
128
129     /**
130      * @return the unlock
131      */
132     public boolean isUnlock() {
133         return unlock;
134     }
135
136     /**
137      * @return the vehicleFinder
138      */
139     public boolean isVehicleFinder() {
140         return vehicleFinder;
141     }
142
143     /**
144      * @return the digitalKey
145      */
146     public DigitalKey getDigitalKey() {
147         return digitalKey;
148     }
149
150     /**
151      * returns a list of capabilities filtered by the provided suffix and the enabled requirement
152      * 
153      * @param suffix the suffix of the capability
154      * @param enabled if it should return only enabled or disabled capabilities
155      * @return the list of capabilities as single string
156      */
157     public String getCapabilitiesAsString(String suffix, boolean enabled) {
158         StringBuffer capabilitiesAsString = new StringBuffer();
159         List<String> capabilitiesAsStringList = getCapabilitiesAsStringList(suffix, enabled);
160
161         for (String capEntry : capabilitiesAsStringList) {
162             // remove "is" prefix and provided suffix
163             String cut = capEntry.substring(2);
164             if (cut.endsWith(suffix)) {
165                 if (capabilitiesAsString.length() > 0) {
166                     capabilitiesAsString.append(Constants.SEMICOLON);
167                 }
168                 capabilitiesAsString.append(cut.substring(0, cut.length() - suffix.length()));
169             }
170         }
171         return capabilitiesAsString.toString();
172     }
173
174     private List<String> getCapabilitiesAsStringList(String suffix, boolean compare) {
175         List<String> l = new ArrayList<>();
176
177         Arrays.asList(VehicleCapabilities.class.getDeclaredFields()).stream()
178                 .filter(field -> field.getName().startsWith(PREFIX_IS) && field.getName().endsWith(suffix))
179                 .forEach(field -> {
180                     try {
181                         boolean value = field.getBoolean(this);
182                         if (compare == value) {
183                             l.add(field.getName());
184                         }
185                     } catch (IllegalArgumentException | IllegalAccessException e) {
186                         logger.trace("field {} not usable: ", field.getName());
187                     }
188                 });
189
190         return l;
191     }
192
193     @Override
194     public String toString() {
195         return "VehicleCapabilities [checkSustainabilityDPP=" + checkSustainabilityDPP + ", climateNow=" + climateNow
196                 + ", horn=" + horn + ", isBmwChargingSupported=" + isBmwChargingSupported + ", isCarSharingSupported="
197                 + isCarSharingSupported + ", isChargeNowForBusinessSupported=" + isChargeNowForBusinessSupported
198                 + ", isChargingHistorySupported=" + isChargingHistorySupported + ", isChargingHospitalityEnabled="
199                 + isChargingHospitalityEnabled + ", isChargingLoudnessEnabled=" + isChargingLoudnessEnabled
200                 + ", isChargingPlanSupported=" + isChargingPlanSupported + ", isChargingPowerLimitEnabled="
201                 + isChargingPowerLimitEnabled + ", isChargingSettingsEnabled=" + isChargingSettingsEnabled
202                 + ", isChargingTargetSocEnabled=" + isChargingTargetSocEnabled + ", isClimateTimerSupported="
203                 + isClimateTimerSupported + ", isClimateTimerWeeklyActive=" + isClimateTimerWeeklyActive
204                 + ", isCustomerEsimSupported=" + isCustomerEsimSupported + ", isDataPrivacyEnabled="
205                 + isDataPrivacyEnabled + ", isDCSContractManagementSupported=" + isDCSContractManagementSupported
206                 + ", isEasyChargeEnabled=" + isEasyChargeEnabled + ", isEvGoChargingSupported="
207                 + isEvGoChargingSupported + ", isMiniChargingSupported=" + isMiniChargingSupported
208                 + ", isNonLscFeatureEnabled=" + isNonLscFeatureEnabled + ", isRemoteEngineStartSupported="
209                 + isRemoteEngineStartSupported + ", isRemoteHistoryDeletionSupported="
210                 + isRemoteHistoryDeletionSupported + ", isRemoteHistorySupported=" + isRemoteHistorySupported
211                 + ", isRemoteParkingSupported=" + isRemoteParkingSupported + ", isRemoteServicesActivationRequired="
212                 + isRemoteServicesActivationRequired + ", isRemoteServicesBookingRequired="
213                 + isRemoteServicesBookingRequired + ", isScanAndChargeSupported=" + isScanAndChargeSupported
214                 + ", isSustainabilityAccumulatedViewEnabled=" + isSustainabilityAccumulatedViewEnabled
215                 + ", isSustainabilitySupported=" + isSustainabilitySupported + ", isWifiHotspotServiceSupported="
216                 + isWifiHotspotServiceSupported + ", lights=" + lights + ", lock=" + lock + ", remote360=" + remote360
217                 + ", remoteChargingCommands=" + remoteChargingCommands + ", remoteSoftwareUpgrade="
218                 + remoteSoftwareUpgrade + ", sendPoi=" + sendPoi + ", speechThirdPartyAlexa=" + speechThirdPartyAlexa
219                 + ", speechThirdPartyAlexaSDK=" + speechThirdPartyAlexaSDK + ", unlock=" + unlock + ", vehicleFinder="
220                 + vehicleFinder + ", digitalKey=" + digitalKey + ", a4aType=" + a4aType + ", climateFunction="
221                 + climateFunction + ", climateTimerTrigger=" + climateTimerTrigger + ", lastStateCallState="
222                 + lastStateCallState + ", vehicleStateSource=" + vehicleStateSource + "]";
223     }
224 }