Skip to content

Commit

Permalink
update to build on latest main.
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Skinner <matt@pcmus.com>
  • Loading branch information
Skinah committed May 16, 2021
1 parent 2e64128 commit cd44751
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1,706 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

import static org.openhab.binding.ipobserver.internal.IpObserverBindingConstants.*;

<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> Bulk updated to UOM.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -28,7 +24,6 @@

import javax.measure.Unit;

<<<<<<< HEAD
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
Expand Down Expand Up @@ -56,40 +51,6 @@
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.openhab.core.types.TypeParser;
=======
=======
>>>>>>> Bulk updated to UOM.
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;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.types.Command;
<<<<<<< HEAD
import org.openhab.core.types.RefreshType;
>>>>>>> ipObserver creation
=======
import org.openhab.core.types.State;
import org.openhab.core.types.TypeParser;
>>>>>>> Bulk updated to UOM.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -102,75 +63,20 @@
*/
@NonNullByDefault
public class IpObserverHandler extends BaseThingHandler {
<<<<<<< HEAD
<<<<<<< HEAD
private final HttpClient httpClient;
private final Logger logger = LoggerFactory.getLogger(IpObserverHandler.class);
private Map<String, ChannelHandler> channelHandlers = new HashMap<String, ChannelHandler>();
<<<<<<< HEAD
private @Nullable ScheduledFuture<?> pollingFuture = null;
private IpObserverConfiguration config = new IpObserverConfiguration();

class ChannelHandler {
private IpObserverHandler handler;
private Channel channel;
private String currentState = "";
private Unit<?> unit;
private final ArrayList<Class<? extends State>> acceptedDataTypes = new ArrayList<Class<? extends State>>();

ChannelHandler(IpObserverHandler handler, Channel channel, Class<? extends State> acceptable, Unit<?> unit) {
super();
this.handler = handler;
this.channel = channel;
this.unit = unit;
acceptedDataTypes.add(acceptable);
}

public void processMessage(String sensorValue) {
if (!sensorValue.equals(this.currentState)) {
this.currentState = sensorValue;
State state = TypeParser.parseState(this.acceptedDataTypes, sensorValue);
if (state instanceof QuantityType) {
handler.updateState(this.channel.getUID(),
QuantityType.valueOf(Double.parseDouble(sensorValue), unit));
} else if (state != null) {
this.handler.updateState(this.channel.getUID(), state);
}
}
}
}

public IpObserverHandler(Thing thing, HttpClient httpClient) {
super(thing);
this.httpClient = httpClient;
=======

=======
private final HttpClient httpClient;
>>>>>>> Bulk updated to UOM.
private final Logger logger = LoggerFactory.getLogger(IpObserverHandler.class);
private Map<String, UpdateHandler> updateHandlers = new HashMap<String, UpdateHandler>();
private @Nullable ScheduledFuture<?> pollingFuture = null;
private IpObserverConfiguration config = new IpObserverConfiguration();

class UpdateHandler {
=======
private @Nullable ScheduledFuture<?> pollingFuture = null;
private IpObserverConfiguration config = new IpObserverConfiguration();

class ChannelHandler {
>>>>>>> Fix merge conflicts.
private IpObserverHandler handler;
private Channel channel;
private String currentState = "";
private Unit<?> unit;
private final ArrayList<Class<? extends State>> acceptedDataTypes = new ArrayList<Class<? extends State>>();

<<<<<<< HEAD
UpdateHandler(IpObserverHandler handler, Channel channel, Class<? extends State> acceptable, Unit<?> unit) {
=======
ChannelHandler(IpObserverHandler handler, Channel channel, Class<? extends State> acceptable, Unit<?> unit) {
>>>>>>> Fix merge conflicts.
super();
this.handler = handler;
this.channel = channel;
Expand All @@ -179,11 +85,7 @@ class ChannelHandler {
}

public void processMessage(String sensorValue) {
<<<<<<< HEAD
if (!Objects.equals(sensorValue, this.currentState)) {
=======
if (!sensorValue.equals(this.currentState)) {
>>>>>>> Fix merge conflicts.
this.currentState = sensorValue;
State state = TypeParser.parseState(this.acceptedDataTypes, sensorValue);
if (state instanceof QuantityType) {
Expand All @@ -198,19 +100,11 @@ public void processMessage(String sensorValue) {

public IpObserverHandler(Thing thing, HttpClient httpClient) {
super(thing);
<<<<<<< HEAD
>>>>>>> ipObserver creation
=======
this.httpClient = httpClient;
>>>>>>> Bulk updated to UOM.
}

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> Bulk updated to UOM.
}

private void parseSettings(String html) {
Expand Down Expand Up @@ -255,7 +149,6 @@ private void parseAndUpdate(String html) {
if (localUpdater != null) {
localUpdater.processMessage(value);
}
<<<<<<< HEAD
}
}
}
Expand All @@ -265,57 +158,6 @@ private void sendGetRequest(String url) {
request.method(HttpMethod.GET).timeout(5, TimeUnit.SECONDS).header(HttpHeader.ACCEPT_ENCODING, "gzip");
String errorReason = "";
try {
<<<<<<< HEAD
ContentResponse contentResponse = request.send();
if (contentResponse.getStatus() == 200) {
updateStatus(ThingStatus.ONLINE);
if (url == STATION_SETTINGS_URL) {
parseSettings(contentResponse.getContentAsString());
} else {
parseAndUpdate(contentResponse.getContentAsString());
}
return;
} else {
errorReason = String.format("IpObserver request failed with %d: %s", contentResponse.getStatus(),
contentResponse.getReason());
}
} catch (TimeoutException e) {
errorReason = "TimeoutException: IpObserver was not reachable on your network";
} catch (ExecutionException e) {
errorReason = String.format("ExecutionException: %s", e.getMessage());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
errorReason = String.format("InterruptedException: %s", e.getMessage());
}
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, errorReason);
}

private void pollStation() {
sendGetRequest(LIVE_DATA_URL);
}

private void createChannel(String chanName, Class<? extends State> type, Unit<?> unit, String htmlName) {
@Nullable
Channel channel = this.getThing().getChannel(chanName);
if (channel != null) {
updateHandlers.put(htmlName, new UpdateHandler(this, channel, type, unit));
=======
if (CHANNEL_1.equals(channelUID.getId())) {
if (command instanceof RefreshType) {
// TODO: handle data refresh
=======
>>>>>>> Bulk updated to UOM.
}
}
}

private void sendGetRequest(String url) {
Request request = httpClient.newRequest("http://" + config.address + url);
request.method(HttpMethod.GET).timeout(5, TimeUnit.SECONDS).header(HttpHeader.ACCEPT_ENCODING, "gzip");
String errorReason = "";
try {
=======
>>>>>>> Fix merge conflicts.
long start = System.currentTimeMillis();
ContentResponse contentResponse = request.send();
if (contentResponse.getStatus() == 200) {
Expand Down Expand Up @@ -357,93 +199,15 @@ private void pollStation() {
sendGetRequest(LIVE_DATA_URL);
}

<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
// Note: if communication with thing fails for some reason,
// indicate that by setting the status with detail information:
// updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
// "Could not control device at IP address x.x.x.x");
>>>>>>> ipObserver creation
=======
private void createChannel(String chanName, Class<? extends State> type, Unit<?> unit, String htmlName) {
@Nullable
Channel channel = this.getThing().getChannel(chanName);
if (channel != null) {
updateHandlers.put(htmlName, new UpdateHandler(this, channel, type, unit));
>>>>>>> Bulk updated to UOM.
=======
=======
>>>>>>> Fix merge conflicts.
private void createChannelHandler(String chanName, Class<? extends State> type, Unit<?> unit, String htmlName) {
@Nullable
Channel channel = this.getThing().getChannel(chanName);
if (channel != null) {
channelHandlers.put(htmlName, new ChannelHandler(this, channel, type, unit));
>>>>>>> Fix time channels.
}
}

<<<<<<< HEAD
@Override
public void initialize() {
config = getConfigAs(IpObserverConfiguration.class);
<<<<<<< HEAD
<<<<<<< HEAD
updateStatus(ThingStatus.UNKNOWN);
sendGetRequest(STATION_SETTINGS_URL);
createChannel(INDOOR_TEMP, QuantityType.class, SIUnits.CELSIUS, "inTemp");// ImperialUnits.FAHRENHEIT
createChannel(OUTDOOR_TEMP, QuantityType.class, SIUnits.CELSIUS, "outTemp");
createChannel(INDOOR_HUMIDITY, DecimalType.class, Units.PERCENT, "inHumi");
createChannel(OUTDOOR_HUMIDITY, DecimalType.class, Units.PERCENT, "outHumi");
createChannel(ABS_PRESSURE, DecimalType.class, SIUnits.PASCAL, "AbsPress");
createChannel(REL_PRESSURE, DecimalType.class, SIUnits.PASCAL, "RelPress");
createChannel(WIND_DIRECTION, DecimalType.class, SIUnits.CELSIUS, "windir");
createChannel(WIND_SPEED, QuantityType.class, Units.KNOT, "avgwind");
createChannel(WIND_SPEED2, QuantityType.class, Units.KNOT, "windspeed");
createChannel(WIND_GUST, QuantityType.class, Units.KNOT, "gustspeed");
createChannel(DAILY_GUST, QuantityType.class, Units.KNOT, "dailygust");
createChannel(SOLAR_RADIATION, DecimalType.class, SIUnits.CELSIUS, "solarrad");
createChannel(UV, DecimalType.class, SIUnits.CELSIUS, "uv");
createChannel(UVI, DecimalType.class, SIUnits.CELSIUS, "uvi");
createChannel(HOURLY_RAIN, QuantityType.class, Units.MILLIMETRE_PER_HOUR, "rainofhourly");
createChannel(DAILY_RAIN, QuantityType.class, MetricPrefix.MILLI(SIUnits.METRE), "rainofdaily");
createChannel(WEEKLY_RAIN, QuantityType.class, MetricPrefix.MILLI(SIUnits.METRE), "rainofweekly");
createChannel(MONTHLY_RAIN, QuantityType.class, MetricPrefix.MILLI(SIUnits.METRE), "rainofmonthly");
createChannel(YEARLY_RAIN, QuantityType.class, MetricPrefix.MILLI(SIUnits.METRE), "rainofyearly");
createChannel(BATTERY_OUT, StringType.class, Units.PERCENT, "outBattSta1");
createChannel(INDOOR_BATTERY, StringType.class, Units.PERCENT, "inBattSta");
createChannel(LAST_UPDATED_TIME, StringType.class, SIUnits.CELSIUS, "CurrTime");
pollingFuture = scheduler.scheduleWithFixedDelay(this::pollStation, 1, config.pollTime, TimeUnit.SECONDS);
}

@Override
public void dispose() {
updateHandlers.clear();
if (pollingFuture != null) {
pollingFuture.cancel(true);
pollingFuture = null;
}
=======

// TODO: Initialize the handler.
// The framework requires you to return from this method quickly. Also, before leaving this method a thing
// status from one of ONLINE, OFFLINE or UNKNOWN must be set. This might already be the real thing status in
// case you can decide it directly.
// In case you can not decide the thing status directly (e.g. for long running connection handshake using WAN
// access or similar) you should set status UNKNOWN here and then decide the real status asynchronously in the
// background.

// set the thing status to UNKNOWN temporarily and let the background task decide for the real status.
// the framework is then able to reuse the resources from the thing handler initialization.
// we set this upfront to reliably check status updates in unit tests.
=======
>>>>>>> Bulk updated to UOM.
updateStatus(ThingStatus.UNKNOWN);
sendGetRequest(STATION_SETTINGS_URL);
=======
private void setupChannels() {
>>>>>>> updates
if (config.imperialTemperature) {
logger.debug("Using imperial units of measurement for temperature.");
createChannelHandler(TEMP_INDOOR, QuantityType.class, ImperialUnits.FAHRENHEIT, "inTemp");
Expand Down Expand Up @@ -533,33 +297,6 @@ public void initialize() {
pollingFuture = scheduler.scheduleWithFixedDelay(this::pollStation, 1, config.pollTime, TimeUnit.SECONDS);
}

<<<<<<< HEAD
<<<<<<< HEAD
// Example for background initialization:
scheduler.execute(() -> {
boolean thingReachable = true; // <background task with long running initialization here>
// when done do:
if (thingReachable) {
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE);
}
});

// These logging types should be primarily used by bindings
// logger.trace("Example trace message");
// logger.debug("Example debug message");
// logger.warn("Example warn message");

// Note: When initialization can NOT be done set the status with more details for further
// analysis. See also class ThingStatusDetail for all available status details.
// Add a description to give user information to understand why thing does not work as expected. E.g.
// updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
// "Can not access device as username and/or password are invalid");
>>>>>>> ipObserver creation
=======
=======
>>>>>>> Fix merge conflicts.
@Override
public void dispose() {
channelHandlers.clear();
Expand All @@ -569,6 +306,5 @@ public void dispose() {
localFuture.cancel(true);
localFuture = null;
}
>>>>>>> Bulk updated to UOM.
}
}
Loading

0 comments on commit cd44751

Please sign in to comment.