added migrated 2.x add-ons

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer
2020-09-21 01:58:32 +02:00
parent bbf1a7fd29
commit 6df6783b60
11662 changed files with 1302875 additions and 11 deletions

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.wlanthermo-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
<feature name="openhab-binding-wlanthermo" description="WlanThermo Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.wlanthermo/${project.version}</bundle>
</feature>
</features>

View File

@@ -0,0 +1,82 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;
/**
* The {@link WlanThermoBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Christian Schlipp - Initial contribution
*/
@NonNullByDefault
public class WlanThermoBindingConstants {
private static final String BINDING_ID = "wlanthermo";
// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_WLANTHERMO_NANO = new ThingTypeUID(BINDING_ID, "nano");
public static final ThingTypeUID THING_TYPE_WLANTHERMO_MINI = new ThingTypeUID(BINDING_ID, "mini");
// ThreadPool
public static final String WLANTHERMO_THREAD_POOL = "wlanthermo";
// List of all Channel ids
// System Channels
public static final String SYSTEM = "system";
public static final String SYSTEM_SOC = "soc";
public static final String SYSTEM_CHARGE = "charge";
public static final String SYSTEM_RSSI = "rssi";
public static final String SYSTEM_RSSI_SIGNALSTRENGTH = "rssi_signalstrength";
public static final String SYSTEM_CPU_LOAD = "cpu_load";
public static final String SYSTEM_CPU_TEMP = "cpu_temp";
public static final String CHANNEL0 = "channel0";
public static final String CHANNEL1 = "channel1";
public static final String CHANNEL2 = "channel2";
public static final String CHANNEL3 = "channel3";
public static final String CHANNEL4 = "channel4";
public static final String CHANNEL5 = "channel5";
public static final String CHANNEL6 = "channel6";
public static final String CHANNEL7 = "channel7";
public static final String CHANNEL8 = "channel8";
public static final String CHANNEL9 = "channel9";
public static final String CHANNEL_NAME = "name";
public static final String CHANNEL_TYP = "typ";
public static final String CHANNEL_TEMP = "temp";
public static final String CHANNEL_MIN = "min";
public static final String CHANNEL_MAX = "max";
public static final String CHANNEL_ALARM_DEVICE = "alarm_device";
public static final String CHANNEL_ALARM_PUSH = "alarm_push";
public static final String CHANNEL_ALARM_OPENHAB = "alarm_openhab";
public static final String CHANNEL_ALARM_OPENHAB_LOW = "alarm_openhab_low";
public static final String CHANNEL_ALARM_OPENHAB_HIGH = "alarm_openhab_high";
public static final String CHANNEL_COLOR = "color";
public static final String CHANNEL_COLOR_NAME = "color_name";
public static final String CHANNEL_PITMASTER_ENABLED = "enabled"; // Mini
public static final String CHANNEL_PITMASTER_CURRENT = "current"; // Mini
public static final String CHANNEL_PITMASTER_SETPOINT = "setpoint"; // Mini+Nano
public static final String CHANNEL_PITMASTER_DUTY_CYCLE = "duty_cycle"; // Mini+Nano
public static final String CHANNEL_PITMASTER_LID_OPEN = "lid_open"; // Mini
public static final String CHANNEL_PITMASTER_CHANNEL_ID = "channel_id"; // Mini+Nano
public static final String CHANNEL_PITMASTER_STATE = "state"; // Nano
public static final String CHANNEL_PITMASTER_PIDPROFILE = "pid_id"; // Nano
public static final String TRIGGER_ALARM_OFF = "OFF";
public static final String TRIGGER_ALARM_MIN = "MIN";
public static final String TRIGGER_ALARM_MAX = "MAX";
}

View File

@@ -0,0 +1,69 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.openhab.core.io.net.http.HttpClientFactory;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerFactory;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* The {@link WlanThermoHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Christian Schlipp - Initial contribution
*/
@NonNullByDefault
@Component(configurationPid = "binding.wlanthermo", service = ThingHandlerFactory.class)
public class WlanThermoHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = new HashSet<ThingTypeUID>(
Arrays.asList(WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_NANO,
WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_MINI));
private final HttpClient httpClient;
@Activate
public WlanThermoHandlerFactory(@Reference HttpClientFactory httpClientFactory) {
this.httpClient = httpClientFactory.getCommonHttpClient();
}
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
}
@Override
protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_NANO.equals(thingTypeUID)) {
return new WlanThermoNanoHandler(thing, httpClient);
} else if (WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_MINI.equals(thingTypeUID)) {
return new WlanThermoMiniHandler(thing, httpClient);
}
return null;
}
}

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link WlanThermoMiniConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Christian Schlipp - Initial contribution
*/
@NonNullByDefault
public class WlanThermoMiniConfiguration {
/**
* IP Address of WlanThermo.
*/
private String ipAddress = "";
/**
* Polling interval
*/
private int pollingInterval = 10;
public String getIpAddress() {
return ipAddress;
}
public URI getUri(String path) throws URISyntaxException {
String uri = ipAddress;
if (!uri.startsWith("http://")) {
uri = "http://" + uri;
}
if (!path.startsWith("/") && !uri.endsWith("/")) {
uri = uri + "/";
}
uri = uri + path;
return new URI(uri);
}
public URI getUri() throws URISyntaxException {
return getUri("");
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public int getPollingInterval() {
return pollingInterval;
}
public void setPollingInterval(int pollingInterval) {
this.pollingInterval = pollingInterval;
}
}

View File

@@ -0,0 +1,151 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal;
import java.net.URISyntaxException;
import java.util.concurrent.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.openhab.binding.wlanthermo.internal.api.mini.builtin.App;
import org.openhab.binding.wlanthermo.internal.api.mini.builtin.WlanThermoMiniCommandHandler;
import org.openhab.core.common.ThreadPoolManager;
import org.openhab.core.thing.*;
import org.openhab.core.thing.binding.BaseThingHandler;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
/**
* The {@link WlanThermoMiniHandler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Christian Schlipp - Initial contribution
*/
@NonNullByDefault
public class WlanThermoMiniHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(WlanThermoMiniHandler.class);
private final WlanThermoMiniCommandHandler wlanThermoMiniCommandHandler = new WlanThermoMiniCommandHandler();
private WlanThermoMiniConfiguration config = new WlanThermoMiniConfiguration();
private final HttpClient httpClient;
private @Nullable ScheduledFuture<?> pollingScheduler;
private final ScheduledExecutorService scheduler = ThreadPoolManager
.getScheduledPool(WlanThermoBindingConstants.WLANTHERMO_THREAD_POOL);
private final Gson gson = new Gson();
private App app = new App();
public WlanThermoMiniHandler(Thing thing, HttpClient httpClient) {
super(thing);
this.httpClient = httpClient;
}
@Override
public void initialize() {
logger.debug("Start initializing WlanThermo Mini!");
config = getConfigAs(WlanThermoMiniConfiguration.class);
updateStatus(ThingStatus.UNKNOWN);
scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS);
logger.debug("Finished initializing WlanThermo Mini!");
}
private void checkConnection() {
try {
if (httpClient.GET(config.getUri("/app.php")).getStatus() == 200) {
updateStatus(ThingStatus.ONLINE);
ScheduledFuture<?> oldScheduler = pollingScheduler;
if (oldScheduler != null) {
oldScheduler.cancel(false);
}
pollingScheduler = scheduler.scheduleWithFixedDelay(this::update, 0, config.getPollingInterval(),
TimeUnit.SECONDS);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"WlanThermo not found under given address.");
}
} catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) {
logger.debug("Failed to connect.", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Could not connect to WlanThermo at " + config.getIpAddress());
ScheduledFuture<?> oldScheduler = pollingScheduler;
if (oldScheduler != null) {
oldScheduler.cancel(false);
}
pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS);
}
}
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
State s = wlanThermoMiniCommandHandler.getState(channelUID, app);
if (s != null)
updateState(channelUID, s);
}
// Mini is read only!
}
private void update() {
try {
// Update objects with data from device
String json = httpClient.GET(config.getUri("/app.php")).getContentAsString();
app = gson.fromJson(json, App.class);
logger.debug("Received at /app.php: {}", json);
// Update channels
for (Channel channel : thing.getChannels()) {
State state = wlanThermoMiniCommandHandler.getState(channel.getUID(), app);
if (state != null) {
updateState(channel.getUID(), state);
} else {
String trigger = wlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app);
if (trigger != null) {
triggerChannel(channel.getUID(), trigger);
}
}
}
} catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) {
logger.debug("Update failed, checking connection", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed, reconnecting...");
ScheduledFuture<?> oldScheduler = pollingScheduler;
if (oldScheduler != null) {
oldScheduler.cancel(false);
}
for (Channel channel : thing.getChannels()) {
updateState(channel.getUID(), UnDefType.UNDEF);
}
checkConnection();
}
}
@Override
public void dispose() {
ScheduledFuture<?> oldScheduler = pollingScheduler;
if (oldScheduler != null) {
boolean stopped = oldScheduler.cancel(true);
logger.debug("Stopped polling: {}", stopped);
}
pollingScheduler = null;
}
}

