diff --git a/bundles/org.openhab.binding.smsmodem/README.md b/bundles/org.openhab.binding.smsmodem/README.md index 0effb5ebed025..63b8a49823560 100644 --- a/bundles/org.openhab.binding.smsmodem/README.md +++ b/bundles/org.openhab.binding.smsmodem/README.md @@ -46,6 +46,8 @@ The *smsconversation* thing is just a shortcut to address/receive messages with |-------|--------------------------| | recipient | The msisdn of the phone you want to discuss with.| | deliveryReport | If enabled, ask the network for a delivery report (default false)| +| encoding | The encoding to use when sending the message (either Enc7, Enc8, EncUcs2, EncCustom, default is Enc7). EncUcs2 is good for non latin character, but SMS character size limit is then reduced| + ``` Thing smsmodem:smsconversation:aconversationname [ recipient="XXXXXXXXXXX", deliveryReport="true" ] @@ -90,6 +92,12 @@ Once this action instance is retrieved, you can invoke the 'send' method on it: smsAction.sendSMS("1234567890", "Hello world!") ``` +Or with a special encoding: + +``` +smsAction.sendSMS("1234567890", "Hello world!", "EncUcs2") +``` + ## Full Example ### Send SMS diff --git a/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/SMSConversationConfiguration.java b/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/SMSConversationConfiguration.java index 1b032c29fd464..5a05ed3dad23d 100644 --- a/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/SMSConversationConfiguration.java +++ b/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/SMSConversationConfiguration.java @@ -24,4 +24,5 @@ public class SMSConversationConfiguration { public String recipient = ""; public boolean deliveryReport = false; + public String encoding = "Enc7"; } diff --git a/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/actions/SMSModemActions.java b/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/actions/SMSModemActions.java index 1622b71bb5403..9f83d4d74df5f 100644 --- a/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/actions/SMSModemActions.java +++ b/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/actions/SMSModemActions.java @@ -22,6 +22,7 @@ import org.openhab.core.thing.binding.ThingHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.smslib.message.AbstractMessage.Encoding; /** * The {@link SMSModemActions} exposes some actions @@ -46,22 +47,35 @@ public void setThingHandler(@Nullable ThingHandler handler) { return handler; } - @RuleAction(label = "Send Message", description = "Send a message") + @RuleAction(label = "Send Message With Special Encoding", description = "Send a message and specify encoding") public void sendSMS( @ActionInput(name = "recipient", label = "recipient", description = "Recipient of the message") @Nullable String recipient, - @ActionInput(name = "message", label = "message", description = "Message to send") @Nullable String message) { + @ActionInput(name = "message", label = "message", description = "Message to send") @Nullable String message, + @ActionInput(name = "encoding", label = "encoding", description = "Encoding") @Nullable String encoding) { if (recipient != null && !recipient.isEmpty() && message != null) { - handler.send(recipient, message, false); + handler.send(recipient, message, false, encoding); } else { logger.error("SMSModem cannot send a message with no recipient or text"); } } - public static void sendSMS(@Nullable ThingActions actions, @Nullable String recipient, @Nullable String message) { + @RuleAction(label = "Send Message", description = "Send a message") + public void sendSMS( + @ActionInput(name = "recipient", label = "recipient", description = "Recipient of the message") @Nullable String recipient, + @ActionInput(name = "message", label = "message", description = "Message to send") @Nullable String message) { + sendSMS(recipient, message, Encoding.Enc7.toString()); + } + + public static void sendSMS(@Nullable ThingActions actions, @Nullable String recipient, @Nullable String message, + @Nullable String encoding) { if (actions instanceof SMSModemActions) { - ((SMSModemActions) actions).sendSMS(recipient, message); + ((SMSModemActions) actions).sendSMS(recipient, message, encoding); } else { throw new IllegalArgumentException("Instance is not an SMSModemActions class."); } } + + public static void sendSMS(@Nullable ThingActions actions, @Nullable String recipient, @Nullable String message) { + sendSMS(actions, recipient, message, Encoding.Enc7.toString()); + } } diff --git a/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/handler/SMSConversationHandler.java b/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/handler/SMSConversationHandler.java index 68bd9db275b1c..cd8b5adbfed1d 100644 --- a/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/handler/SMSConversationHandler.java +++ b/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/handler/SMSConversationHandler.java @@ -106,7 +106,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { public void send(String text) { SMSModemBridgeHandler bridgeHandlerFinal = bridgeHandler; if (bridgeHandlerFinal != null) { - bridgeHandlerFinal.send(getRecipient(), text, config.deliveryReport); + bridgeHandlerFinal.send(getRecipient(), text, config.deliveryReport, config.encoding); } else { logger.warn("Only channel 'send' in SMSConversation can receive command"); } diff --git a/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/handler/SMSModemBridgeHandler.java b/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/handler/SMSModemBridgeHandler.java index 20b3c1c0c6470..9df9b1ccbbd8a 100644 --- a/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/handler/SMSModemBridgeHandler.java +++ b/bundles/org.openhab.binding.smsmodem/src/main/java/org/openhab/binding/smsmodem/internal/handler/SMSModemBridgeHandler.java @@ -52,6 +52,7 @@ import org.smslib.callback.IDeviceInformationListener; import org.smslib.callback.IInboundOutboundMessageListener; import org.smslib.callback.IModemStatusListener; +import org.smslib.message.AbstractMessage.Encoding; import org.smslib.message.DeliveryReportMessage; import org.smslib.message.InboundMessage; import org.smslib.message.MsIsdn; @@ -265,8 +266,16 @@ public void messageReceived(InboundMessage message) { * @param text The message content * @param deliveryReport If we should ask the network for a delivery report */ - public void send(String recipient, String text, boolean deliveryReport) { + public void send(String recipient, String text, boolean deliveryReport, @Nullable String encoding) { OutboundMessage out = new OutboundMessage(recipient, text); + try { + if (encoding != null && !encoding.isEmpty()) { + Encoding encoding2 = Encoding.valueOf(encoding); + out.setEncoding(encoding2); + } + } catch (IllegalArgumentException e) { + logger.error("Encoding {} is not supported. Use Enc7, Enc8, EncUcs2, or EncCustom", encoding); + } out.setRequestDeliveryReport(deliveryReport); logger.debug("Sending message to {}", recipient); modem.queue(out); diff --git a/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/i18n/smsmodem.properties b/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/i18n/smsmodem.properties index 60d1e5f0d7de0..b4bb9ad063c20 100644 --- a/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/i18n/smsmodem.properties +++ b/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/i18n/smsmodem.properties @@ -14,6 +14,8 @@ thing-type.smsmodem.smsmodembridge.description = This bridge represents a modem. thing-type.config.smsmodem.smsconversation.deliveryReport.label = Delivery Report thing-type.config.smsmodem.smsconversation.deliveryReport.description = Ask network for delivery report. +thing-type.config.smsmodem.smsconversation.encoding.label = Encoding +thing-type.config.smsmodem.smsconversation.encoding.description = Encoding for the message to send. Default Enc7. thing-type.config.smsmodem.smsconversation.recipient.label = Recipient Number thing-type.config.smsmodem.smsconversation.recipient.description = The SMS number of the recipient. thing-type.config.smsmodem.smsmodembridge.baudOrNetworkPort.label = Baud Or Network Port diff --git a/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/i18n/smsmodem_fr.properties b/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/i18n/smsmodem_fr.properties index 57b96f8e2c06a..63a219c64f4fe 100644 --- a/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/i18n/smsmodem_fr.properties +++ b/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/i18n/smsmodem_fr.properties @@ -1,37 +1,39 @@ # binding binding.smsmodem.name = Extension SMSModem -binding.smsmodem.description = Cette extension gère un modem GSM supportant les messages AT et connecté en série, ou exposé sur le réseau. Elle peut envoyer et recevoir des SMS +binding.smsmodem.description = Cette extension gère un modem GSM supportant les messages AT et connecté en série, ou exposé sur le réseau. Elle peut envoyer et recevoir des SMS # thing types thing-type.smsmodem.smsconversation.label = Conversation SMS -thing-type.smsmodem.smsconversation.description = Représente une conversation avec un correspondant. +thing-type.smsmodem.smsconversation.description = Représente une conversation avec un correspondant. thing-type.smsmodem.smsmodembridge.label = SMSModem -thing-type.smsmodem.smsmodembridge.description = Un modem connecté en série ou par le réseau +thing-type.smsmodem.smsmodembridge.description = Un modem connecté en série ou par le réseau # thing types config -thing-type.config.smsmodem.smsconversation.deliveryReport.label = Accusé de réception -thing-type.config.smsmodem.smsconversation.deliveryReport.description = Demande au réseau un accusé de réception. -thing-type.config.smsmodem.smsconversation.recipient.label = Numéro Du Correspondant -thing-type.config.smsmodem.smsconversation.recipient.description = Le numéro SMS du correspondant. -thing-type.config.smsmodem.smsmodembridge.baudOrNetworkPort.label = Taux (Baud) Ou Port Réseau -thing-type.config.smsmodem.smsmodembridge.baudOrNetworkPort.description = Taux de transmission, si modem connecté en série, ou port réseau si il est sur une autre machine du réseau. -thing-type.config.smsmodem.smsmodembridge.delayBetweenSend.description = Délai entre deux envois (en millisecondes). Peut être utile pour les modems lents. -thing-type.config.smsmodem.smsmodembridge.pollingInterval.description = Délai entre deux essais de récupération de message (in seconds). +thing-type.config.smsmodem.smsconversation.deliveryReport.label = Accusé de réception +thing-type.config.smsmodem.smsconversation.deliveryReport.description = Demande au réseau un accusé de réception. +thing-type.config.smsmodem.smsconversation.encoding.label = Encodage +thing-type.config.smsmodem.smsconversation.encoding.description = Encodage du message à envoyer. Défaut Enc7. +thing-type.config.smsmodem.smsconversation.recipient.label = Numéro Du Correspondant +thing-type.config.smsmodem.smsconversation.recipient.description = Le numéro SMS du correspondant. +thing-type.config.smsmodem.smsmodembridge.baudOrNetworkPort.label = Taux (Baud) Ou Port Réseau +thing-type.config.smsmodem.smsmodembridge.baudOrNetworkPort.description = Taux de transmission, si modem connecté en série, ou port réseau si il est sur une autre machine du réseau. +thing-type.config.smsmodem.smsmodembridge.delayBetweenSend.description = Délai entre deux envois (en millisecondes). Peut être utile pour les modems lents. +thing-type.config.smsmodem.smsmodembridge.pollingInterval.description = Délai entre deux essais de récupération de message (in seconds). thing-type.config.smsmodem.smsmodembridge.serialPortOrIP.label = Addresse -thing-type.config.smsmodem.smsmodembridge.serialPortOrIP.description = Port série du modem, ou addresse IP si il est sur le réseau. +thing-type.config.smsmodem.smsmodembridge.serialPortOrIP.description = Port série du modem, ou addresse IP si il est sur le réseau. thing-type.config.smsmodem.smsmodembridge.simPin.label = Code PIN -thing-type.config.smsmodem.smsmodembridge.simPin.description = Le code PIN (si nécessaire) de la carte SIM. +thing-type.config.smsmodem.smsmodembridge.simPin.description = Le code PIN (si nécessaire) de la carte SIM. # channel types -channel-type.smsmodem.deliverystatus.label = Accusé De Réception +channel-type.smsmodem.deliverystatus.label = Accusé De Réception channel-type.smsmodem.deliverystatus.description = Dernier statut de message (soit UNKNOWN, QUEUED, SENT, PENDING, DELIVERED, EXPIRED, ou FAILED) -channel-type.smsmodem.receive.label = Message Reçu -channel-type.smsmodem.receive.description = Dernier message reçu -channel-type.smsmodem.send.label = Message Envoyé -channel-type.smsmodem.send.description = Message à envoyer au correspondant -channel-type.smsmodem.smsmodemreceivetrigger.label = Message Reçu -channel-type.smsmodem.smsmodemreceivetrigger.description = Déclenché quand un message est réceptionné, sous la forme "<msisdn_sender>|<text>" +channel-type.smsmodem.receive.label = Message Reçu +channel-type.smsmodem.receive.description = Dernier message reçu +channel-type.smsmodem.send.label = Message Envoyé +channel-type.smsmodem.send.description = Message à envoyer au correspondant +channel-type.smsmodem.smsmodemreceivetrigger.label = Message Reçu +channel-type.smsmodem.smsmodemreceivetrigger.description = Déclenché quand un message est réceptionné, sous la forme "<msisdn_sender>|<text>" diff --git a/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/thing/smsconversation.xml b/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/thing/smsconversation.xml index 31485fdc8b51c..6e6501695b808 100644 --- a/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/thing/smsconversation.xml +++ b/bundles/org.openhab.binding.smsmodem/src/main/resources/OH-INF/thing/smsconversation.xml @@ -29,6 +29,17 @@ <description>Ask network for delivery report.</description> <default>false</default> </parameter> + <parameter name="encoding" type="text" required="false"> + <label>Encoding</label> + <options> + <option value="Enc7">Enc7</option> + <option value="Enc8">Enc8</option> + <option value="EncUcs2">EncUcs2</option> + <option value="EncCustom">EncCustom</option> + </options> + <description>Encoding for the message to send. Default Enc7</description> + <default>Enc7</default> + </parameter> </config-description> </thing-type>