From 223ac76fde0a4f2cd9503f1e64f0937d1565a3fa Mon Sep 17 00:00:00 2001 From: Arjan Mels Date: Sat, 30 Apr 2022 13:13:12 +0200 Subject: [PATCH] Fixed various review findings --- bundles/org.openhab.binding.groupepsa/NOTICE | 2 +- .../org.openhab.binding.groupepsa/README.md | 114 +++++++++--------- .../bridge/GroupePSABridgeHandler.java | 4 - .../groupepsa/internal/rest/api/dto/User.java | 9 +- .../internal/rest/api/dto/VehicleStatus.java | 9 +- .../internal/things/GroupePSAHandler.java | 8 +- .../resources/OH-INF/thing/thing-types.xml | 20 +-- 7 files changed, 75 insertions(+), 91 deletions(-) diff --git a/bundles/org.openhab.binding.groupepsa/NOTICE b/bundles/org.openhab.binding.groupepsa/NOTICE index d5a8932c5e090..cdc134b446023 100644 --- a/bundles/org.openhab.binding.groupepsa/NOTICE +++ b/bundles/org.openhab.binding.groupepsa/NOTICE @@ -14,7 +14,7 @@ https://github.com/openhab/openhab-addons == Third-party Content -Java Telegram Bot API +GeoJSON support for Gson * License: Apache License 2.0 * Project: https://github.com/filosganga/geogson * Source: https://github.com/filosganga/geogson diff --git a/bundles/org.openhab.binding.groupepsa/README.md b/bundles/org.openhab.binding.groupepsa/README.md index e65176797c96f..590164803ab8b 100644 --- a/bundles/org.openhab.binding.groupepsa/README.md +++ b/bundles/org.openhab.binding.groupepsa/README.md @@ -18,68 +18,68 @@ You need to select a brand and enter the User Name and Password. The Polling interval (in minutes) determines how often the API will polled for new cars. The Client ID and Client Secret should not need to be updated. (However you can register your own app via https://developer.groupe-psa.com/inc/ and use this client information if you wish.) -### properties +### parameters -|Property|Default|Required|Description| -|--------|-------|--------|-----------| -|vendor|None|Yes|The brand of the car (PEUGEOT, CITROEN, DS, OPEL or VAUXHALL)| -|userName|None|Yes|The user name for the mypeugot/mycitroen/myds/myopel/myvauxhall website or app| -|password|None|Yes|The password for the given user| -|pollingInterval|60|No|The Polling interval (in minutes) determines how often the available vehicles are queried| -|clientId||Yes|The client ID for API access: can normally left at the default value. (see: https://developer.groupe-psa.io/webapi/b2c/quickstart/connect/#article)| -|clientSecret||Yes|The client secret for API access: can normally left at the default value. (see: https://developer.groupe-psa.io/webapi/b2c/quickstart/connect/#article)| +| Property | Default | Required | Description | +| --------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | +| vendor | None | Yes | The brand of the car (PEUGEOT, CITROEN, DS, OPEL or VAUXHALL) | +| userName | None | Yes | The user name for the mypeugot/mycitroen/myds/myopel/myvauxhall website or app | +| password | None | Yes | The password for the given user | +| pollingInterval | 60 | No | The Polling interval (in minutes) determines how often the available vehicles are queried | +| clientId | | Yes | The client ID for API access: can normally left at the default value. (see: https://developer.groupe-psa.io/webapi/b2c/quickstart/connect/#article) | +| clientSecret | | Yes | The client secret for API access: can normally left at the default value. (see: https://developer.groupe-psa.io/webapi/b2c/quickstart/connect/#article) | ## Vehicle Configuration Normally the vehicles will be autodiscovered. The Polling Interval and Online Timeout can be adjusted. -### properties +### parameters -|Property|Default|Required|Description| -|--------|-------|--------|-----------| -|id|None|Yes|Vehicle API ID|The ID is the vehicle API ID (not equal to the VIN), which is autodiscoverd by the bridge.| -|pollingInterval|5|No|The Polling interval (in minutes) determines how often the car is polled for updated information| -|onlineInterval|15|No|The Online Timeout (in minutes) determines when the car is deemed to be offline.| +| Property | Default | Required | Description | +| --------------- | ------- | -------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | +| id | None | Yes | Vehicle API ID | The ID is the vehicle API ID (not equal to the VIN), which is autodiscoverd by the bridge. | +| pollingInterval | 5 | No | The Polling interval (in minutes) determines how often the car is polled for updated information | +| onlineInterval | 15 | No | The Online Timeout (in minutes) determines when the car is deemed to be offline. | ## Channels -|Channel Type ID|Item Type|Description| -|-|-|-| -current|Number:ElectricCurrent|Electrical current -voltage|Number:ElectricPotential|Voltage -temperature|Number:Temperature|Temperature -daytime|Contact|Enabled if it is daytime -doorLock|String|Door lock state -doorOpen|Contact|Door is open -ignition|String|Ignition state -moving|Contact|Vehicle is moving -acceleration|Number:Acceleration|Current acceleration -speed|Number:Speed|Current speed -mileage|Number:Length|Total travelled distance -position|Location|Last known position -heading|Number:Angle|Direction of travel -type|String|Position acquisition type -signal|Number:Dimensionless|Strength of the position localization signal -lastUpdated|DateTime|Last time the results were updated on the server -privacy|String|Privacy status -belt|String|Seat belt status -emergency|String|Emergency call status -service|String|Service Type -preconditioning|String|Air conditioning status -preconditioningFailure|String|Airr conditioning failure cause -level|Number:Dimensionless|Fuel level -autonomy|Number:Length|Remaining distance -consumption|Number:VolumetricFlowRate|Fuel consumption -residual|Number:Energy|Remaining battery charge -capacity|Number:Energy|Battery capacity -healthCapacity|Number:Dimensionless|Health of the battery capacity -healthResistance|Number:Dimensionless|Health of the battery resistance -chargingStatus|String|Battery charging status -chargingMode|String|Battery charging mode -chargingPlugged|Contact|Vehicle plugged in to charger -chargingRate|Number:Speed|Battery Charging Rate -chargingRemainingTime|Number:Time|Time remaining till charged -chargingNextDelayedTime|Number:Time|Time till the next charging starts +| Channel Type ID | Item Type | Description | +| ----------------------- | ------------------------- | ------------------------------------------------ | +| current | Number:ElectricCurrent | Electrical current | +| voltage | Number:ElectricPotential | Voltage | +| temperature | Number:Temperature | Temperature | +| daytime | Contact | Enabled if it is daytime | +| doorLock | String | Door lock state | +| doorOpen | Contact | Door is open | +| ignition | String | Ignition state | +| moving | Contact | Vehicle is moving | +| acceleration | Number:Acceleration | Current acceleration | +| speed | Number:Speed | Current speed | +| mileage | Number:Length | Total travelled distance | +| position | Location | Last known position | +| heading | Number:Angle | Direction of travel | +| type | String | Position acquisition type | +| signal | Number:Dimensionless | Strength of the position localization signal | +| lastUpdated | DateTime | Last time the results were updated on the server | +| privacy | String | Privacy status | +| belt | String | Seat belt status | +| emergency | String | Emergency call status | +| service | String | Service Type | +| preconditioning | String | Air conditioning status | +| preconditioningFailure | String | Airr conditioning failure cause | +| level | Number:Dimensionless | Fuel level | +| autonomy | Number:Length | Remaining distance | +| consumption | Number:VolumetricFlowRate | Fuel consumption | +| residual | Number:Energy | Remaining battery charge | +| capacity | Number:Energy | Battery capacity | +| healthCapacity | Number:Dimensionless | Health of the battery capacity | +| healthResistance | Number:Dimensionless | Health of the battery resistance | +| chargingStatus | String | Battery charging status | +| chargingMode | String | Battery charging mode | +| chargingPlugged | Contact | Vehicle plugged in to charger | +| chargingRate | Number:Speed | Battery Charging Rate | +| chargingRemainingTime | Number:Time | Time remaining till charged | +| chargingNextDelayedTime | Number:Time | Time till the next charging starts | Further documentation can be found at: https://developer.groupe-psa.io/webapi/b2c/api-reference/specification/#article @@ -87,16 +87,16 @@ Further documentation can be found at: https://developer.groupe-psa.io/webapi/b2 ### Things file -```perl -Bridge groupepsa:bridge:opel "Auto Interface" [ +``` +Bridge groupepsa:bridge:opel "Auto Interface" [ pollingInterval=60, userName="anonymous@anonymous.email", password="password", vendor="OPEL" ] { Things: - vehicle zafira "Auto" @ "Outdoors" - [ + vehicle zafira "Auto" @ "Outdoors" + [ id="", pollingInterval=5, onlineInterval=1440 @@ -107,7 +107,7 @@ Bridge groupepsa:bridge:opel "Auto Interface" [ ### Items file -```perl +``` Group Auto Number:ElectricCurrent Auto_Aux_Current "Auxillliary Battery Current [%.1f %unit%]" (Auto) ["Measurement","Current"] {channel="groupepsa:vehicle:opel:zafira:battery#current"} diff --git a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java index e41d0b56d1931..b5d02e9a7a602 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java +++ b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java @@ -44,8 +44,6 @@ import org.openhab.core.thing.binding.BaseBridgeHandler; import org.openhab.core.thing.binding.ThingHandlerService; import org.openhab.core.types.Command; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * The {@link GroupePSABridgeHandler} is responsible for handling commands, @@ -55,8 +53,6 @@ */ @NonNullByDefault public class GroupePSABridgeHandler extends BaseBridgeHandler { - private final Logger logger = LoggerFactory.getLogger(GroupePSABridgeHandler.class); - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BRIDGE); private static final long DEFAULT_POLLING_INTERVAL_M = TimeUnit.HOURS.toMinutes(1); diff --git a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/dto/User.java b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/dto/User.java index 8228740da044d..6c2d6ae2e409e 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/dto/User.java +++ b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/dto/User.java @@ -18,6 +18,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; +import com.google.gson.annotations.SerializedName; + /** * @author Arjan Mels - Initial contribution */ @@ -26,7 +28,8 @@ public class User { private @Nullable String email; private @Nullable String firstName; private @Nullable String lastName; - private @Nullable Embedded _embedded; + @SerializedName("_embedded") + private @Nullable Embedded embedded; private @Nullable ZonedDateTime createdAt; private @Nullable ZonedDateTime updatedAt; @@ -52,7 +55,7 @@ public String toString() { } public @Nullable List getVehicles() { - final Embedded resEmbedded = _embedded; + final Embedded resEmbedded = embedded; if (resEmbedded != null) { return resEmbedded.vehicles; } else { @@ -72,6 +75,6 @@ public String toString() { public String toString() { return new ToStringBuilder(this).append("createdAt", createdAt).append("updatedAt", createdAt) .append("email", email).append("firstName", firstName).append("lastName", lastName) - .append("vehicles", _embedded != null ? _embedded : null).toString(); + .append("vehicles", embedded != null ? embedded : null).toString(); } } diff --git a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/dto/VehicleStatus.java b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/dto/VehicleStatus.java index 24dbbfa45639f..44d7d65cbbd66 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/dto/VehicleStatus.java +++ b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/dto/VehicleStatus.java @@ -27,7 +27,8 @@ public class VehicleStatus { private @Nullable ZonedDateTime updatedAt; - private @Nullable Embedded _embedded; + @SerializedName("_embedded") + private @Nullable Embedded embedded; private @Nullable Battery battery; private @Nullable DoorsState doorsState; private @Nullable List energy = null; @@ -65,7 +66,7 @@ public String toString() { if (kinetic != null) { return kinetic; } else { - final Embedded finalEmbedded = _embedded; + final Embedded finalEmbedded = embedded; if (finalEmbedded != null) { final Extension finalExtension = finalEmbedded.extension; if (finalExtension != null) { @@ -80,7 +81,7 @@ public String toString() { if (odometer != null) { return odometer; } else { - Embedded finalEmbedded = _embedded; + Embedded finalEmbedded = embedded; if (finalEmbedded != null) { final Extension finalExtension = finalEmbedded.extension; if (finalExtension != null) { @@ -137,7 +138,7 @@ public String toString() { @Override public String toString() { - return new ToStringBuilder(this).append("updatedAt", updatedAt).append("_embedded", _embedded) + return new ToStringBuilder(this).append("updatedAt", updatedAt).append("_embedded", embedded) .append("battery", battery).append("doorsState", doorsState).append("energy", energy) .append("environment", environment).append("ignition", ignition).append("kinetic", kinetic) .append("odometer", odometer).append("lastPosition", lastPosition) diff --git a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/things/GroupePSAHandler.java b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/things/GroupePSAHandler.java index 5dee94f6b953c..30a1b706c8552 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/things/GroupePSAHandler.java +++ b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/things/GroupePSAHandler.java @@ -99,6 +99,10 @@ public class GroupePSAHandler extends BaseThingHandler { private long maxQueryFrequencyNanos = TimeUnit.MINUTES.toNanos(1); private long onlineIntervalM; + public GroupePSAHandler(Thing thing) { + super(thing); + } + @Override protected @Nullable Bridge getBridge() { return super.getBridge(); @@ -113,10 +117,6 @@ private void pollStatus() { } }; - public GroupePSAHandler(Thing thing) { - super(thing); - } - @Override public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { diff --git a/bundles/org.openhab.binding.groupepsa/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.groupepsa/src/main/resources/OH-INF/thing/thing-types.xml index 963c4c2b52263..712f95ae92048 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.groupepsa/src/main/resources/OH-INF/thing/thing-types.xml @@ -130,7 +130,6 @@ Environmental conditions - Sun_Clouds @@ -143,7 +142,6 @@ Motion information - Motion @@ -156,7 +154,6 @@ Location information - MoveControl @@ -207,7 +204,6 @@ Contact Enabled if it is daytime - Sun @@ -241,7 +237,6 @@ String Ignition state - Motion @@ -256,14 +251,12 @@ Contact Vehicle is moving - Motion Number:Acceleration Current acceleration - Motion @@ -271,7 +264,6 @@ Number:Speed Current speed - Motion @@ -279,7 +271,6 @@ Number:Length Total travelled distance - Motion @@ -287,7 +278,6 @@ Location Last known position - MoveControl @@ -295,7 +285,6 @@ Number:Angle Direction of travel - MoveControl @@ -303,7 +292,6 @@ String Position acquisition type - MoveControl @@ -387,7 +375,7 @@ String - Airr conditioning failure cause + Air conditioning failure cause @@ -412,8 +400,7 @@ - Electric energy - Electric motor energy status + Electric motor energy status @@ -440,7 +427,6 @@ Number:Dimensionless Fuel level - Pressure @@ -448,7 +434,6 @@ Number:Length Remaining distance - Pressure @@ -456,7 +441,6 @@ Number:VolumetricFlowRate Fuel consumption - Pressure