View File

@@ -0,0 +1,101 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link WlanThermoNanoConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Christian Schlipp - Initial contribution
*/
@NonNullByDefault
public class WlanThermoNanoConfiguration {
/**
* IP Address of WlanThermo.
*/
private String ipAddress = "";
/**
* Username of WlanThermo user.
*/
private @Nullable String username;
/**
* Password of WlanThermo user.
*/
private @Nullable String password;
/**
* Polling interval
*/
private int pollingInterval = 10;
public String getIpAddress() {
return ipAddress;
}
public URI getUri(String path) throws URISyntaxException {
String uri = ipAddress;
if (!uri.startsWith("http://")) {
uri = "http://" + uri;
}
if (!path.startsWith("/") && !uri.endsWith("/")) {
uri = uri + "/";
}
uri = uri + path;
return new URI(uri);
}
public URI getUri() throws URISyntaxException {
return getUri("");
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
@Nullable
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Nullable
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getPollingInterval() {
return pollingInterval;
}
public void setPollingInterval(int pollingInterval) {
this.pollingInterval = pollingInterval;
}
}

View File

@@ -0,0 +1,204 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.Authentication;
import org.eclipse.jetty.client.api.AuthenticationStore;
import org.eclipse.jetty.client.util.DigestAuthentication;
import org.eclipse.jetty.client.util.StringContentProvider;
import org.openhab.binding.wlanthermo.internal.api.nano.WlanThermoNanoCommandHandler;
import org.openhab.binding.wlanthermo.internal.api.nano.data.Data;
import org.openhab.binding.wlanthermo.internal.api.nano.settings.Settings;
import org.openhab.core.common.ThreadPoolManager;
import org.openhab.core.thing.*;
import org.openhab.core.thing.binding.BaseThingHandler;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
/**
* The {@link WlanThermoNanoHandler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Christian Schlipp - Initial contribution
*/
@NonNullByDefault
public class WlanThermoNanoHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(WlanThermoNanoHandler.class);
private WlanThermoNanoConfiguration config = new WlanThermoNanoConfiguration();
private WlanThermoNanoCommandHandler wlanThermoNanoCommandHandler = new WlanThermoNanoCommandHandler();
private final HttpClient httpClient;
private @Nullable ScheduledFuture<?> pollingScheduler;
private final ScheduledExecutorService scheduler = ThreadPoolManager
.getScheduledPool(WlanThermoBindingConstants.WLANTHERMO_THREAD_POOL);
private final Gson gson = new Gson();
private Data data = new Data();
private Settings settings = new Settings();
public WlanThermoNanoHandler(Thing thing, HttpClient httpClient) {
super(thing);
this.httpClient = httpClient;
}
@Override
public void initialize() {
logger.debug("Start initializing WlanThermo Nano!");
config = getConfigAs(WlanThermoNanoConfiguration.class);
updateStatus(ThingStatus.UNKNOWN);
try {
if (config.getUsername() != null && !config.getUsername().isEmpty() && config.getPassword() != null
&& !config.getPassword().isEmpty()) {
AuthenticationStore authStore = httpClient.getAuthenticationStore();
authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM,
config.getUsername(), config.getPassword()));
}
scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS);
logger.debug("Finished initializing WlanThermo Nano!");
} catch (URISyntaxException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Failed to initialize WlanThermo Nano!");
logger.debug("Failed to initialize WlanThermo Nano!", e);
}
}
private void checkConnection() {
try {
if (httpClient.GET(config.getUri()).getStatus() == 200) {
updateStatus(ThingStatus.ONLINE);
ScheduledFuture<?> oldScheduler = pollingScheduler;
if (oldScheduler != null) {
oldScheduler.cancel(false);
}
pollingScheduler = scheduler.scheduleWithFixedDelay(this::update, 0, config.getPollingInterval(),
TimeUnit.SECONDS);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"WlanThermo not found under given address.");
}
} catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) {
logger.debug("Failed to connect.", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Could not connect to WlanThermo at " + config.getIpAddress());
ScheduledFuture<?> oldScheduler = pollingScheduler;
if (oldScheduler != null) {
oldScheduler.cancel(false);
}
pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS);
}
}
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
State s = wlanThermoNanoCommandHandler.getState(channelUID, data, settings);
if (s != null)
updateState(channelUID, s);
} else {
if (wlanThermoNanoCommandHandler.setState(channelUID, command, data)) {
logger.debug("Data updated, pushing changes");
push();
} else {
logger.debug("Could not handle command of type {} for channel {}!",
command.getClass().toGenericString(), channelUID.getId());
}
}
}
private void update() {
try {
// Update objects with data from device
String json = httpClient.GET(config.getUri("/data")).getContentAsString();
data = gson.fromJson(json, Data.class);
logger.debug("Received at /data: {}", json);
json = httpClient.GET(config.getUri("/settings")).getContentAsString();
settings = gson.fromJson(json, Settings.class);
logger.debug("Received at /settings: {}", json);
// Update channels
for (Channel channel : thing.getChannels()) {
State state = wlanThermoNanoCommandHandler.getState(channel.getUID(), data, settings);
if (state != null) {
updateState(channel.getUID(), state);
} else {
// if we could not obtain a state, try trigger instead
String trigger = wlanThermoNanoCommandHandler.getTrigger(channel.getUID(), data);
if (trigger != null) {
triggerChannel(channel.getUID(), trigger);
}
}
}
} catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) {
logger.debug("Update failed, checking connection", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed, reconnecting...");
ScheduledFuture<?> oldScheduler = pollingScheduler;
if (oldScheduler != null) {
oldScheduler.cancel(false);
}
for (Channel channel : thing.getChannels()) {
updateState(channel.getUID(), UnDefType.UNDEF);
}
checkConnection();
}
}
private void push() {
data.getChannel().forEach(c -> {
try {
String json = gson.toJson(c);
logger.debug("Pushing: {}", json);
URI uri = config.getUri("/setchannels");
int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json")
.timeout(5, TimeUnit.SECONDS).send().getStatus();
if (status == 401) {
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!");
} else if (status != 200) {
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel "
+ c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString());
} else {
updateStatus(ThingStatus.ONLINE);
}
} catch (InterruptedException | TimeoutException | ExecutionException | URISyntaxException e) {
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Failed to update channel " + c.getName() + " on device!");
logger.debug("Failed to update channel {} on device", c.getName(), e);
}
});
}
@Override
public void dispose() {
ScheduledFuture<?> oldScheduler = pollingScheduler;
if (oldScheduler != null) {
boolean stopped = oldScheduler.cancel(true);
logger.debug("Stopped polling: {}", stopped);
}
pollingScheduler = null;
}
}

View File

