]> git.basschouten.com Git - openhab-addons.git/commitdiff
[sonyprojector] Allow translation of exception messages that can be d… (#11392)
authorlolodomo <lg.hc@free.fr>
Fri, 12 Nov 2021 23:29:32 +0000 (00:29 +0100)
committerGitHub <noreply@github.com>
Fri, 12 Nov 2021 23:29:32 +0000 (00:29 +0100)
* [sonyprojector] Allow translation of exception messages that can be displayed in MainUI

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
13 files changed:
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/SonyProjectorException.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/SonyProjectorHandlerFactory.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/communication/SonyProjectorConnector.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/communication/sdcp/SonyProjectorSdcpConnector.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/communication/sdcp/SonyProjectorSdcpError.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/communication/sdcp/SonyProjectorSdcpSimuConnector.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/communication/serial/SonyProjectorSerialConnector.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/communication/serial/SonyProjectorSerialError.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/communication/serial/SonyProjectorSerialOverIpConnector.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/communication/serial/SonyProjectorSerialSimuConnector.java
bundles/org.openhab.binding.sonyprojector/src/main/java/org/openhab/binding/sonyprojector/internal/handler/SonyProjectorHandler.java
bundles/org.openhab.binding.sonyprojector/src/main/resources/OH-INF/i18n/sonyprojector.properties
bundles/org.openhab.binding.sonyprojector/src/main/resources/OH-INF/i18n/sonyprojector_fr.properties

index 6743dd761a595aceab3f95f607a7ef83fc08dcd8..8d30601f7aaf1b037366213727e898e01d361cbc 100644 (file)
@@ -13,7 +13,6 @@
 package org.openhab.binding.sonyprojector.internal;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
 
 /**
  * The {@link SonyProjectorException} class is used for any exception thrown by the binding
@@ -21,15 +20,15 @@ import org.eclipse.jdt.annotation.Nullable;
  * @author Markus Wehrle - Initial contribution
  */
 @NonNullByDefault
-public class SonyProjectorException extends Exception {
+public class SonyProjectorException extends RuntimeException {
+
     private static final long serialVersionUID = 1L;
 
-    // Parameterless Constructor
-    public SonyProjectorException() {
+    public SonyProjectorException(String message) {
+        super(message);
     }
 
-    // Constructor that accepts a message
-    public SonyProjectorException(@Nullable String message) {
-        super(message);
+    public SonyProjectorException(String message, Throwable cause) {
+        super(message, cause);
     }
 }
index ad85245fcf8863d63e192d31e5db551d9865d073..c830dec372164645aae241b5631d32aec704a540 100644 (file)
@@ -22,6 +22,7 @@ import java.util.stream.Stream;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.sonyprojector.internal.handler.SonyProjectorHandler;
+import org.openhab.core.i18n.TranslationProvider;
 import org.openhab.core.io.transport.serial.SerialPortManager;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingTypeUID;
@@ -49,12 +50,15 @@ public class SonyProjectorHandlerFactory extends BaseThingHandlerFactory {
     private final SerialPortManager serialPortManager;
 
     private final SonyProjectorStateDescriptionOptionProvider stateDescriptionProvider;
+    private final TranslationProvider i18nProvider;
 
     @Activate
     public SonyProjectorHandlerFactory(final @Reference SerialPortManager serialPortManager,
-            final @Reference SonyProjectorStateDescriptionOptionProvider stateDescriptionProvider) {
+            final @Reference SonyProjectorStateDescriptionOptionProvider stateDescriptionProvider,
+            final @Reference TranslationProvider i18nProvider) {
         this.serialPortManager = serialPortManager;
         this.stateDescriptionProvider = stateDescriptionProvider;
+        this.i18nProvider = i18nProvider;
     }
 
     @Override
@@ -67,7 +71,7 @@ public class SonyProjectorHandlerFactory extends BaseThingHandlerFactory {
         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
 
         if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
-            return new SonyProjectorHandler(thing, stateDescriptionProvider, serialPortManager);
+            return new SonyProjectorHandler(thing, stateDescriptionProvider, serialPortManager, i18nProvider);
         }
 
         return null;
index c319217ade22aa343869583157d632ab38c496fa..1e022d774a3bcf1d2b033c5890d653734b0214ea 100644 (file)
@@ -21,6 +21,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
 import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConnectionException;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.util.HexUtils;
 import org.slf4j.Logger;
@@ -86,7 +88,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current power status
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public SonyProjectorStatusPower getStatusPower() throws SonyProjectorException {
         return SonyProjectorStatusPower.getFromDataCode(getSetting(SonyProjectorItem.STATUS_POWER));
@@ -95,7 +97,7 @@ public abstract class SonyProjectorConnector {
     /**
      * Power ON the projector
      *
-     * @throws SonyProjectorException - In case the projector is not ready for a power ON command or any other problem
+     * @throws SonyProjectorException in case the projector is not ready for a power ON command or any other problem
      */
     public void powerOn() throws SonyProjectorException {
         SonyProjectorStatusPower status = null;
@@ -121,7 +123,7 @@ public abstract class SonyProjectorConnector {
     /**
      * Power OFF the projector
      *
-     * @throws SonyProjectorException - In case the projector is not ready for a power OFF command or any other problem
+     * @throws SonyProjectorException in case the projector is not ready for a power OFF command or any other problem
      */
     public void powerOff() throws SonyProjectorException {
         SonyProjectorStatusPower status = null;
@@ -146,7 +148,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current calibration preset
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getCalibrationPreset() throws SonyProjectorException {
         return model.getCalibrPresetNameFromDataCode(getSetting(SonyProjectorItem.CALIBRATION_PRESET));
@@ -157,7 +159,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the calibration preset to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setCalibrationPreset(String value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.CALIBRATION_PRESET, model.getCalibrPresetDataCodeFromName(value));
@@ -168,7 +170,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current video input
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getInput() throws SonyProjectorException {
         return model.getInputNameFromDataCode(getSetting(SonyProjectorItem.INPUT));
@@ -179,7 +181,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the video input to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setInput(String value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.INPUT, model.getInputDataCodeFromName(value));
@@ -190,7 +192,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current contrast value
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public int getContrast() throws SonyProjectorException {
         return convertDataToInt(getSetting(SonyProjectorItem.CONTRAST));
@@ -201,7 +203,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the contrast value to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setContrast(int value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.CONTRAST, convertIntToData(value));
@@ -212,7 +214,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current brightness value
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public int getBrightness() throws SonyProjectorException {
         return convertDataToInt(getSetting(SonyProjectorItem.BRIGHTNESS));
@@ -223,7 +225,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the brightness value to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setBrightness(int value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.BRIGHTNESS, convertIntToData(value));
@@ -234,7 +236,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current color value
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public int getColor() throws SonyProjectorException {
         return convertDataToInt(getSetting(SonyProjectorItem.COLOR));
@@ -245,7 +247,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the color value to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setColor(int value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.COLOR, convertIntToData(value));
@@ -256,7 +258,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current hue value
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public int getHue() throws SonyProjectorException {
         return convertDataToInt(getSetting(SonyProjectorItem.HUE));
@@ -267,7 +269,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the hue value to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setHue(int value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.HUE, convertIntToData(value));
@@ -278,7 +280,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current sharpness value
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public int getSharpness() throws SonyProjectorException {
         return convertDataToInt(getSetting(SonyProjectorItem.SHARPNESS));
@@ -289,7 +291,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the sharpness value to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setSharpness(int value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.SHARPNESS, convertIntToData(value));
@@ -300,7 +302,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current contrast enhancer mode
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getContrastEnhancer() throws SonyProjectorException {
         return model.getContrastEnhancerNameFromDataCode(getSetting(SonyProjectorItem.CONTRAST_ENHANCER));
@@ -311,7 +313,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the contrast enhancer mode to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setContrastEnhancer(String value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.CONTRAST_ENHANCER, model.getContrastEnhancerDataCodeFromName(value));
@@ -322,7 +324,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current film mode
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public String getFilmMode() throws SonyProjectorException {
         if (!model.isFilmModeAvailable()) {
@@ -337,7 +339,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the film mode to set
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setFilmMode(String value) throws SonyProjectorException {
         if (!model.isFilmModeAvailable()) {
@@ -352,7 +354,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the lamp use time
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public int getLampUseTime() throws SonyProjectorException {
         return convertDataToInt(getSetting(SonyProjectorItem.LAMP_USE_TIME));
@@ -363,7 +365,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current mode for the lamp control setting
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public String getLampControl() throws SonyProjectorException {
         if (!model.isLampControlAvailable()) {
@@ -378,7 +380,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the mode to set for the lamp control setting
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setLampControl(String value) throws SonyProjectorException {
         if (!model.isLampControlAvailable()) {
@@ -393,7 +395,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return OnOffType.ON if the picture is muted, OnOffType.OFF if not
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public OnOffType getPictureMuting() throws SonyProjectorException {
         return Arrays.equals(getSetting(SonyProjectorItem.PICTURE_MUTING), PICTURE_ON) ? OnOffType.ON : OnOffType.OFF;
@@ -402,7 +404,7 @@ public abstract class SonyProjectorConnector {
     /**
      * Request the projector to mute the picture
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void mutePicture() throws SonyProjectorException {
         setSetting(SonyProjectorItem.PICTURE_MUTING, PICTURE_ON);
@@ -411,7 +413,7 @@ public abstract class SonyProjectorConnector {
     /**
      * Request the projector to unmute the picture
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void unmutePicture() throws SonyProjectorException {
         setSetting(SonyProjectorItem.PICTURE_MUTING, PICTURE_OFF);
@@ -422,7 +424,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current mode for the picture position setting
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public String getPicturePosition() throws SonyProjectorException {
         if (!model.isPicturePositionAvailable()) {
@@ -437,7 +439,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the mode to set for the picture position setting
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setPicturePosition(String value) throws SonyProjectorException {
         if (!model.isPicturePositionAvailable()) {
@@ -452,7 +454,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return OnOffType.ON if the overscan is enabled, OnOffType.OFF if not
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public OnOffType getOverscan() throws SonyProjectorException {
         if (!model.isOverscanAvailable()) {
@@ -465,7 +467,7 @@ public abstract class SonyProjectorConnector {
     /**
      * Request the projector to enable the overscan
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void enableOverscan() throws SonyProjectorException {
         if (!model.isOverscanAvailable()) {
@@ -478,7 +480,7 @@ public abstract class SonyProjectorConnector {
     /**
      * Request the projector to disable the overscan
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void disableOverscan() throws SonyProjectorException {
         if (!model.isOverscanAvailable()) {
@@ -493,7 +495,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current current aspect ratio mode
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getAspect() throws SonyProjectorException {
         return model.getAspectNameFromDataCode(getSetting(SonyProjectorItem.ASPECT));
@@ -504,7 +506,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the aspect ratio mode to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setAspect(String value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.ASPECT, model.getAspectCodeFromName(value));
@@ -515,7 +517,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current color temperature value
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getColorTemperature() throws SonyProjectorException {
         return model.getColorTempNameFromDataCode(getSetting(SonyProjectorItem.COLOR_TEMP));
@@ -526,7 +528,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the color temperature value to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setColorTemperature(String value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.COLOR_TEMP, model.getColorTempCodeFromName(value));
@@ -537,7 +539,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current iris mode
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public String getIrisMode() throws SonyProjectorException {
         if (!model.isIrisModeAvailable()) {
@@ -552,7 +554,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the iris mode to set
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setIrisMode(String value) throws SonyProjectorException {
         if (!model.isIrisModeAvailable()) {
@@ -567,7 +569,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current value for the iris manual setting
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public int getIrisManual() throws SonyProjectorException {
         if (!model.isIrisManualAvailable()) {
@@ -582,7 +584,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the iris manual value to set
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setIrisManual(int value) throws SonyProjectorException {
         if (!model.isIrisManualAvailable()) {
@@ -597,7 +599,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current iris sensitivity
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public String getIrisSensitivity() throws SonyProjectorException {
         if (!model.isIrisSensitivityAvailable()) {
@@ -612,7 +614,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the iris sensitivity to set
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setIrisSensitivity(String value) throws SonyProjectorException {
         if (!model.isIrisSensitivityAvailable()) {
@@ -627,7 +629,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current film projection mode
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public String getFilmProjection() throws SonyProjectorException {
         if (!model.isFilmProjectionAvailable()) {
@@ -642,7 +644,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the film projection mode to set
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setFilmProjection(String value) throws SonyProjectorException {
         if (!model.isFilmProjectionAvailable()) {
@@ -657,7 +659,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current motion enhancer mode
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getMotionEnhancer() throws SonyProjectorException {
         if (!model.isMotionEnhancerAvailable()) {
@@ -672,7 +674,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the motion enhancer mode to set
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setMotionEnhancer(String value) throws SonyProjectorException {
         if (!model.isMotionEnhancerAvailable()) {
@@ -687,7 +689,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current gamma correction
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getGammaCorrection() throws SonyProjectorException {
         return model.getGammaCorrectionNameFromDataCode(getSetting(SonyProjectorItem.GAMMA_CORRECTION));
@@ -698,7 +700,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the gamma correction to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setGammaCorrection(String value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.GAMMA_CORRECTION, model.getGammaCorrectionCodeFromName(value));
@@ -709,7 +711,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current color space
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getColorSpace() throws SonyProjectorException {
         return model.getColorSpaceNameFromDataCode(getSetting(SonyProjectorItem.COLOR_SPACE));
@@ -720,7 +722,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the color space to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setColorSpace(String value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.COLOR_SPACE, model.getColorSpaceCodeFromName(value));
@@ -731,7 +733,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current noise reduction mode
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getNr() throws SonyProjectorException {
         return model.getNrNameFromDataCode(getSetting(SonyProjectorItem.NR));
@@ -742,7 +744,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the noise reduction mode to set
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public void setNr(String value) throws SonyProjectorException {
         setSetting(SonyProjectorItem.NR, model.getNrCodeFromName(value));
@@ -753,7 +755,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current block noise reduction mode
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public String getBlockNr() throws SonyProjectorException {
         if (!model.isBlockNrAvailable()) {
@@ -768,7 +770,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the block noise reduction mode to set
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setBlockNr(String value) throws SonyProjectorException {
         if (!model.isBlockNrAvailable()) {
@@ -783,7 +785,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current mosquito noise reduction mode
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public String getMosquitoNr() throws SonyProjectorException {
         if (!model.isMosquitoNrAvailable()) {
@@ -798,7 +800,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the mosquito noise reduction mode to set
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setMosquitoNr(String value) throws SonyProjectorException {
         if (!model.isMosquitoNrAvailable()) {
@@ -813,7 +815,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current MPEG noise reduction mode
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public String getMpegNr() throws SonyProjectorException {
         if (!model.isMpegNrAvailable()) {
@@ -828,7 +830,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param value the MPEG noise reduction mode to set
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void setMpegNr(String value) throws SonyProjectorException {
         if (!model.isMpegNrAvailable()) {
@@ -843,7 +845,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current value for xvColor
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public OnOffType getXvColor() throws SonyProjectorException {
         if (!model.isXvColorAvailable()) {
@@ -856,7 +858,7 @@ public abstract class SonyProjectorConnector {
     /**
      * Request the projector to set xvColor to ON
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void enableXvColor() throws SonyProjectorException {
         if (!model.isXvColorAvailable()) {
@@ -869,7 +871,7 @@ public abstract class SonyProjectorConnector {
     /**
      * Request the projector to set xvColor to OFF
      *
-     * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+     * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
      */
     public void disableXvColor() throws SonyProjectorException {
         if (!model.isXvColorAvailable()) {
@@ -886,7 +888,7 @@ public abstract class SonyProjectorConnector {
      *
      * @return the current value for the setting
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     protected byte[] getSetting(SonyProjectorItem item) throws SonyProjectorException {
         logger.debug("Get setting {}", item.getName());
@@ -897,9 +899,8 @@ public abstract class SonyProjectorConnector {
             logger.debug("Get setting {} succeeded: result data: {}", item.getName(), HexUtils.bytesToHex(result));
 
             return result;
-        } catch (SonyProjectorException e) {
-            logger.debug("Get setting {} failed: {}", item.getName(), e.getMessage());
-            throw new SonyProjectorException("Get setting " + item.getName() + " failed: " + e.getMessage());
+        } catch (CommunicationException e) {
+            throw new SonyProjectorException("Get setting " + item.getName() + " failed", e);
         }
     }
 
@@ -909,16 +910,15 @@ public abstract class SonyProjectorConnector {
      * @param item the projector setting to set
      * @param data the value to set for the setting
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     private void setSetting(SonyProjectorItem item, byte[] data) throws SonyProjectorException {
         logger.debug("Set setting {} data {}", item.getName(), HexUtils.bytesToHex(data));
 
         try {
             executeCommand(item, false, data);
-        } catch (SonyProjectorException e) {
-            logger.debug("Set setting {} failed: {}", item.getName(), e.getMessage());
-            throw new SonyProjectorException("Set setting " + item.getName() + " failed: " + e.getMessage());
+        } catch (CommunicationException e) {
+            throw new SonyProjectorException("Set setting " + item.getName() + " failed", e);
         }
 
         logger.debug("Set setting {} succeeded", item.getName());
@@ -929,7 +929,7 @@ public abstract class SonyProjectorConnector {
      *
      * @param item the IR information to send
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     private synchronized void sendIR(SonyProjectorItem item) throws SonyProjectorException {
         logger.debug("Send IR {}", item.getName());
@@ -950,13 +950,11 @@ public abstract class SonyProjectorConnector {
             if (!runningSession) {
                 close();
             }
-        } catch (SonyProjectorException e) {
-            logger.debug("Send IR {} failed: {}", item.getName(), e.getMessage());
-            throw new SonyProjectorException("Send IR " + item.getName() + " failed: " + e.getMessage());
+        } catch (CommunicationException e) {
+            throw new SonyProjectorException("Send IR " + item.getName() + " failed", e);
         } catch (InterruptedException e) {
-            logger.debug("Send IR {} interrupted: {}", item.getName(), e.getMessage());
             Thread.currentThread().interrupt();
-            throw new SonyProjectorException("Send IR " + item.getName() + " interrupted: " + e.getMessage());
+            throw new SonyProjectorException("Send IR " + item.getName() + " interrupted", e);
         }
 
         logger.debug("Send IR {} succeeded", item.getName());
@@ -971,40 +969,37 @@ public abstract class SonyProjectorConnector {
      *
      * @return the buffer containing the returned message
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws ConnectionException in case of any connection problem
+     * @throws CommunicationException in case of any communication problem
      */
     private synchronized byte[] executeCommand(SonyProjectorItem item, boolean getCommand, byte[] data)
-            throws SonyProjectorException {
-        try {
-            boolean runningSession = connected;
+            throws ConnectionException, CommunicationException {
+        boolean runningSession = connected;
 
-            open();
+        open();
 
-            // Build the message and send it
-            writeCommand(buildMessage(item, getCommand, data));
+        // Build the message and send it
+        writeCommand(buildMessage(item, getCommand, data));
 
-            // Read the response
-            byte[] responseMessage = readResponse();
+        // Read the response
+        byte[] responseMessage = readResponse();
 
-            if (!runningSession) {
-                close();
-            }
+        if (!runningSession) {
+            close();
+        }
 
-            // Validate the content of the response
-            validateResponse(responseMessage, item);
+        // Validate the content of the response
+        validateResponse(responseMessage, item);
 
-            return responseMessage;
-        } catch (SonyProjectorException e) {
-            throw new SonyProjectorException(e.getMessage());
-        }
+        return responseMessage;
     }
 
     /**
      * Open the connection with the projector if not yet opened
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws ConnectionException in case of any problem
      */
-    public abstract void open() throws SonyProjectorException;
+    public abstract void open() throws ConnectionException;
 
     /**
      * Close the connection with the projector
@@ -1049,23 +1044,23 @@ public abstract class SonyProjectorConnector {
      * @param dataBuffer the buffer into which the data is read.
      * @return the total number of bytes read into the buffer, or -1 if there is no more data because the end of the
      *         stream has been reached.
-     * @throws SonyProjectorException - If the input stream is null, if the first byte cannot be read for any reason
+     * @throws CommunicationException if the input stream is null, if the first byte cannot be read for any reason
      *             other than the end of the file, if the input stream has been closed, or if some other I/O error
      *             occurs.
      */
-    protected int readInput(byte[] dataBuffer) throws SonyProjectorException {
+    protected int readInput(byte[] dataBuffer) throws CommunicationException {
         if (simu) {
-            throw new SonyProjectorException("readInput failed: should not be called in simu mode");
+            throw new CommunicationException("readInput failed: should not be called in simu mode");
         }
         InputStream dataIn = this.dataIn;
         if (dataIn == null) {
-            throw new SonyProjectorException("readInput failed: input stream is null");
+            throw new CommunicationException("readInput failed: input stream is null");
         }
         try {
             return dataIn.read(dataBuffer);
         } catch (IOException e) {
             logger.debug("readInput failed: {}", e.getMessage());
-            throw new SonyProjectorException("readInput failed: " + e.getMessage());
+            throw new CommunicationException("readInput failed", e);
         }
     }
 
@@ -1074,23 +1069,23 @@ public abstract class SonyProjectorConnector {
      *
      * @param message the buffer containing the message to be sent
      *
-     * @throws SonyProjectorException - In case of any communication problem
+     * @throws CommunicationException in case of any communication problem
      */
-    protected void writeCommand(byte[] message) throws SonyProjectorException {
+    protected void writeCommand(byte[] message) throws CommunicationException {
         logger.debug("writeCommand: {}", HexUtils.bytesToHex(message));
         if (simu) {
             return;
         }
         OutputStream dataOut = this.dataOut;
         if (dataOut == null) {
-            throw new SonyProjectorException("writeCommand failed: output stream is null");
+            throw new CommunicationException("writeCommand failed: output stream is null");
         }
         try {
             dataOut.write(message);
             dataOut.flush();
         } catch (IOException e) {
             logger.debug("writeCommand failed: {}", e.getMessage());
-            throw new SonyProjectorException("writeCommand failed: " + e.getMessage());
+            throw new CommunicationException("writeCommand failed", e);
         }
     }
 
@@ -1099,9 +1094,9 @@ public abstract class SonyProjectorConnector {
      *
      * @return the buffer containing the returned message
      *
-     * @throws SonyProjectorException - In case of any communication problem
+     * @throws CommunicationException in case of any communication problem
      */
-    protected abstract byte[] readResponse() throws SonyProjectorException;
+    protected abstract byte[] readResponse() throws CommunicationException;
 
     /**
      * Validate the content of a returned message
@@ -1109,10 +1104,10 @@ public abstract class SonyProjectorConnector {
      * @param responseMessage the buffer containing the returned message
      * @param the projector setting to get or set
      *
-     * @throws SonyProjectorException - If the message has unexpected content
+     * @throws CommunicationException if the message has unexpected content
      */
     protected abstract void validateResponse(byte[] responseMessage, SonyProjectorItem item)
-            throws SonyProjectorException;
+            throws CommunicationException;
 
     /**
      * Extract the value from the returned message
index 21d7a394177917ac489594776cc0279f5bc5025a..4d86e9fab5e0c6681c419bd5f8670339445807d6 100644 (file)
@@ -28,6 +28,8 @@ import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
 import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorConnector;
 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorItem;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConnectionException;
 import org.openhab.core.util.HexUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -114,7 +116,7 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
     }
 
     @Override
-    public synchronized void open() throws SonyProjectorException {
+    public synchronized void open() throws ConnectionException {
         if (!connected) {
             logger.debug("Opening SDCP connection IP {} port {}", this.address, this.port);
             try {
@@ -130,8 +132,7 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
 
                 logger.debug("SDCP connection opened");
             } catch (IOException | SecurityException | IllegalArgumentException e) {
-                logger.debug("Opening SDCP connection failed: {}", e.getMessage());
-                throw new SonyProjectorException("Opening SDCP connection failed: " + e.getMessage());
+                throw new ConnectionException("@text/exception.opening-sdcp-connection-failed", e);
             }
         }
     }
@@ -181,15 +182,15 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
      * @param dataBuffer the buffer into which the data is read.
      * @return the total number of bytes read into the buffer, or -1 if there is no more data because the end of the
      *         stream has been reached.
-     * @throws SonyProjectorException - If the input stream is null, if the first byte cannot be read for any reason
+     * @throws CommunicationException if the input stream is null, if the first byte cannot be read for any reason
      *             other than the end of the file, if the input stream has been closed, or if some other I/O error
      *             occurs.
      */
     @Override
-    protected int readInput(byte[] dataBuffer) throws SonyProjectorException {
+    protected int readInput(byte[] dataBuffer) throws CommunicationException {
         InputStream dataIn = this.dataIn;
         if (dataIn == null) {
-            throw new SonyProjectorException("readInput failed: input stream is null");
+            throw new CommunicationException("readInput failed: input stream is null");
         }
         try {
             return dataIn.read(dataBuffer);
@@ -197,12 +198,12 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
             return 0;
         } catch (IOException e) {
             logger.debug("readInput failed: {}", e.getMessage());
-            throw new SonyProjectorException("readInput failed: " + e.getMessage());
+            throw new CommunicationException("readInput failed", e);
         }
     }
 
     @Override
-    protected synchronized byte[] readResponse() throws SonyProjectorException {
+    protected synchronized byte[] readResponse() throws CommunicationException {
         logger.debug("readResponse (timeout = {} ms)...", READ_TIMEOUT_MS);
         byte[] message = new byte[MSG_MAX_SIZE];
         boolean timeout = false;
@@ -222,22 +223,22 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
         }
         if ((count < MSG_MIN_SIZE) && timeout) {
             logger.debug("readResponse timeout: only {} bytes read after {} ms", count, READ_TIMEOUT_MS);
-            throw new SonyProjectorException("readResponse failed: timeout");
+            throw new CommunicationException("readResponse failed: timeout");
         }
         logger.debug("readResponse: {}", HexUtils.bytesToHex(message));
         if (count < MSG_MIN_SIZE) {
             logger.debug("readResponse: unexpected response data length: {}", count);
-            throw new SonyProjectorException("Unexpected response data length");
+            throw new CommunicationException("Unexpected response data length");
         }
         return message;
     }
 
     @Override
-    protected void validateResponse(byte[] responseMessage, SonyProjectorItem item) throws SonyProjectorException {
+    protected void validateResponse(byte[] responseMessage, SonyProjectorItem item) throws CommunicationException {
         // Check response size
         if (responseMessage.length < MSG_MIN_SIZE) {
             logger.debug("Unexpected response data length: {}", responseMessage.length);
-            throw new SonyProjectorException("Unexpected response data length");
+            throw new CommunicationException("Unexpected response data length");
         }
 
         // Header should be a sony projector header
@@ -245,7 +246,7 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
         if (!Arrays.equals(headerMsg, HEADER)) {
             logger.debug("Unexpected HEADER in response: {} rather than {}", HexUtils.bytesToHex(headerMsg),
                     HexUtils.bytesToHex(HEADER));
-            throw new SonyProjectorException("Unexpected HEADER in response");
+            throw new CommunicationException("Unexpected HEADER in response");
         }
 
         // Community should be the same as used for sending
@@ -253,7 +254,7 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
         if (!Arrays.equals(communityResponseMsg, community.getBytes())) {
             logger.debug("Unexpected community in response: {} rather than {}",
                     HexUtils.bytesToHex(communityResponseMsg), HexUtils.bytesToHex(community.getBytes()));
-            throw new SonyProjectorException("Unexpected community in response");
+            throw new CommunicationException("Unexpected community in response");
         }
 
         // Item number should be the same as used for sending
@@ -261,14 +262,14 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
         if (!Arrays.equals(itemResponseMsg, item.getCode())) {
             logger.debug("Unexpected item number in response: {} rather than {}", HexUtils.bytesToHex(itemResponseMsg),
                     HexUtils.bytesToHex(item.getCode()));
-            throw new SonyProjectorException("Unexpected item number in response");
+            throw new CommunicationException("Unexpected item number in response");
         }
 
         // Check response size
         int dataLength = responseMessage[9] & 0x000000FF;
         if (responseMessage.length < (10 + dataLength)) {
             logger.debug("Unexpected response data length: {}", dataLength);
-            throw new SonyProjectorException("Unexpected response data length");
+            throw new CommunicationException("Unexpected response data length");
         }
 
         // byte 7 is expected to be 1, which indicates that the request was successful
@@ -279,11 +280,11 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
                 try {
                     SonyProjectorSdcpError error = SonyProjectorSdcpError.getFromDataCode(errorCode);
                     msg = error.getMessage();
-                } catch (SonyProjectorException e) {
+                } catch (CommunicationException e) {
                 }
             }
             logger.debug("{} received in response", msg);
-            throw new SonyProjectorException(msg + " received in response");
+            throw new CommunicationException(msg + " received in response");
         }
     }
 
@@ -303,7 +304,7 @@ public class SonyProjectorSdcpConnector extends SonyProjectorConnector {
      *
      * @return the model name
      *
-     * @throws SonyProjectorException - In case of any problem
+     * @throws SonyProjectorException in case of any problem
      */
     public String getModelName() throws SonyProjectorException {
         return new String(getSetting(SonyProjectorItem.MODEL_NAME), StandardCharsets.UTF_8);
index 4520f182d49e1bf19a11ae7f19de3d0c9112b22b..5f7a970eda553beff5c983ddbf21bef3c5f552ed 100644 (file)
@@ -15,7 +15,7 @@ package org.openhab.binding.sonyprojector.internal.communication.sdcp;
 import java.util.Arrays;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
+import org.openhab.core.i18n.CommunicationException;
 import org.openhab.core.util.HexUtils;
 
 /**
@@ -89,14 +89,14 @@ public enum SonyProjectorSdcpError {
      *
      * @return the error associated to the data code
      *
-     * @throws SonyProjectorException - If no error is associated to the data code
+     * @throws CommunicationException if no error is associated to the data code
      */
-    public static SonyProjectorSdcpError getFromDataCode(byte[] dataCode) throws SonyProjectorException {
+    public static SonyProjectorSdcpError getFromDataCode(byte[] dataCode) throws CommunicationException {
         for (SonyProjectorSdcpError value : SonyProjectorSdcpError.values()) {
             if (Arrays.equals(dataCode, value.getDataCode())) {
                 return value;
             }
         }
-        throw new SonyProjectorException("Unknwon error code: " + HexUtils.bytesToHex(dataCode));
+        throw new CommunicationException("Unknwon error code: " + HexUtils.bytesToHex(dataCode));
     }
 }
index 608882e45dd4f8d94f7965e044931021dc61e283..4aadd64fd69c125e4517a2257fed24979e31df7e 100644 (file)
 package org.openhab.binding.sonyprojector.internal.communication.sdcp;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
 import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorItem;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConnectionException;
 import org.openhab.core.util.HexUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,7 +45,7 @@ public class SonyProjectorSdcpSimuConnector extends SonyProjectorSdcpConnector {
     }
 
     @Override
-    public synchronized void open() throws SonyProjectorException {
+    public synchronized void open() throws ConnectionException {
         if (!connected) {
             connected = true;
             logger.debug("Simulated SDCP connection opened");
@@ -66,7 +67,7 @@ public class SonyProjectorSdcpSimuConnector extends SonyProjectorSdcpConnector {
     }
 
     @Override
-    protected synchronized byte[] readResponse() throws SonyProjectorException {
+    protected synchronized byte[] readResponse() throws CommunicationException {
         byte[] message = new byte[34];
         byte[] communityData = getCommunity().getBytes();
         message[0] = HEADER[0];
index 673c86182d18470d369039a188aaca019fa8d5d3..f99f799dc80cccf5fc077f770bff0473e8846c5a 100644 (file)
@@ -15,17 +15,17 @@ package org.openhab.binding.sonyprojector.internal.communication.serial;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
 import java.util.TooManyListenersException;
 import java.util.concurrent.TimeUnit;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
 import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorConnector;
 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorItem;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConnectionException;
 import org.openhab.core.io.transport.serial.PortInUseException;
 import org.openhab.core.io.transport.serial.SerialPort;
 import org.openhab.core.io.transport.serial.SerialPortEvent;
@@ -91,14 +91,13 @@ public class SonyProjectorSerialConnector extends SonyProjectorConnector impleme
     }
 
     @Override
-    public synchronized void open() throws SonyProjectorException {
+    public synchronized void open() throws ConnectionException {
         if (!connected) {
             logger.debug("Opening serial connection on port {}", serialPortName);
             try {
                 SerialPortIdentifier portIdentifier = serialPortManager.getIdentifier(serialPortName);
                 if (portIdentifier == null) {
-                    logger.debug("Opening serial connection failed: No Such Port: {}", serialPortName);
-                    throw new SonyProjectorException("Opening serial connection failed: No Such Port");
+                    throw new ConnectionException("@text/exception.invalid-serial-port", serialPortName);
                 }
 
                 SerialPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
@@ -139,20 +138,8 @@ public class SonyProjectorSerialConnector extends SonyProjectorConnector impleme
                 connected = true;
 
                 logger.debug("Serial connection opened");
-            } catch (PortInUseException e) {
-                logger.debug("Opening serial connection failed: Port in Use Exception: {}", e.getMessage(), e);
-                throw new SonyProjectorException("Opening serial connection failed: Port in Use Exception");
-            } catch (UnsupportedCommOperationException e) {
-                logger.debug("Opening serial connection failed: Unsupported Comm Operation Exception: {}",
-                        e.getMessage(), e);
-                throw new SonyProjectorException(
-                        "Opening serial connection failed: Unsupported Comm Operation Exception");
-            } catch (UnsupportedEncodingException e) {
-                logger.debug("Opening serial connection failed: Unsupported Encoding Exception: {}", e.getMessage(), e);
-                throw new SonyProjectorException("Opening serial connection failed: Unsupported Encoding Exception");
-            } catch (IOException e) {
-                logger.debug("Opening serial connection failed: IO Exception: {}", e.getMessage(), e);
-                throw new SonyProjectorException("Opening serial connection failed: IO Exception");
+            } catch (PortInUseException | UnsupportedCommOperationException | IOException e) {
+                throw new ConnectionException("@text/exception.opening-serial-connection-failed", e);
             }
         }
     }
@@ -189,7 +176,7 @@ public class SonyProjectorSerialConnector extends SonyProjectorConnector impleme
     }
 
     @Override
-    protected synchronized byte[] readResponse() throws SonyProjectorException {
+    protected synchronized byte[] readResponse() throws CommunicationException {
         logger.debug("readResponse (timeout = {} ms)...", READ_TIMEOUT_MS);
         byte[] message = new byte[8];
         boolean startCodeReached = false;
@@ -221,7 +208,7 @@ public class SonyProjectorSerialConnector extends SonyProjectorConnector impleme
         }
         if (!endCodeReached && timeout) {
             logger.debug("readResponse timeout: only {} bytes read after {} ms", index, READ_TIMEOUT_MS);
-            throw new SonyProjectorException("readResponse failed: timeout");
+            throw new CommunicationException("readResponse failed: timeout");
         }
         logger.debug("readResponse: {}", HexUtils.bytesToHex(message));
 
@@ -229,31 +216,31 @@ public class SonyProjectorSerialConnector extends SonyProjectorConnector impleme
     }
 
     @Override
-    protected void validateResponse(byte[] responseMessage, SonyProjectorItem item) throws SonyProjectorException {
+    protected void validateResponse(byte[] responseMessage, SonyProjectorItem item) throws CommunicationException {
         if (responseMessage.length != 8) {
             logger.debug("Unexpected response data length: {}", responseMessage.length);
-            throw new SonyProjectorException("Unexpected response data length");
+            throw new CommunicationException("Unexpected response data length");
         }
 
         // Check START CODE
         if (responseMessage[0] != START_CODE) {
             logger.debug("Unexpected message START CODE in response: {} rather than {}",
                     Integer.toHexString(responseMessage[0] & 0x000000FF), Integer.toHexString(START_CODE & 0x000000FF));
-            throw new SonyProjectorException("Unexpected message START CODE in response");
+            throw new CommunicationException("Unexpected message START CODE in response");
         }
 
         // Check END CODE
         if (responseMessage[7] != END_CODE) {
             logger.debug("Unexpected  message END CODE in response: {} rather than {}",
                     Integer.toHexString(responseMessage[7] & 0x000000FF), Integer.toHexString(END_CODE & 0x000000FF));
-            throw new SonyProjectorException("Unexpected message END CODE in response");
+            throw new CommunicationException("Unexpected message END CODE in response");
         }
 
         byte checksum = computeCheckSum(responseMessage);
         if (responseMessage[6] != checksum) {
             logger.debug("Invalid check sum in response: {} rather than {}",
                     Integer.toHexString(responseMessage[6] & 0x000000FF), Integer.toHexString(checksum & 0x000000FF));
-            throw new SonyProjectorException("Invalid check sum in response");
+            throw new CommunicationException("Invalid check sum in response");
         }
 
         if (responseMessage[3] == TYPE_ITEM) {
@@ -262,7 +249,7 @@ public class SonyProjectorSerialConnector extends SonyProjectorConnector impleme
             if (!Arrays.equals(itemResponseMsg, item.getCode())) {
                 logger.debug("Unexpected item number in response: {} rather than {}",
                         HexUtils.bytesToHex(itemResponseMsg), HexUtils.bytesToHex(item.getCode()));
-                throw new SonyProjectorException("Unexpected item number in response");
+                throw new CommunicationException("Unexpected item number in response");
             }
         } else if (responseMessage[3] == TYPE_ACK) {
             // ACK
@@ -272,14 +259,14 @@ public class SonyProjectorSerialConnector extends SonyProjectorConnector impleme
                 try {
                     SonyProjectorSerialError error = SonyProjectorSerialError.getFromDataCode(errorCode);
                     msg = error.getMessage();
-                } catch (SonyProjectorException e) {
+                } catch (CommunicationException e) {
                 }
                 logger.debug("{} received in response", msg);
-                throw new SonyProjectorException(msg + " received in response");
+                throw new CommunicationException(msg + " received in response");
             }
         } else {
             logger.debug("Unexpected TYPE in response: {}", Integer.toHexString(responseMessage[3] & 0x000000FF));
-            throw new SonyProjectorException("Unexpected TYPE in response");
+            throw new CommunicationException("Unexpected TYPE in response");
         }
     }
 
index 79a5ea4d0fcd936930ac35c91788b42184f36cc1..4baa5712ca8220cf40e539579d46bba267bacb73 100644 (file)
@@ -15,7 +15,7 @@ package org.openhab.binding.sonyprojector.internal.communication.serial;
 import java.util.Arrays;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
+import org.openhab.core.i18n.CommunicationException;
 import org.openhab.core.util.HexUtils;
 
 /**
@@ -77,14 +77,14 @@ public enum SonyProjectorSerialError {
      *
      * @return the error associated to the searched data code
      *
-     * @throws SonyProjectorException - If no error is associated to the searched data code
+     * @throws CommunicationException if no error is associated to the searched data code
      */
-    public static SonyProjectorSerialError getFromDataCode(byte[] dataCode) throws SonyProjectorException {
+    public static SonyProjectorSerialError getFromDataCode(byte[] dataCode) throws CommunicationException {
         for (SonyProjectorSerialError value : SonyProjectorSerialError.values()) {
             if (Arrays.equals(dataCode, value.getDataCode())) {
                 return value;
             }
         }
-        throw new SonyProjectorException("Unknwon error code: " + HexUtils.bytesToHex(dataCode));
+        throw new CommunicationException("Unknwon error code: " + HexUtils.bytesToHex(dataCode));
     }
 }
index 6487941b0b89b1ba7cbbdd44862502e94f973783..749f3ed11d1d2856bb36f370b2d18291a601f36b 100644 (file)
@@ -21,8 +21,9 @@ import java.net.SocketTimeoutException;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
 import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConnectionException;
 import org.openhab.core.io.transport.serial.SerialPortManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -59,7 +60,7 @@ public class SonyProjectorSerialOverIpConnector extends SonyProjectorSerialConne
     }
 
     @Override
-    public synchronized void open() throws SonyProjectorException {
+    public synchronized void open() throws ConnectionException {
         if (!connected) {
             logger.debug("Opening serial over IP connection on IP {} port {}", this.address, this.port);
             try {
@@ -75,8 +76,7 @@ public class SonyProjectorSerialOverIpConnector extends SonyProjectorSerialConne
 
                 logger.debug("Serial over IP connection opened");
             } catch (IOException | SecurityException | IllegalArgumentException e) {
-                logger.debug("Opening serial over IP connection failed: {}", e.getMessage());
-                throw new SonyProjectorException("Opening serial over IP connection failed: " + e.getMessage());
+                throw new ConnectionException("@text/exception.opening-serial-over-ip-connection-failed", e);
             }
         }
     }
@@ -106,15 +106,15 @@ public class SonyProjectorSerialOverIpConnector extends SonyProjectorSerialConne
      * @param dataBuffer the buffer into which the data is read.
      * @return the total number of bytes read into the buffer, or -1 if there is no more data because the end of the
      *         stream has been reached.
-     * @throws SonyProjectorException - If the input stream is null, if the first byte cannot be read for any reason
+     * @throws CommunicationException if the input stream is null, if the first byte cannot be read for any reason
      *             other than the end of the file, if the input stream has been closed, or if some other I/O error
      *             occurs.
      */
     @Override
-    protected int readInput(byte[] dataBuffer) throws SonyProjectorException {
+    protected int readInput(byte[] dataBuffer) throws CommunicationException {
         InputStream dataIn = this.dataIn;
         if (dataIn == null) {
-            throw new SonyProjectorException("readInput failed: input stream is null");
+            throw new CommunicationException("readInput failed: input stream is null");
         }
         try {
             return dataIn.read(dataBuffer);
@@ -122,7 +122,7 @@ public class SonyProjectorSerialOverIpConnector extends SonyProjectorSerialConne
             return 0;
         } catch (IOException e) {
             logger.debug("readInput failed: {}", e.getMessage());
-            throw new SonyProjectorException("readInput failed: " + e.getMessage());
+            throw new CommunicationException("readInput failed", e);
         }
     }
 }
index 43cfeaf76c5ef80a61f6c81ffb6e54b5f31e200b..638c2e0006c30744d4d5ff25f672e97ad35a4634 100644 (file)
@@ -13,8 +13,9 @@
 package org.openhab.binding.sonyprojector.internal.communication.serial;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
 import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConnectionException;
 import org.openhab.core.io.transport.serial.SerialPortManager;
 import org.openhab.core.util.HexUtils;
 import org.slf4j.Logger;
@@ -41,7 +42,7 @@ public class SonyProjectorSerialSimuConnector extends SonyProjectorSerialConnect
     }
 
     @Override
-    public synchronized void open() throws SonyProjectorException {
+    public synchronized void open() throws ConnectionException {
         if (!connected) {
             connected = true;
             logger.debug("Simulated serial connection opened");
@@ -57,7 +58,7 @@ public class SonyProjectorSerialSimuConnector extends SonyProjectorSerialConnect
     }
 
     @Override
-    protected synchronized byte[] readResponse() throws SonyProjectorException {
+    protected synchronized byte[] readResponse() throws CommunicationException {
         byte[] message = new byte[8];
         message[0] = START_CODE;
         message[1] = SonyProjectorSerialError.COMPLETE.getDataCode()[0];
index d4d5f7996002e0ec64adca91e93d70c065bf08f8..916b16f01a18814bd354fbd013eb91f74afaf246 100644 (file)
@@ -33,6 +33,8 @@ import org.openhab.binding.sonyprojector.internal.configuration.SonyProjectorEth
 import org.openhab.binding.sonyprojector.internal.configuration.SonyProjectorSerialConfiguration;
 import org.openhab.binding.sonyprojector.internal.configuration.SonyProjectorSerialOverIpConfiguration;
 import org.openhab.core.cache.ExpiringCacheMap;
+import org.openhab.core.i18n.ConnectionException;
+import org.openhab.core.i18n.TranslationProvider;
 import org.openhab.core.io.transport.serial.SerialPortManager;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
@@ -47,6 +49,8 @@ import org.openhab.core.types.Command;
 import org.openhab.core.types.RefreshType;
 import org.openhab.core.types.State;
 import org.openhab.core.types.UnDefType;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -60,31 +64,36 @@ import org.slf4j.LoggerFactory;
 @NonNullByDefault
 public class SonyProjectorHandler extends BaseThingHandler {
 
-    private final Logger logger = LoggerFactory.getLogger(SonyProjectorHandler.class);
-
     private static final SonyProjectorModel DEFAULT_MODEL = SonyProjectorModel.VW520;
     private static final long POLLING_INTERVAL = TimeUnit.SECONDS.toSeconds(15);
 
+    private final Logger logger = LoggerFactory.getLogger(SonyProjectorHandler.class);
+
+    private final SonyProjectorStateDescriptionOptionProvider stateDescriptionProvider;
+    private final SerialPortManager serialPortManager;
+    private final TranslationProvider i18nProvider;
+
+    private final Bundle bundle;
+
+    private final ExpiringCacheMap<String, State> cache;
+
     private @Nullable ScheduledFuture<?> refreshJob;
 
     private boolean identifyProjector;
     private SonyProjectorModel projectorModel = DEFAULT_MODEL;
     private SonyProjectorConnector connector = new SonyProjectorSdcpSimuConnector(DEFAULT_MODEL);
 
-    private SonyProjectorStateDescriptionOptionProvider stateDescriptionProvider;
-    private SerialPortManager serialPortManager;
-
     private boolean simu;
 
     private final Object commandLock = new Object();
 
-    private final ExpiringCacheMap<String, State> cache;
-
     public SonyProjectorHandler(Thing thing, SonyProjectorStateDescriptionOptionProvider stateDescriptionProvider,
-            SerialPortManager serialPortManager) {
+            SerialPortManager serialPortManager, TranslationProvider i18nProvider) {
         super(thing);
         this.stateDescriptionProvider = stateDescriptionProvider;
         this.serialPortManager = serialPortManager;
+        this.i18nProvider = i18nProvider;
+        this.bundle = FrameworkUtil.getBundle(this.getClass());
         this.cache = new ExpiringCacheMap<>(TimeUnit.SECONDS.toMillis(POLLING_INTERVAL));
     }
 
@@ -102,9 +111,10 @@ public class SonyProjectorHandler extends BaseThingHandler {
         synchronized (commandLock) {
             try {
                 connector.open();
-            } catch (SonyProjectorException e) {
-                logger.debug("Command {} from channel {} failed: {}", command, channel, e.getMessage());
-                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
+            } catch (ConnectionException e) {
+                logger.debug("Command {} from channel {} failed: {}", command, channel,
+                        e.getMessage(bundle, i18nProvider));
+                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getRawMessage());
                 return;
             }
             try {
@@ -405,9 +415,9 @@ public class SonyProjectorHandler extends BaseThingHandler {
 
             try {
                 connector.open();
-            } catch (SonyProjectorException e) {
-                logger.debug("Poll projector failed: {}", e.getMessage());
-                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
+            } catch (ConnectionException e) {
+                logger.debug("Poll projector failed: {}", e.getMessage(bundle, i18nProvider), e);
+                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getRawMessage());
                 return;
             }
 
index 1f6e51989db6dcb75e4119660883578a7a65bc71..a43f2b9e12b07c3ce8347a2006480dcb3b72559b 100644 (file)
@@ -296,3 +296,10 @@ offline.config-error-unknown-port = Undefined port configuration setting
 offline.config-error-invalid-port = Invalid port configuration setting
 offline.config-error-unknown-model = Undefined model configuration setting
 offline.config-error-invalid-thing-type = Use serial over IP connection thing type
+
+# Exceptions
+
+exception.invalid-serial-port = Opening serial connection failed: no port {0}
+exception.opening-serial-connection-failed = Opening serial connection failed
+exception.opening-serial-over-ip-connection-failed = Opening serial over IP connection failed
+exception.opening-sdcp-connection-failed = Opening SDCP connection failed
index 1db0f3a0327d7a23d8d138ca36e6dbcf77301844..8f13cf6c0fffa03c208be5c0f071599cabcf44a7 100644 (file)
@@ -296,3 +296,10 @@ offline.config-error-unknown-port = Paramètre de port indéfini
 offline.config-error-invalid-port = Paramètre de port invalide
 offline.config-error-unknown-model = Paramètre de modèle indéfini
 offline.config-error-invalid-thing-type = Utiliser le type connexion série sur IP
+
+# Exceptions
+
+exception.invalid-serial-port = Echec de l''ouverture de la connexion série: pas de port {0}
+exception.opening-serial-connection-failed = Echec de l''ouverture de la connexion série
+exception.opening-serial-over-ip-connection-failed = Echec de l''ouverture de la connexion série sur IP
+exception.opening-sdcp-connection-failed = Echec de l''ouverture de la connexion SDCP