From c3b6843c8fb5823a97da7b0ec843517813f0b5e7 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Sat, 17 Aug 2024 14:37:18 +0200 Subject: [PATCH 1/2] [freeboxos] Fix command handling for DECT thing type Related to comment in #17262 Signed-off-by: Laurent Garnier --- .../freeboxos/internal/api/rest/PhoneManager.java | 15 ++------------- .../config/PhoneConfigurationBuilder.java | 7 +++---- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java index 73bac2d0bcaa4..50b877a892dfc 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java @@ -37,22 +37,11 @@ protected class ConfigResponse extends Response { protected class StatusResponse extends Response { } - private enum NetworkStatus { - WORKING, - UNKNOWN - } - - public static record Config(NetworkStatus network, boolean dectEcoMode, String dectPin, int dectRingPattern, + public static record Config(String network, boolean dectEcoMode, String dectPin, int dectRingPattern, boolean dectRegistration, boolean dectNemoMode, boolean dectEnabled, boolean dectRingOnOff) { } - public enum Type { - FXS, - DECT, - UNKNOWN - } - - public static record Status(int id, boolean isRinging, boolean onHook, boolean hardwareDefect, Type type, + public static record Status(int id, boolean isRinging, boolean onHook, boolean hardwareDefect, String type, @Nullable String vendor, int gainRx, int gainTx) { public String vendor() { diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java index f46fe12cdf6f9..6cbc160a67a35 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java @@ -16,7 +16,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Status; -import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Type; import org.openhab.core.config.discovery.DiscoveryResultBuilder; import org.openhab.core.thing.ThingUID; import org.slf4j.Logger; @@ -42,13 +41,13 @@ public static PhoneConfigurationBuilder getInstance() { } public DiscoveryResultBuilder configure(ThingUID bridgeUID, Status config) { - ThingUID thingUID = new ThingUID(Type.DECT.equals(config.type()) ? THING_TYPE_DECT : THING_TYPE_FXS, bridgeUID, - Integer.toString(config.id())); + ThingUID thingUID = new ThingUID("dect".equalsIgnoreCase(config.type()) ? THING_TYPE_DECT : THING_TYPE_FXS, + bridgeUID, Integer.toString(config.id())); logger.debug("Adding new Freebox Phone {} to inbox", thingUID); return DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID) - .withProperty(ClientConfiguration.ID, config.id()).withLabel(config.type().name()) + .withProperty(ClientConfiguration.ID, config.id()).withLabel(config.type()) .withRepresentationProperty(ClientConfiguration.ID); } } From 63188490dc4142ff875f48cccfc0bb014a8714bb Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Sun, 18 Aug 2024 12:28:50 +0200 Subject: [PATCH 2/2] Keep enum in API response record DTO Signed-off-by: Laurent Garnier --- .../internal/api/rest/PhoneManager.java | 20 +++++++++++++++++-- .../config/PhoneConfigurationBuilder.java | 3 ++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java index 50b877a892dfc..067c531e83404 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java @@ -20,6 +20,8 @@ import org.openhab.binding.freeboxos.internal.api.FreeboxException; import org.openhab.binding.freeboxos.internal.api.Response; +import com.google.gson.annotations.SerializedName; + /** * The {@link PhoneManager} is the Java class used to handle api requests related to phone and calls * @@ -37,11 +39,25 @@ protected class ConfigResponse extends Response { protected class StatusResponse extends Response { } - public static record Config(String network, boolean dectEcoMode, String dectPin, int dectRingPattern, + private enum NetworkStatus { + @SerializedName("working") + WORKING, + UNKNOWN + } + + public static record Config(NetworkStatus network, boolean dectEcoMode, String dectPin, int dectRingPattern, boolean dectRegistration, boolean dectNemoMode, boolean dectEnabled, boolean dectRingOnOff) { } - public static record Status(int id, boolean isRinging, boolean onHook, boolean hardwareDefect, String type, + public enum Type { + @SerializedName("fxs") + FXS, + @SerializedName("dect") + DECT, + UNKNOWN + } + + public static record Status(int id, boolean isRinging, boolean onHook, boolean hardwareDefect, Type type, @Nullable String vendor, int gainRx, int gainTx) { public String vendor() { diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java index bb678e501785c..a474b4c59a37a 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/config/PhoneConfigurationBuilder.java @@ -16,6 +16,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Status; +import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Type; import org.openhab.core.config.discovery.DiscoveryResultBuilder; import org.openhab.core.thing.ThingUID; import org.slf4j.Logger; @@ -43,7 +44,7 @@ public static PhoneConfigurationBuilder getInstance() { public DiscoveryResultBuilder configure(ThingUID bridgeUID, Status config) { ThingUID thingUID; String label; - if ("dect".equalsIgnoreCase(config.type())) { + if (Type.DECT.equals(config.type())) { thingUID = new ThingUID(THING_TYPE_DECT, bridgeUID, Integer.toString(config.id())); label = "DECT Phone"; } else {