@@ -0,0 +1,167 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.mini.builtin;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
* Be careful to not overwrite the getState/getTrigger function mapping the Data to OH channels!
*
* @author Christian Schlipp - Initial contribution
*/
public class App {
@SerializedName("temp_unit")
@Expose
private String tempUnit;
@SerializedName("pit")
@Expose
private Pit pit;
@SerializedName("pit2")
@Expose
private Pit pit2;
@SerializedName("cpu_load")
@Expose
private Double cpuLoad;
@SerializedName("cpu_temp")
@Expose
private Double cpuTemp;
@SerializedName("channel")
@Expose
private Channel channel;
@SerializedName("timestamp")
@Expose
private String timestamp;
/**
* No args constructor for use in serialization
*
*/
public App() {
}
/**
*
* @param cpuLoad
* @param pit2
* @param tempUnit
* @param channel
* @param pit
* @param cpuTemp
* @param timestamp
*/
public App(String tempUnit, Pit pit, Pit pit2, Double cpuLoad, Double cpuTemp, Channel channel, String timestamp) {
super();
this.tempUnit = tempUnit;
this.pit = pit;
this.pit2 = pit2;
this.cpuLoad = cpuLoad;
this.cpuTemp = cpuTemp;
this.channel = channel;
this.timestamp = timestamp;
}
public String getTempUnit() {
return tempUnit;
}
public void setTempUnit(String tempUnit) {
this.tempUnit = tempUnit;
}
public App withTempUnit(String tempUnit) {
this.tempUnit = tempUnit;
return this;
}
public Pit getPit() {
return pit;
}
public void setPit(Pit pit) {
this.pit = pit;
}
public App withPit(Pit pit) {
this.pit = pit;
return this;
}
public Pit getPit2() {
return pit2;
}
public void setPit2(Pit pit2) {
this.pit2 = pit2;
}
public App withPit2(Pit pit2) {
this.pit2 = pit2;
return this;
}
public Double getCpuLoad() {
return cpuLoad;
}
public void setCpuLoad(Double cpuLoad) {
this.cpuLoad = cpuLoad;
}
public App withCpuLoad(Double cpuLoad) {
this.cpuLoad = cpuLoad;
return this;
}
public Double getCpuTemp() {
return cpuTemp;
}
public void setCpuTemp(Double cpuTemp) {
this.cpuTemp = cpuTemp;
}
public App withCpuTemp(Double cpuTemp) {
this.cpuTemp = cpuTemp;
return this;
}
public Channel getChannel() {
return channel;
}
public void setChannel(Channel channel) {
this.channel = channel;
}
public App withChannel(Channel channel) {
this.channel = channel;
return this;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public App withTimestamp(String timestamp) {
this.timestamp = timestamp;
return this;
}
}

View File

@@ -0,0 +1,247 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.mini.builtin;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Channel {
@SerializedName("0")
@Expose
private Data _0;
@SerializedName("1")
@Expose
private Data _1;
@SerializedName("2")
@Expose
private Data _2;
@SerializedName("3")
@Expose
private Data _3;
@SerializedName("4")
@Expose
private Data _4;
@SerializedName("5")
@Expose
private Data _5;
@SerializedName("6")
@Expose
private Data _6;
@SerializedName("7")
@Expose
private Data _7;
@SerializedName("8")
@Expose
private Data _8;
@SerializedName("9")
@Expose
private Data _9;
/**
* No args constructor for use in serialization
*
*/
public Channel() {
}
/**
*
* @param _0
* @param _1
* @param _2
* @param _3
* @param _4
* @param _5
* @param _6
* @param _7
* @param _8
* @param _9
*/
public Channel(Data _0, Data _1, Data _2, Data _3, Data _4, Data _5, Data _6, Data _7, Data _8, Data _9) {
super();
this._0 = _0;
this._1 = _1;
this._2 = _2;
this._3 = _3;
this._4 = _4;
this._5 = _5;
this._6 = _6;
this._7 = _7;
this._8 = _8;
this._9 = _9;
}
public Data get0() {
return _0;
}
public void set0(Data _0) {
this._0 = _0;
}
public Channel with0(Data _0) {
this._0 = _0;
return this;
}
public Data get1() {
return _1;
}
public void set1(Data _1) {
this._1 = _1;
}
public Channel with1(Data _1) {
this._1 = _1;
return this;
}
public Data get2() {
return _2;
}
public void set2(Data _2) {
this._2 = _2;
}
public Channel with2(Data _2) {
this._2 = _2;
return this;
}
public Data get3() {
return _3;
}
public void set3(Data _3) {
this._3 = _3;
}
public Channel with3(Data _3) {
this._3 = _3;
return this;
}
public Data get4() {
return _4;
}
public void set4(Data _4) {
this._4 = _4;
}
public Channel with4(Data _4) {
this._4 = _4;
return this;
}
public Data get5() {
return _5;
}
public void set5(Data _5) {
this._5 = _5;
}
public Channel with5(Data _5) {
this._5 = _5;
return this;
}
public Data get6() {
return _6;
}
public void set6(Data _6) {
this._6 = _6;
}
public Channel with6(Data _6) {
this._6 = _6;
return this;
}
public Data get7() {
return _7;
}
public void set7(Data _7) {
this._7 = _7;
}
public Channel with7(Data _7) {
this._7 = _7;
return this;
}
public Data get8() {
return _8;
}
public void set8(Data _8) {
this._8 = _8;
}
public Channel with8(Data _8) {
this._8 = _8;
return this;
}
public Data get9() {
return _9;
}
public void set9(Data _9) {
this._9 = _9;
}
public Channel with9(Data _9) {
this._9 = _9;
return this;
}
public Data getData(int i) {
switch (i) {
case 0:
return get0();
case 1:
return get1();
case 2:
return get2();
case 3:
return get3();
case 4:
return get4();
case 5:
return get5();
case 6:
return get6();
case 7:
return get7();
case 8:
return get8();
case 9:
return get9();
default:
return null;
}
}
}

View File

@@ -0,0 +1,185 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.mini.builtin;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Data {
@SerializedName("temp")
@Expose
private Double temp;
@SerializedName("color")
@Expose
private String color;
@SerializedName("state")
@Expose
private String state;
@SerializedName("temp_min")
@Expose
private Double tempMin;
@SerializedName("temp_max")
@Expose
private Double tempMax;
@SerializedName("name")
@Expose
private String name;
@SerializedName("alert")
@Expose
private Boolean alert;
@SerializedName("show")
@Expose
private Boolean show;
/**
* No args constructor for use in serialization
*
*/
public Data() {
}
/**
*
* @param tempMax
* @param temp
* @param color
* @param alert
* @param name
* @param show
* @param state
* @param tempMin
*/
public Data(Double temp, String color, String state, Double tempMin, Double tempMax, String name, Boolean alert,
Boolean show) {
super();
this.temp = temp;
this.color = color;
this.state = state;
this.tempMin = tempMin;
this.tempMax = tempMax;
this.name = name;
this.alert = alert;
this.show = show;
}
public Double getTemp() {
return temp;
}
public void setTemp(Double temp) {
this.temp = temp;
}
public Data withTemp(Double temp) {
this.temp = temp;
return this;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public Data withColor(String color) {
this.color = color;
return this;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Data withState(String state) {
this.state = state;
return this;
}
public Double getTempMin() {
return tempMin;
}
public void setTempMin(Double tempMin) {
this.tempMin = tempMin;
}
public Data withTempMin(Double tempMin) {
this.tempMin = tempMin;
return this;
}
public Double getTempMax() {
return tempMax;
}
public void setTempMax(Double tempMax) {
this.tempMax = tempMax;
}
public Data withTempMax(Double tempMax) {
this.tempMax = tempMax;
return this;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Data withName(String name) {
this.name = name;
return this;
}
public Boolean getAlert() {
return alert;
}
public void setAlert(Boolean alert) {
this.alert = alert;
}
public Data withAlert(Boolean alert) {
this.alert = alert;
return this;
}
public Boolean getShow() {
return show;
}
public void setShow(Boolean show) {
this.show = show;
}
public Data withShow(Boolean show) {
this.show = show;
return this;
}
}

View File

@@ -0,0 +1,185 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.mini.builtin;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Pit {
@SerializedName("enabled")
@Expose
private Boolean enabled;
@SerializedName("timestamp")
@Expose
private String timestamp;
@SerializedName("setpoint")
@Expose
private Double setpoint;
@SerializedName("current")
@Expose
private Double current;
@SerializedName("control_out")
@Expose
private Integer controlOut;
@SerializedName("ch")
@Expose
private Integer ch;
@SerializedName("type")
@Expose
private String type;
@SerializedName("open_lid")
@Expose
private String openLid;
/**
* No args constructor for use in serialization
*
*/
public Pit() {
}
/**
*
* @param current
* @param setpoint
* @param ch
* @param openLid
* @param controlOut
* @param type
* @param enabled
* @param timestamp
*/
public Pit(Boolean enabled, String timestamp, Double setpoint, Double current, Integer controlOut, Integer ch,
String type, String openLid) {
super();
this.enabled = enabled;
this.timestamp = timestamp;
this.setpoint = setpoint;
this.current = current;
this.controlOut = controlOut;
this.ch = ch;
this.type = type;
this.openLid = openLid;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Pit withEnabled(Boolean enabled) {
this.enabled = enabled;
return this;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public Pit withTimestamp(String timestamp) {
this.timestamp = timestamp;
return this;
}
public Double getSetpoint() {
return setpoint;
}
public void setSetpoint(Double setpoint) {
this.setpoint = setpoint;
}
public Pit withSetpoint(Double setpoint) {
this.setpoint = setpoint;
return this;
}
public Double getCurrent() {
return current;
}
public void setCurrent(Double current) {
this.current = current;
}
public Pit withCurrent(Double current) {
this.current = current;
return this;
}
public Integer getControlOut() {
return controlOut;
}
public void setControlOut(Integer controlOut) {
this.controlOut = controlOut;
}
public Pit withControlOut(Integer controlOut) {
this.controlOut = controlOut;
return this;
}
public Integer getCh() {
return ch;
}
public void setCh(Integer ch) {
this.ch = ch;
}
public Pit withCh(Integer ch) {
this.ch = ch;
return this;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Pit withType(String type) {
this.type = type;
return this;
}
public String getOpenLid() {
return openLid;
}
public void setOpenLid(String openLid) {
this.openLid = openLid;
}
public Pit withOpenLid(String openLid) {
this.openLid = openLid;
return this;
}
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.mini.builtin;
import java.util.HashMap;
import java.util.Map;
/**
* The {@link UtilMini} class provides conversion functions for the WlanThermo Mini
*
* @author Christian Schlipp - Initial contribution
*/
public class UtilMini {
private static final Map<String, String> COLOR_MAPPINGS = createColorMap();
private static final String DEFAULT_HEX = "#ffffff";
private UtilMini() {
// hidden
}
private static Map<String, String> createColorMap() {
HashMap<String, String> map = new HashMap<>();
map.put("green", "#008000");
map.put("red", "#FF0000");
map.put("blue", "#0000FF");
map.put("olive", "#808000");
map.put("magenta", "#FF00FF");
map.put("yellow", "#FFFF00");
map.put("violet", "#EE82EE");
map.put("orange", "#FFA500");
map.put("mediumpurple3", "#9370DB");
map.put("aquamarine", "#7FFFD4");
map.put("brown", "#A52A2A");
map.put("plum", "#DDA0DD");
map.put("skyblue", "#87CEEB");
map.put("orange-red", "#FF4500");
map.put("salmon", "#FA8072");
map.put("black", "#000000");
map.put("dark-grey", "#A9A9A9");
map.put("purple", "800080");
map.put("turquoise", "#40E0D0");
map.put("khaki", "#F0E68C");
map.put("dark-violet", "#9400D3");
map.put("seagreen", "#2E8B57");
map.put("web-blue", "#0080ff");
map.put("steelblue", "#4682B4");
map.put("gold", "#FFD700");
map.put("dark-green", "#006400");
map.put("midnight-blue", "#191970");
map.put("dark-khaki", "#BDB76B");
map.put("dark-olivegreen", "#556B2F");
map.put("pink", "#FFC0CB");
map.put("chartreuse", "#7FFF00");
map.put("gray", "#808080");
map.put("slategrey", "#708090");
return map;
}
/**
* Convert WlanThermo Color Name to Hex
*
* @param colorName the WlanThermo color name
* @return The color as Hex String
*/
public static String toHex(String colorName) {
return COLOR_MAPPINGS.getOrDefault(colorName, DEFAULT_HEX);
}
}

View File

@@ -0,0 +1,164 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.mini.builtin;
import java.awt.*;
import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
/**
* The {@link WlanThermoMiniCommandHandler} is responsible for mapping the Commands to the respective data fields
* of the API.
*
* @author Christian Schlipp - Initial contribution
*/
public class WlanThermoMiniCommandHandler {
public State getState(ChannelUID channelUID, App app) {
State state = null;
if ("system".equals(channelUID.getGroupId())) {
switch (channelUID.getIdWithoutGroup()) {
case WlanThermoBindingConstants.SYSTEM_CPU_TEMP:
if (app.getCpuTemp() == null) {
state = UnDefType.UNDEF;
} else {
state = new DecimalType(app.getCpuTemp());
}
break;
case WlanThermoBindingConstants.SYSTEM_CPU_LOAD:
if (app.getCpuLoad() == null) {
state = UnDefType.UNDEF;
} else {
state = new DecimalType(app.getCpuLoad());
}
break;
}
} else if (channelUID.getId().startsWith("channel")) {
int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length()));
if (channelId >= 0 && channelId <= 9) {
Channel channel = app.getChannel();
if (channel == null) {
return UnDefType.UNDEF;
}
Data data = channel.getData(channelId);
switch (channelUID.getIdWithoutGroup()) {
case WlanThermoBindingConstants.CHANNEL_NAME:
state = new StringType(data.getName());
break;
case WlanThermoBindingConstants.CHANNEL_TEMP:
if (data.getState().equals("er")) {
state = UnDefType.UNDEF;
} else {
state = new DecimalType(data.getTemp());
}
break;
case WlanThermoBindingConstants.CHANNEL_MIN:
state = new DecimalType(data.getTempMin());
break;
case WlanThermoBindingConstants.CHANNEL_MAX:
state = new DecimalType(data.getTempMax());
break;
case WlanThermoBindingConstants.CHANNEL_ALARM_DEVICE:
state = OnOffType.from(data.getAlert());
break;
case WlanThermoBindingConstants.CHANNEL_ALARM_OPENHAB_HIGH:
if (!data.getState().equals("er") && data.getTemp() > data.getTempMax()) {
state = OnOffType.ON;
} else {
state = OnOffType.OFF;
}
break;
case WlanThermoBindingConstants.CHANNEL_ALARM_OPENHAB_LOW:
if (!data.getState().equals("er") && data.getTemp() < data.getTempMin()) {
state = OnOffType.ON;
} else {
state = OnOffType.OFF;
}
break;
case WlanThermoBindingConstants.CHANNEL_COLOR:
Color c = Color.decode(UtilMini.toHex(data.getColor()));
state = HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue());
break;
case WlanThermoBindingConstants.CHANNEL_COLOR_NAME:
state = new StringType(data.getColor());
break;
}
}
} else if (channelUID.getId().startsWith("pit")) {
Pit pit;
if (channelUID.getGroupId().equals("pit1")) {
pit = app.getPit();
} else if (channelUID.getGroupId().equals("pit2")) {
pit = app.getPit2();
} else {
return UnDefType.UNDEF;
}
if (pit == null || !pit.getEnabled()) {
return UnDefType.UNDEF;
}
switch (channelUID.getIdWithoutGroup()) {
case WlanThermoBindingConstants.CHANNEL_PITMASTER_ENABLED:
state = OnOffType.from(pit.getEnabled());
break;
case WlanThermoBindingConstants.CHANNEL_PITMASTER_CURRENT:
state = new DecimalType(pit.getCurrent());
break;
case WlanThermoBindingConstants.CHANNEL_PITMASTER_SETPOINT:
state = new DecimalType(pit.getSetpoint());
break;
case WlanThermoBindingConstants.CHANNEL_PITMASTER_DUTY_CYCLE:
state = new DecimalType(pit.getControlOut());
break;
case WlanThermoBindingConstants.CHANNEL_PITMASTER_LID_OPEN:
state = OnOffType.from(pit.getOpenLid().equals("True"));
break;
case WlanThermoBindingConstants.CHANNEL_PITMASTER_CHANNEL_ID:
state = new DecimalType(pit.getCh());
break;
}
}
return state;
}
public String getTrigger(ChannelUID channelUID, App app) {
String trigger = null;
if (channelUID.getId().startsWith("channel")) {
int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1;
if (channelId >= 0 && channelId <= 9) {
Channel channel = app.getChannel();
if (channel == null) {
return "";
}
Data data = channel.getData(channelId);
switch (channelUID.getIdWithoutGroup()) {
case "alarm_openhab":
if (!data.getState().equals("er")) {
if (data.getTemp() > data.getTempMax()) {
trigger = WlanThermoBindingConstants.TRIGGER_ALARM_MAX;
} else if (data.getTemp() < data.getTempMin()) {
trigger = WlanThermoBindingConstants.TRIGGER_ALARM_MIN;
}
}
}
}
}
return trigger;
}
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano;
import java.util.HashMap;
import java.util.Map;
/**
* The {@link UtilNano} class provides conversion functions for the WlanThermo Nano
*
* @author Christian Schlipp - Initial contribution
*/
public class UtilNano {
private static final Map<String, String> COLOR_MAPPINGS = createColorMap();
private static final String DEFAULT_HEX = "#ffffff";
private static final String DEFAULT_COLORNAME = "niagara";
private UtilNano() {
// hidden
}
private static Map<String, String> createColorMap() {
HashMap<String, String> map = new HashMap<>();
map.put("niagara", "#5587A2");
map.put("rosa", "#FFAEC9");
map.put("lapis blue", "#0C4C88");
map.put("orange", "#EF562D");
map.put("lila", "#A349A4");
map.put("red", "#ED1C24");
map.put("green", "#22B14C");
map.put("gold", "#FFC100");
map.put("kale", "#5C7148");
map.put("brown", "#804000");
return map;
}
/**
* Convert WlanThermo Color Name to Hex
*
* @param colorName the WlanThermo color name
* @return The color as Hex String
*/
public static String toHex(String colorName) {
return COLOR_MAPPINGS.getOrDefault(colorName, DEFAULT_HEX);
}
public static String toColorName(String colorHex) {
String colorName = null;
if (!colorHex.startsWith("#")) {
colorHex = "#" + colorHex;
}
for (Map.Entry<String, String> entry : COLOR_MAPPINGS.entrySet()) {
if (entry.getValue().equalsIgnoreCase(colorHex)) {
colorName = entry.getKey();
}
}
if (colorName == null) {
colorName = DEFAULT_COLORNAME;
}
return colorName;
}
}

View File

@@ -0,0 +1,261 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano;
import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*;
import java.awt.*;
import java.math.BigInteger;
import java.util.List;
import org.openhab.binding.wlanthermo.internal.api.nano.data.Channel;
import org.openhab.binding.wlanthermo.internal.api.nano.data.Data;
import org.openhab.binding.wlanthermo.internal.api.nano.data.Pm;
import org.openhab.binding.wlanthermo.internal.api.nano.data.System;
import org.openhab.binding.wlanthermo.internal.api.nano.settings.Settings;
import org.openhab.core.library.types.*;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
/**
* The {@link WlanThermoNanoCommandHandler} is responsible for mapping the Commands to the respective data fields
* of the API.
*
* @author Christian Schlipp - Initial contribution
*/
public class WlanThermoNanoCommandHandler {
public State getState(ChannelUID channelUID, Data data, Settings settings) {
State state = null;
System system = data.getSystem();
List<Channel> channel = data.getChannel();
if ("system".equals(channelUID.getGroupId()) && system != null) {
switch (channelUID.getIdWithoutGroup()) {
case SYSTEM_SOC:
state = new DecimalType(system.getSoc());
break;
case SYSTEM_CHARGE:
state = OnOffType.from(system.getCharge());
break;
case SYSTEM_RSSI_SIGNALSTRENGTH:
int dbm = system.getRssi();
if (dbm >= -80) {
state = new DecimalType(4);
} else if (dbm >= -95) {
state = new DecimalType(3);
} else if (dbm >= -105) {
state = new DecimalType(2);
} else {
state = new DecimalType(1);
}
break;
case SYSTEM_RSSI:
state = new DecimalType(system.getRssi());
break;
}
} else if (channelUID.getId().startsWith("channel")) {
int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1;
if (channel.size() > 0 && channelId <= channel.size()) {
switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_NAME:
state = new StringType(channel.get(channelId).getName());
break;
case CHANNEL_TYP:
state = new StringType(settings.sensors.get(channel.get(channelId).getTyp()));
break;
case CHANNEL_TEMP:
if (channel.get(channelId).getTemp() == 999.0) {
state = UnDefType.UNDEF;
} else {
state = new DecimalType(channel.get(channelId).getTemp());
}
break;
case CHANNEL_MIN:
state = new DecimalType(channel.get(channelId).getMin());
break;
case CHANNEL_MAX:
state = new DecimalType(channel.get(channelId).getMax());
break;
case CHANNEL_ALARM_DEVICE:
state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(1));
break;
case CHANNEL_ALARM_PUSH:
state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(0));
break;
case CHANNEL_ALARM_OPENHAB_HIGH:
if (channel.get(channelId).getTemp() != 999
&& channel.get(channelId).getTemp() > channel.get(channelId).getMax()) {
state = OnOffType.ON;
} else {
state = OnOffType.OFF;
}
break;
case CHANNEL_ALARM_OPENHAB_LOW:
if (channel.get(channelId).getTemp() != 999
&& channel.get(channelId).getTemp() < channel.get(channelId).getMin()) {
state = OnOffType.ON;
} else {
state = OnOffType.OFF;
}
break;
case CHANNEL_COLOR:
String color = channel.get(channelId).getColor();
if (color != null && !color.isEmpty()) {
Color c = Color.decode(color);
state = HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue());
}
break;
case CHANNEL_COLOR_NAME:
String colorHex = channel.get(channelId).getColor();
if (colorHex != null && !colorHex.isEmpty()) {
state = new StringType(UtilNano.toColorName(colorHex));
}
break;
}
}
} else if (channelUID.getId().startsWith("pit1")) {
if (data.getPitmaster() != null && data.getPitmaster().getPm() != null
&& data.getPitmaster().getPm().size() > 0) {
Pm pm = data.getPitmaster().getPm().get(0);
switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_PITMASTER_CHANNEL_ID:
state = new DecimalType(pm.getChannel());
break;
case CHANNEL_PITMASTER_PIDPROFILE:
state = new DecimalType(pm.getPid());
break;
case CHANNEL_PITMASTER_DUTY_CYCLE:
state = new DecimalType(pm.getValue());
break;
case CHANNEL_PITMASTER_SETPOINT:
state = new DecimalType(pm.getSet());
break;
case CHANNEL_PITMASTER_STATE:
state = new StringType(pm.getTyp());
}
} else {
return UnDefType.UNDEF;
}
}
return state;
}
public boolean setState(ChannelUID channelUID, Command command, Data data) {
boolean success = false;
List<Channel> channel = data.getChannel();
if (channelUID.getId().startsWith("channel")) {
int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1;
if (channel.size() > 0 && channelId <= channel.size()) {
switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_NAME:
if (command instanceof StringType) {
channel.get(channelId).setName(command.toFullString());
success = true;
}
break;
case CHANNEL_MIN:
if (command instanceof QuantityType) {
channel.get(channelId).setMin(((QuantityType) command).doubleValue());
success = true;
}
break;
case CHANNEL_MAX:
if (command instanceof QuantityType) {
channel.get(channelId).setMax(((QuantityType) command).doubleValue());
success = true;
}
break;
case CHANNEL_ALARM_DEVICE:
if (command instanceof OnOffType) {
BigInteger value;
if (command == OnOffType.ON) {
value = BigInteger.valueOf(channel.get(channelId).getAlarm()).setBit(1);
} else {
value = BigInteger.valueOf(channel.get(channelId).getAlarm()).clearBit(1);
}
channel.get(channelId).setAlarm(value.intValue());
success = true;
}
break;
case CHANNEL_ALARM_PUSH:
if (command instanceof OnOffType) {
BigInteger value;
if (command == OnOffType.ON) {
value = BigInteger.valueOf(channel.get(channelId).getAlarm()).setBit(0);
} else {
value = BigInteger.valueOf(channel.get(channelId).getAlarm()).clearBit(0);
}
channel.get(channelId).setAlarm(value.intValue());
success = true;
}
break;
case CHANNEL_COLOR_NAME:
if (command instanceof StringType) {
channel.get(channelId).setColor(UtilNano.toHex(((StringType) command).toString()));
success = true;
}
break;
}
}
} else if (channelUID.getId().equals("pit1")) {
if (data.getPitmaster() != null && data.getPitmaster().getPm() != null
&& data.getPitmaster().getPm().size() > 0) {
Pm pm = data.getPitmaster().getPm().get(0);
switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_PITMASTER_CHANNEL_ID:
pm.setChannel(((QuantityType) command).intValue());
success = true;
break;
case CHANNEL_PITMASTER_PIDPROFILE:
pm.setPid(((QuantityType) command).intValue());
success = true;
break;
case CHANNEL_PITMASTER_SETPOINT:
pm.setSet(((QuantityType) command).doubleValue());
success = true;
break;
case CHANNEL_PITMASTER_STATE:
String state = ((StringType) command).toString();
if (state.equalsIgnoreCase("off") || state.equalsIgnoreCase("manual")
|| state.equalsIgnoreCase("auto")) {
pm.setTyp(state);
success = true;
}
}
}
}
return success;
}
public String getTrigger(ChannelUID channelUID, Data data) {
String trigger = null;
List<Channel> channel = data.getChannel();
if (channelUID.getId().startsWith("channel")) {
int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1;
if (channel.size() > 0 && channelId <= channel.size()) {
if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) {
if (channel.get(channelId).getTemp() != 999) {
if (channel.get(channelId).getTemp() > channel.get(channelId).getMax()) {
trigger = TRIGGER_ALARM_MAX;
} else if (channel.get(channelId).getTemp() < channel.get(channelId).getMin()) {
trigger = TRIGGER_ALARM_MIN;
}
}
}
}
}
return trigger;
}
}

