import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
* @author Dan Cunningham - Initial contribution
* @author Svilen Valkanov - Replaced Apache HttpClient with Jetty
*/
+@NonNullByDefault
public class AutelisHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(AutelisHandler.class);
*/
private static final int THROTTLE_TIME_MILLISECONDS = 500;
- /**
- * Autelis web port
- */
- private static final int WEB_PORT = 80;
-
/**
* Pentair values for pump response
*/
/**
* Constructed URL consisting of host and port
*/
- private String baseURL;
-
- /**
- * Our poll rate
- */
- private int refresh;
+ private String baseURL = "";
/**
* The http client used for polling requests
/**
* Authentication for login
*/
- private String basicAuthentication;
+ private String basicAuthentication = "";
/**
* Regex expression to match XML responses from the Autelis, this is used to
/**
* Future to poll for updated
*/
- private ScheduledFuture<?> pollFuture;
+ private @Nullable ScheduledFuture<?> pollFuture;
public AutelisHandler(Thing thing) {
super(thing);
value = 0;
} else if (command == OnOffType.ON) {
value = 1;
- } else if (command instanceof DecimalType) {
- value = ((DecimalType) command).intValue();
+ } else if (command instanceof DecimalType commandAsDecimalType) {
+ value = commandAsDecimalType.intValue();
if (!isJandy() && value >= 3) {
// this is an autelis dim type. not sure what 2 does
cmd = "dim";
clearPolling();
AutelisConfiguration configuration = getConfig().as(AutelisConfiguration.class);
- Integer refreshOrNull = configuration.refresh;
- Integer portOrNull = configuration.port;
+ int refresh = configuration.refresh;
+ int port = configuration.port;
String host = configuration.host;
String username = configuration.user;
String password = configuration.password;
- if (username == null || username.isBlank()) {
+ if (username.isBlank()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "username must not be empty");
return;
}
- if (password == null || password.isBlank()) {
+ if (password.isBlank()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "password must not be empty");
return;
}
- if (host == null || host.isBlank()) {
+ if (host.isBlank()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "hostname must not be empty");
return;
}
- refresh = DEFAULT_REFRESH_SECONDS;
- if (refreshOrNull != null) {
- refresh = refreshOrNull.intValue();
- }
-
- int port = WEB_PORT;
- if (portOrNull != null) {
- port = portOrNull.intValue();
- }
-
baseURL = "http://" + host + ":" + port;
basicAuthentication = "Basic "
+ Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1));
* Stops/clears this thing's polling future
*/
private void clearPolling() {
+ ScheduledFuture<?> pollFuture = this.pollFuture;
if (pollFuture != null && !pollFuture.isCancelled()) {
logger.trace("Canceling future");
pollFuture.cancel(false);
logger.trace("{}/{}.xml \n {}", baseURL, status, response);
if (response == null) {
// all models and versions have the status.xml endpoint
- if (status.equals("status")) {
+ if ("status".equals(status)) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR);
return;
} else {
* @param timeout
* @return
*/
- private synchronized String getUrl(String url, int timeout) throws InterruptedException {
+ private synchronized @Nullable String getUrl(String url, int timeout) throws InterruptedException {
// throttle commands for a very short time to avoid 'loosing' them
long now = System.currentTimeMillis();
long nextReq = lastRequestTime + THROTTLE_TIME_MILLISECONDS;
* @param value
* @return {@link State}
*/
- private State toState(String type, String value) throws NumberFormatException {
+ private State toState(@Nullable String type, String value) throws NumberFormatException {
if ("Number".equals(type)) {
return new DecimalType(value);
} else if ("Switch".equals(type)) {
}
}
- private void stopHttpClient(HttpClient client) {
+ private void stopHttpClient(@Nullable HttpClient client) {
if (client != null) {
client.getAuthenticationStore().clearAuthentications();
client.getAuthenticationStore().clearAuthenticationResults();