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.mybmw.internal.dto.vehicle;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
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;
25 * The {@link VehicleCapabilities} Data Transfer Object
27 * @author Bernd Weymann - Initial contribution
28 * @author Martin Grassl - refactored to Java Bean
31 public class VehicleCapabilities {
32 private final Logger logger = LoggerFactory.getLogger(VehicleCapabilities.class);
34 private static final String PREFIX_IS = "is";
35 public static final String SUPPORTED_SUFFIX = "Supported";
36 public static final String ENABLED_SUFFIX = "Enabled";
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,
88 * @return the climateNow
90 public boolean isClimateNow() {
97 public boolean isHorn() {
104 public boolean isLights() {
111 public boolean isLock() {
116 * @return the remote360
118 public boolean isRemote360() {
123 * @return the sendPoi
125 public boolean isSendPoi() {
132 public boolean isUnlock() {
137 * @return the vehicleFinder
139 public boolean isVehicleFinder() {
140 return vehicleFinder;
144 * @return the digitalKey
146 public DigitalKey getDigitalKey() {
151 * returns a list of capabilities filtered by the provided suffix and the enabled requirement
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
157 public String getCapabilitiesAsString(String suffix, boolean enabled) {
158 StringBuffer capabilitiesAsString = new StringBuffer();
159 List<String> capabilitiesAsStringList = getCapabilitiesAsStringList(suffix, enabled);
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);
168 capabilitiesAsString.append(cut.substring(0, cut.length() - suffix.length()));
171 return capabilitiesAsString.toString();
174 private List<String> getCapabilitiesAsStringList(String suffix, boolean compare) {
175 List<String> l = new ArrayList<>();
177 Arrays.asList(VehicleCapabilities.class.getDeclaredFields()).stream()
178 .filter(field -> field.getName().startsWith(PREFIX_IS) && field.getName().endsWith(suffix))
181 boolean value = field.getBoolean(this);
182 if (compare == value) {
183 l.add(field.getName());
185 } catch (IllegalArgumentException | IllegalAccessException e) {
186 logger.trace("field {} not usable: ", field.getName());
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 + "]";