View File

@@ -0,0 +1,186 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.data;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Channel {
@SerializedName("number")
@Expose
private Integer number;
@SerializedName("name")
@Expose
private String name;
@SerializedName("typ")
@Expose
private Integer typ;
@SerializedName("temp")
@Expose
private Double temp;
@SerializedName("min")
@Expose
private Double min;
@SerializedName("max")
@Expose
private Double max;
@SerializedName("alarm")
@Expose
private Integer alarm;
@SerializedName("color")
@Expose
private String color;
/**
* No args constructor for use in serialization
*
*/
public Channel() {
}
/**
*
* @param number
* @param temp
* @param min
* @param color
* @param max
* @param name
* @param alarm
* @param typ
*/
public Channel(Integer number, String name, Integer typ, Double temp, Double min, Double max, Integer alarm,
String color) {
super();
this.number = number;
this.name = name;
this.typ = typ;
this.temp = temp;
this.min = min;
this.max = max;
this.alarm = alarm;
this.color = color;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public Channel withNumber(Integer number) {
this.number = number;
return this;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Channel withName(String name) {
this.name = name;
return this;
}
public Integer getTyp() {
return typ;
}
public void setTyp(Integer typ) {
this.typ = typ;
}
public Channel withTyp(Integer typ) {
this.typ = typ;
return this;
}
public Double getTemp() {
return temp;
}
public void setTemp(Double temp) {
this.temp = temp;
}
public Channel withTemp(Double temp) {
this.temp = temp;
return this;
}
public Double getMin() {
return min;
}
public void setMin(Double min) {
this.min = min;
}
public Channel withMin(Double min) {
this.min = min;
return this;
}
public Double getMax() {
return max;
}
public void setMax(Double max) {
this.max = max;
}
public Channel withMax(Double max) {
this.max = max;
return this;
}
public Integer getAlarm() {
return alarm;
}
public void setAlarm(Integer alarm) {
this.alarm = alarm;
}
public Channel withAlarm(Integer alarm) {
this.alarm = alarm;
return this;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public Channel withColor(String color) {
this.color = color;
return this;
}
}

View File

@@ -0,0 +1,93 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.data;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
* Be careful to not overwrite the setState/getState/getTrigger function mapping the Data to OH channels!
*
* @author Christian Schlipp - Initial contribution
*/
public class Data {
@SerializedName("system")
@Expose
private System system;
@SerializedName("channel")
@Expose
private List<Channel> channel = new ArrayList<>();
@SerializedName("pitmaster")
@Expose
private Pitmaster pitmaster;
/**
* No args constructor for use in serialization
*
*/
public Data() {
}
public Data(System system, List<Channel> channel, Pitmaster pitmaster) {
super();
this.system = system;
this.channel = channel;
this.pitmaster = pitmaster;
}
public System getSystem() {
return system;
}
public void setSystem(System system) {
this.system = system;
}
public Data withSystem(System system) {
this.system = system;
return this;
}
public List<Channel> getChannel() {
return channel;
}
public void setChannel(List<Channel> channel) {
this.channel = channel;
}
public Data withChannel(List<Channel> channel) {
this.channel = channel;
return this;
}
public Pitmaster getPitmaster() {
return pitmaster;
}
public void setPitmaster(Pitmaster pitmaster) {
this.pitmaster = pitmaster;
}
public Data withPitmaster(Pitmaster pitmaster) {
this.pitmaster = pitmaster;
return this;
}
}

View File

@@ -0,0 +1,80 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.data;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Pitmaster {
@SerializedName("type")
@Expose
private List<String> type = new ArrayList<String>();
@SerializedName("pm")
@Expose
private List<Pm> pm = new ArrayList<Pm>();
/**
* No args constructor for use in serialization
*
*/
public Pitmaster() {
}
/**
*
* @param type
* @param pm
*/
public Pitmaster(List<String> type, List<Pm> pm) {
super();
this.type = type;
this.pm = pm;
}
public List<String> getType() {
return type;
}
public void setType(List<String> type) {
this.type = type;
}
public Pitmaster withType(List<String> type) {
this.type = type;
return this;
}
public List<Pm> getPm() {
return pm;
}
public void setPm(List<Pm> pm) {
this.pm = pm;
}
public Pitmaster withPm(List<Pm> pm) {
this.pm = pm;
return this;
}
}

View File

@@ -0,0 +1,186 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.data;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Pm {
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("channel")
@Expose
private Integer channel;
@SerializedName("pid")
@Expose
private Integer pid;
@SerializedName("value")
@Expose
private Integer value;
@SerializedName("set")
@Expose
private Double set;
@SerializedName("typ")
@Expose
private String typ;
@SerializedName("set_color")
@Expose
private String setColor;
@SerializedName("value_color")
@Expose
private String valueColor;
/**
* No args constructor for use in serialization
*
*/
public Pm() {
}
/**
*
* @param set
* @param setColor
* @param channel
* @param pid
* @param typ
* @param id
* @param value
* @param valueColor
*/
public Pm(Integer id, Integer channel, Integer pid, Integer value, Double set, String typ, String setColor,
String valueColor) {
super();
this.id = id;
this.channel = channel;
this.pid = pid;
this.value = value;
this.set = set;
this.typ = typ;
this.setColor = setColor;
this.valueColor = valueColor;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Pm withId(Integer id) {
this.id = id;
return this;
}
public Integer getChannel() {
return channel;
}
public void setChannel(Integer channel) {
this.channel = channel;
}
public Pm withChannel(Integer channel) {
this.channel = channel;
return this;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public Pm withPid(Integer pid) {
this.pid = pid;
return this;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public Pm withValue(Integer value) {
this.value = value;
return this;
}
public Double getSet() {
return set;
}
public void setSet(Double set) {
this.set = set;
}
public Pm withSet(Double set) {
this.set = set;
return this;
}
public String getTyp() {
return typ;
}
public void setTyp(String typ) {
this.typ = typ;
}
public Pm withTyp(String typ) {
this.typ = typ;
return this;
}
public String getSetColor() {
return setColor;
}
public void setSetColor(String setColor) {
this.setColor = setColor;
}
public Pm withSetColor(String setColor) {
this.setColor = setColor;
return this;
}
public String getValueColor() {
return valueColor;
}
public void setValueColor(String valueColor) {
this.valueColor = valueColor;
}
public Pm withValueColor(String valueColor) {
this.valueColor = valueColor;
return this;
}
}

View File

@@ -0,0 +1,149 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.data;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class System {
@SerializedName("time")
@Expose
private String time;
@SerializedName("unit")
@Expose
private String unit;
@SerializedName("soc")
@Expose
private Integer soc;
@SerializedName("charge")
@Expose
private Boolean charge;
@SerializedName("rssi")
@Expose
private Integer rssi;
@SerializedName("online")
@Expose
private Integer online;
/**
* No args constructor for use in serialization
*
*/
public System() {
}
/**
*
* @param unit
* @param rssi
* @param charge
* @param soc
* @param online
* @param time
*/
public System(String time, String unit, Integer soc, Boolean charge, Integer rssi, Integer online) {
super();
this.time = time;
this.unit = unit;
this.soc = soc;
this.charge = charge;
this.rssi = rssi;
this.online = online;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public System withTime(String time) {
this.time = time;
return this;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public System withUnit(String unit) {
this.unit = unit;
return this;
}
public Integer getSoc() {
return soc;
}
public void setSoc(Integer soc) {
this.soc = soc;
}
public System withSoc(Integer soc) {
this.soc = soc;
return this;
}
public Boolean getCharge() {
return charge;
}
public void setCharge(Boolean charge) {
this.charge = charge;
}
public System withCharge(Boolean charge) {
this.charge = charge;
return this;
}
public Integer getRssi() {
return rssi;
}
public void setRssi(Integer rssi) {
this.rssi = rssi;
}
public System withRssi(Integer rssi) {
this.rssi = rssi;
return this;
}
public Integer getOnline() {
return online;
}
public void setOnline(Integer online) {
this.online = online;
}
public System withOnline(Integer online) {
this.online = online;
return this;
}
}

View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.settings;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Api {
@SerializedName("version")
@Expose
public String version;
}

View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.settings;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Device {
@SerializedName("device")
@Expose
public String device;
@SerializedName("serial")
@Expose
public String serial;
@SerializedName("item")
@Expose
public String item;
@SerializedName("hw_version")
@Expose
public String hwVersion;
@SerializedName("sw_version")
@Expose
public String swVersion;
@SerializedName("api_version")
@Expose
public String apiVersion;
@SerializedName("language")
@Expose
public String language;
}

View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.settings;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Ext {
@SerializedName("on")
@Expose
public Integer on;
@SerializedName("token")
@Expose
public String token;
@SerializedName("id")
@Expose
public String id;
@SerializedName("repeat")
@Expose
public Integer repeat;
@SerializedName("service")
@Expose
public Integer service;
@SerializedName("services")
@Expose
public List<String> services = new ArrayList<String>();
}

View File

@@ -0,0 +1,59 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.settings;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Iot {
@SerializedName("PMQhost")
@Expose
public String pMQhost;
@SerializedName("PMQport")
@Expose
public Integer pMQport;
@SerializedName("PMQuser")
@Expose
public String pMQuser;
@SerializedName("PMQpass")
@Expose
public String pMQpass;
@SerializedName("PMQqos")
@Expose
public Integer pMQqos;
@SerializedName("PMQon")
@Expose
public Boolean pMQon;
@SerializedName("PMQint")
@Expose
public Integer pMQint;
@SerializedName("CLon")
@Expose
public Boolean cLon;
@SerializedName("CLtoken")
@Expose
public String cLtoken;
@SerializedName("CLint")
@Expose
public Integer cLint;
@SerializedName("CLurl")
@Expose
public String cLurl;
}

View File

@@ -0,0 +1,35 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.settings;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Notes {
@SerializedName("fcm")
@Expose
public List<Object> fcm = new ArrayList<Object>();
@SerializedName("ext")
@Expose
public Ext ext;
}

View File

@@ -0,0 +1,59 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.settings;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Pid {
@SerializedName("name")
@Expose
public String name;
@SerializedName("id")
@Expose
public Integer id;
@SerializedName("aktor")
@Expose
public Integer aktor;
@SerializedName("Kp")
@Expose
public Double kp;
@SerializedName("Ki")
@Expose
public Double ki;
@SerializedName("Kd")
@Expose
public Double kd;
@SerializedName("DCmmin")
@Expose
public Double dCmmin;
@SerializedName("DCmmax")
@Expose
public Double dCmmax;
@SerializedName("opl")
@Expose
public Integer opl;
@SerializedName("tune")
@Expose
public Integer tune;
@SerializedName("jp")
@Expose
public Integer jp;
}

View File

@@ -0,0 +1,56 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.settings;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class Settings {
@SerializedName("device")
@Expose
public Device device;
@SerializedName("system")
@Expose
public System system;
@SerializedName("hardware")
@Expose
public List<String> hardware = new ArrayList<String>();
@SerializedName("api")
@Expose
public Api api;
@SerializedName("sensors")
@Expose
public List<String> sensors = new ArrayList<String>();
@SerializedName("pid")
@Expose
public List<Pid> pid = new ArrayList<Pid>();
@SerializedName("aktor")
@Expose
public List<String> aktor = new ArrayList<String>();
@SerializedName("iot")
@Expose
public Iot iot;
@SerializedName("notes")
@Expose
public Notes notes;
}

View File

@@ -0,0 +1,56 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.wlanthermo.internal.api.nano.settings;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* This DTO is used to parse the JSON
* Class is auto-generated from JSON using http://www.jsonschema2pojo.org/
*
* @author Christian Schlipp - Initial contribution
*/
public class System {
@SerializedName("time")
@Expose
public String time;
@SerializedName("unit")
@Expose
public String unit;
@SerializedName("ap")
@Expose
public String ap;
@SerializedName("host")
@Expose
public String host;
@SerializedName("language")
@Expose
public String language;
@SerializedName("version")
@Expose
public String version;
@SerializedName("getupdate")
@Expose
public String getupdate;
@SerializedName("autoupd")
@Expose
public Boolean autoupd;
@SerializedName("hwversion")
@Expose
public String hwversion;
@SerializedName("god")
@Expose
public Integer god;
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<binding:binding id="wlanthermo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:binding="https://openhab.org/schemas/binding/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd">
<name>WlanThermo Binding</name>
<description>This is the binding for WlanThermo, ref. https://wlanthermo.de/</description>
<author>Christian Schlipp</author>
</binding:binding>

View File

@@ -0,0 +1,463 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="wlanthermo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
<thing-type id="nano">
<label>WlanThermo Nano</label>
<description>WlanThermo Nano V1/V1+</description>
<channel-groups>
<channel-group id="system" typeId="cg_system_nano"/>
<channel-group id="channel1" typeId="cg_temperature_nano">
<label>Temperature Probe 1</label>
<description>This group contains all channels for temperature probe 1</description>
</channel-group>
<channel-group id="channel2" typeId="cg_temperature_nano">
<label>Temperature Probe 2</label>
<description>This group contains all channels for temperature probe 2</description>
</channel-group>
<channel-group id="channel3" typeId="cg_temperature_nano">
<label>Temperature Probe 3</label>
<description>This group contains all channels for temperature probe 3</description>
</channel-group>
<channel-group id="channel4" typeId="cg_temperature_nano">
<label>Temperature Probe 4</label>
<description>This group contains all channels for temperature probe 4</description>
</channel-group>
<channel-group id="channel5" typeId="cg_temperature_nano">
<label>Temperature Probe 5</label>
<description>This group contains all channels for temperature probe 5</description>
</channel-group>
<channel-group id="channel6" typeId="cg_temperature_nano">
<label>Temperature Probe 6</label>
<description>This group contains all channels for temperature probe 6</description>
</channel-group>
<channel-group id="channel7" typeId="cg_temperature_nano">
<label>Temperature Probe 7</label>
<description>This group contains all channels for temperature probe 7</description>
</channel-group>
<channel-group id="channel8" typeId="cg_temperature_nano">
<label>Temperature Probe 8</label>
<description>This group contains all channels for temperature probe 8</description>
</channel-group>
<channel-group id="pit1" typeId="cg_pitmaster_nano">
<label>Pitmaster 1</label>
<description>This group contains all channels for pitmaster channel 1</description>
</channel-group>
</channel-groups>
<config-description>
<parameter name="ipAddress" type="text" required="true">
<context>network-address</context>
<label>Network Address</label>
<description>Network address of the WlanThermo Nano.</description>
</parameter>
<parameter name="username" type="text">
<label>Username</label>
<description>Optional, only required for write access. Default: 'admin'</description>
<default>admin</default>
</parameter>
<parameter name="password" type="text">
<context>password</context>
<label>Password</label>
<description>Optional, only required for write access. Default: 'admin'</description>
<default>admin</default>
</parameter>
<parameter name="pollingInterval" type="integer" min="1" step="1" unit="s" required="true">
<label>Polling Interval</label>
<description>Seconds between fetching values from the WlanThermo Nano.</description>
<default>10</default>
</parameter>
</config-description>
</thing-type>
<thing-type id="mini">
<label>WlanThermo Mini</label>
<description>WlanThermo Mini</description>
<channel-groups>
<channel-group id="system" typeId="cg_system_mini"/>
<channel-group id="channel0" typeId="cg_temperature_mini">
<label>Temperature Probe 1</label>
<description>This group contains all channels for temperature probe 1</description>
</channel-group>
<channel-group id="channel1" typeId="cg_temperature_mini">
<label>Temperature Probe 2</label>
<description>This group contains all channels for temperature probe 2</description>
</channel-group>
<channel-group id="channel2" typeId="cg_temperature_mini">
<label>Temperature Probe 3</label>
<description>This group contains all channels for temperature probe 3</description>
</channel-group>
<channel-group id="channel3" typeId="cg_temperature_mini">
<label>Temperature Probe 4</label>
<description>This group contains all channels for temperature probe 4</description>
</channel-group>
<channel-group id="channel4" typeId="cg_temperature_mini">
<label>Temperature Probe 5</label>
<description>This group contains all channels for temperature probe 5</description>
</channel-group>
<channel-group id="channel5" typeId="cg_temperature_mini">
<label>Temperature Probe 6</label>
<description>This group contains all channels for temperature probe 6</description>
</channel-group>
<channel-group id="channel6" typeId="cg_temperature_mini">
<label>Temperature Probe 7</label>
<description>This group contains all channels for temperature probe 7</description>
</channel-group>
<channel-group id="channel7" typeId="cg_temperature_mini">
<label>Temperature Probe 8</label>
<description>This group contains all channels for temperature probe 8</description>
</channel-group>
<channel-group id="channel8" typeId="cg_temperature_mini">
<label>Temperature Probe 9</label>
<description>This group contains all channels for temperature probe 9</description>
</channel-group>
<channel-group id="channel9" typeId="cg_temperature_mini">
<label>Temperature Probe 10</label>
<description>This group contains all channels for temperature probe 10</description>
</channel-group>
<channel-group id="pit1" typeId="cg_pitmaster_mini">
<label>Pitmaster 1</label>
<description>This group contains all channels for pitmaster channel 1</description>
</channel-group>
<channel-group id="pit2" typeId="cg_pitmaster_mini">
<label>Pitmaster 2</label>
<description>This group contains all channels for pitmaster channel 2</description>
</channel-group>
</channel-groups>
<config-description>
<parameter name="ipAddress" type="text" required="true">
<context>network-address</context>
<label>Network Address</label>
<description>Network address of the WlanThermo Mini.</description>
</parameter>
<parameter name="pollingInterval" type="integer" min="1" step="1" unit="s" required="true">
<label>Polling Interval</label>
<description>Seconds between fetching values from the WlanThermo Mini.</description>
<default>10</default>
</parameter>
</config-description>
</thing-type>
<!-- System Group Nano -->
<channel-group-type id="cg_system_nano">
<label>System Channel</label>
<description>This group contains all system channels</description>
<channels>
<channel id="soc" typeId="system.battery-level"/>
<channel id="charge" typeId="charging"/>
<channel id="rssi" typeId="rssi"/>
<channel id="rssi_signalstrength" typeId="system.signal-strength"/>
</channels>
</channel-group-type>
<channel-type id="charging" advanced="true">
<item-type>Switch</item-type>
<label>Charging</label>
<category>Energy</category>
<state readOnly="true"/>
</channel-type>
<channel-type id="rssi" advanced="true">
<item-type>Number</item-type>
<label>RSSI in dBm</label>
<category>Text</category>
<state readOnly="true"/>
</channel-type>
<!-- System Group Mini -->
<channel-group-type id="cg_system_mini">
<label>System Channel</label>
<description>This group contains all system channels</description>
<channels>
<channel id="cpu_load" typeId="cpu_load"/>
<channel id="cpu_temp" typeId="temperature"/>
</channels>
</channel-group-type>
<channel-type id="cpu_load" advanced="true">
<item-type>Number</item-type>
<label>CPU Load</label>
<state readOnly="true"/>
</channel-type>
<!-- Temperature Group Nano -->
<channel-group-type id="cg_temperature_nano">
<label>Sensor Nano</label>
<category>Sensor</category>
<channels>
<channel id="name" typeId="name"/>
<channel id="typ" typeId="typ"/>
<channel id="temp" typeId="temperature"/>
<channel id="min" typeId="temperature_min"/>
<channel id="max" typeId="temperature_max"/>
<channel id="alarm_device" typeId="alarm_device"/>
<channel id="alarm_push" typeId="alarm_push"/>
<channel id="alarm_openhab" typeId="alarm_openhab"/>
<channel id="alarm_openhab_low" typeId="alarm_openhab_low"/>
<channel id="alarm_openhab_high" typeId="alarm_openhab_high"/>
<channel id="color" typeId="color"/>
<channel id="color_name" typeId="color_name"/>
</channels>
</channel-group-type>
<!-- Channel Group Temperature Mini -->
<channel-group-type id="cg_temperature_mini">
<label>Sensor Mini</label>
<category>Sensor</category>
<channels>
<channel id="name" typeId="name_ro"/>
<channel id="temp" typeId="temperature"/>
<channel id="min" typeId="temperature_min_ro"/>
<channel id="max" typeId="temperature_max_ro"/>
<channel id="alarm_device" typeId="alarm_device_ro"/>
<channel id="alarm_openhab" typeId="alarm_openhab"/>
<channel id="alarm_openhab_low" typeId="alarm_openhab_low"/>
<channel id="alarm_openhab_high" typeId="alarm_openhab_high"/>
<channel id="color" typeId="color_ro"/>
<channel id="color_name" typeId="color_name_ro"/>
</channels>
</channel-group-type>
<!-- Fundamental channel types -->
<channel-type id="name" advanced="false">
<item-type>String</item-type>
<label>Probe Name</label>
<category>Text</category>
</channel-type>
<channel-type id="name_ro" advanced="false">
<item-type>String</item-type>
<label>Probe Name</label>
<category>Text</category>
<state readOnly="true"/>
</channel-type>
<channel-type id="typ" advanced="true">
<item-type>String</item-type>
<label>Probe Type</label>
<category>Text</category>
<state readOnly="true"/>
</channel-type>
<channel-type id="temperature" advanced="false">
<item-type>Number:Temperature</item-type>
<label>Current Temperature</label>
<category>Temperature</category>
<state min="0" pattern="%.1f %unit%" readOnly="true"/>
</channel-type>
<channel-type id="temperature_min" advanced="true">
<item-type>Number:Temperature</item-type>
<label>Low Temperature Alarm</label>
<category>Temperature</category>
<state min="0" step="0.1" pattern="%.1f %unit%" readOnly="false"/>
</channel-type>
<channel-type id="temperature_max" advanced="true">
<item-type>Number:Temperature</item-type>
<label>High Temperature Alarm</label>
<category>Temperature</category>
<state min="0" step="0.1" pattern="%.1f %unit%" readOnly="false"/>
</channel-type>
<channel-type id="temperature_min_ro" advanced="true">
<item-type>Number:Temperature</item-type>
<label>Low Temperature Alarm</label>
<category>Temperature</category>
<state min="0" step="0.1" pattern="%.1f %unit%" readOnly="true"/>
</channel-type>
<channel-type id="temperature_max_ro" advanced="true">
<item-type>Number:Temperature</item-type>
<label>High Temperature Alarm</label>
<category>Temperature</category>
<state min="0" step="0.1" pattern="%.1f %unit%" readOnly="true"/>
</channel-type>
<channel-type id="alarm_device" advanced="true">
<item-type>Switch</item-type>
<label>Alarm Buzzer</label>
<category>Switch</category>
</channel-type>
<channel-type id="alarm_device_ro" advanced="true">
<item-type>Switch</item-type>
<label>Alarm Buzzer</label>
<category>Switch</category>
<state readOnly="true"/>
</channel-type>
<channel-type id="alarm_push" advanced="true">
<item-type>Switch</item-type>
<label>Push-Alarm</label>
<category>Switch</category>
</channel-type>
<channel-type id="alarm_openhab" advanced="true">
<kind>trigger</kind>
<label>Openhab Alarm Trigger</label>
<event>
<options>
<option value="MIN">Low Temperature Alarm</option>
<option value="MAX">High Temperature Alarm</option>
</options>
</event>
</channel-type>
<channel-type id="alarm_openhab_low" advanced="false">
<item-type>Switch</item-type>
<label>Low Temperature Alarm</label>
<state readOnly="true"/>
</channel-type>
<channel-type id="alarm_openhab_high" advanced="false">
<item-type>Switch</item-type>
<label>High Temperature Alarm</label>
<state readOnly="true"/>
</channel-type>
<channel-type id="color" advanced="true">
<item-type>Color</item-type>
<label>Color</label>
<category>Colorpicker</category>
<state readOnly="true"/>
</channel-type>
<channel-type id="color_name" advanced="true">
<item-type>String</item-type>
<label>Probe Color</label>
<category>Colorpicker</category>
<state>
<options>
<option value="niagara">Niagara</option>
<option value="rosa">Rosa</option>
<option value="lapis blue">Lapis Blue</option>
<option value="orange">Orange</option>
<option value="lila">Lila</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="gold">Gold</option>
<option value="kale">Kale</option>
<option value="brown">Brown</option>
</options>
</state>
</channel-type>
<channel-type id="color_ro" advanced="true">
<item-type>Color</item-type>
<label>Probe Color</label>
<category>Colorpicker</category>
<state readOnly="true"/>
</channel-type>
<channel-type id="color_name_ro" advanced="true">
<item-type>String</item-type>
<label>Probe Color Name</label>
<category>Text</category>
<state readOnly="true"/>
</channel-type>
<!-- Pitmaster Mini -->
<channel-group-type id="cg_pitmaster_mini">
<label>Pitmaster Mini</label>
<category>Sensor</category>
<channels>
<channel id="enabled" typeId="enabled"/>
<channel id="current" typeId="temperature"/>
<channel id="setpoint" typeId="temperature_setpoint_ro"/>
<channel id="duty_cycle" typeId="duty_cycle_ro"/>
<channel id="lid_open" typeId="lid_open"/>
<channel id="channel_id" typeId="channel_id_ro"/>
</channels>
</channel-group-type>
<channel-type id="enabled" advanced="false">
<item-type>Switch</item-type>
<label>Pitmaster Enabled</label>
<state readOnly="true"/>
</channel-type>
<channel-type id="temperature_setpoint_ro" advanced="false">
<item-type>Number:Temperature</item-type>
<label>Pitmaster Setpoint Temperature</label>
<category>Temperature</category>
<state min="0" pattern="%.1f %unit%" readOnly="true"/>
</channel-type>
<channel-type id="duty_cycle_ro" advanced="false">
<item-type>Number</item-type>
<label>Pitmaster Duty Cycle / Control Out</label>
<state min="0" max="100" pattern="%d" readOnly="true"/>
</channel-type>
<channel-type id="lid_open" advanced="false">
<item-type>Switch</item-type>
<label>Pitmaster Lid Open</label>
<state readOnly="true"/>
</channel-type>
<channel-type id="channel_id_ro" advanced="false">
<item-type>Number</item-type>
<label>Pitmaster Channel ID</label>
<state min="0" max="9" pattern="%d" readOnly="true"/>
</channel-type>
<!-- Pitmaster Nano -->
<channel-group-type id="cg_pitmaster_nano">
<label>Pitmaster Nano</label>
<category>Sensor</category>
<channels>
<channel id="state" typeId="pitmaster_type"/>
<channel id="setpoint" typeId="temperature_setpoint"/>
<channel id="duty_cycle" typeId="duty_cycle"/>
<channel id="channel_id" typeId="channel_id"/>
<channel id="pid_id" typeId="pid_id"/>
</channels>
</channel-group-type>
<channel-type id="pitmaster_type" advanced="false">
<item-type>String</item-type>
<label>Pitmaster State</label>
<state>
<options>
<option value="off">Off</option>
<option value="manual">Manual</option>
<option value="auto">Auto</option>
<!--<option value="autotune">Autotune</option> Not clear if still supported -->
</options>
</state>
</channel-type>
<channel-type id="duty_cycle" advanced="false">
<item-type>Number</item-type>
<label>Pitmaster Duty Cycle / Control Out</label>
<state min="0" max="100" pattern="%d"/>
</channel-type>
<channel-type id="pid_id" advanced="false">
<item-type>Number</item-type>
<label>PID Profile ID</label>
<state pattern="%d"/>
</channel-type>
<channel-type id="temperature_setpoint" advanced="false">
<item-type>Number:Temperature</item-type>
<label>Pitmaster Setpoint Temperature</label>
<category>Temperature</category>
<state min="0" pattern="%.1f %unit%"/>
</channel-type>
<channel-type id="channel_id" advanced="false">
<item-type>Number</item-type>
<label>Pitmaster Channel ID</label>
<state min="1" max="8" pattern="%d"/>
</channel-type>
</thing:thing-descriptions>