Skip to content

Commit

Permalink
[smsmodem] Apply code review (removing unnecessary method)
Browse files Browse the repository at this point in the history
Signed-off-by: Gwendal Roulleau <[email protected]>
  • Loading branch information
dalgwen committed Nov 23, 2022
1 parent 6216419 commit 015cd7f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ protected void startScan() {

public void buildDiscovery(String sender) {
String senderSanitized = sender.replaceAll("[^a-zA-Z0-9+]", "_");
ThingUID thingUID = SMSModemHandlerFactory
.getSMSConversationUID(SMSModemBindingConstants.SMSCONVERSATION_THING_TYPE, senderSanitized, bridgeUid);

ThingUID thingUID = new ThingUID(SMSModemBindingConstants.SMSCONVERSATION_THING_TYPE, senderSanitized,
bridgeUid.getId());

DiscoveryResult result = DiscoveryResultBuilder.create(thingUID)
.withProperty(SMSModemBindingConstants.SMSCONVERSATION_PARAMETER_RECIPIENT, senderSanitized)
.withLabel("Conversation with " + sender).withBridge(bridgeUid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.smsmodem.internal.handler.SMSConversationHandler;
import org.openhab.binding.smsmodem.internal.handler.SMSModemBridgeHandler;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.io.transport.serial.SerialPortManager;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerFactory;
Expand Down Expand Up @@ -75,31 +73,4 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {

return null;
}

@Override
public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration,
@Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
if (SMSModemBridgeHandler.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
return super.createThing(thingTypeUID, configuration, thingUID, null);
}
if (SMSConversationHandler.SUPPORTED_THING_TYPES_UIDS.equals(thingTypeUID)) {
if (bridgeUID != null) {
ThingUID safethingUID = thingUID == null
? getSMSConversationUID(thingTypeUID,
(String) configuration
.get(SMSModemBindingConstants.SMSCONVERSATION_PARAMETER_RECIPIENT),
bridgeUID)
: thingUID;
return super.createThing(thingTypeUID, configuration, safethingUID, bridgeUID);
} else {
throw new IllegalArgumentException("Cannot create a SMSConversation without a SMSModem bridge");
}

}
throw new IllegalArgumentException("The thing type " + thingTypeUID + " is not supported by the binding.");
}

public static ThingUID getSMSConversationUID(ThingTypeUID thingTypeUID, String recipient, ThingUID bridgeUID) {
return new ThingUID(thingTypeUID, recipient, bridgeUID.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected void updateConfiguration(Configuration configuration) {

@Override
public void initialize() {
updateStatus(ThingStatus.UNKNOWN);
shouldRun = true;
ScheduledFuture<?> checkScheduledFinal = checkScheduled;
if (checkScheduledFinal == null || (checkScheduledFinal.isDone()) && this.shouldRun) {
Expand Down Expand Up @@ -180,7 +181,11 @@ private synchronized void checkAndStartModemIfNeeded() {
}
} catch (ModemConfigurationException e) {
String message = e.getMessage();
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, message);
if (e.getCause() != null && e.getCause() instanceof IOException) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, message);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, message);
}
}
}

Expand Down

0 comments on commit 015cd7f

Please sign in to comment.