diff --git a/AUTHORS b/AUTHORS index 050aad496b902..2164c4965f160 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,14 @@ # This file lists all individuals having contributed content to the repository. -# If you're submitting a patch, please add your name here in alphabetical order as part of the patch. -# -# For a list of active project maintainers, see the MAINTAINERS file. -# +# For how it is generated, see `project-orga/generate-authors.sh`. + +Dancho Penev +Gerhard Riegler +Gaël L'hopital +Gideon le Grange +Jochen Hiller Kai Kreuzer +Karel Goderis +manroh +Marcel Verpaalen +Oliver Libutzki Thomas Eichstädt-Engelen diff --git a/addons/binding/org.openhab.binding.freebox/.classpath b/addons/binding/org.openhab.binding.freebox/.classpath new file mode 100644 index 0000000000000..9bf0580367a05 --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/.classpath @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/addons/binding/org.openhab.binding.freebox/.project b/addons/binding/org.openhab.binding.freebox/.project new file mode 100644 index 0000000000000..4d20df9e2e70f --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/.project @@ -0,0 +1,33 @@ + + + org.openhab.binding.freebox + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/addons/binding/org.openhab.binding.freebox/.settings/org.eclipse.pde.core.prefs b/addons/binding/org.openhab.binding.freebox/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000000000..923c37fb8d55b --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +resolve.requirebundle=false diff --git a/addons/binding/org.openhab.binding.freebox/ESH-INF/binding/binding.xml b/addons/binding/org.openhab.binding.freebox/ESH-INF/binding/binding.xml new file mode 100644 index 0000000000000..db6751f6d6559 --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/ESH-INF/binding/binding.xml @@ -0,0 +1,11 @@ + + + + Freebox Binding + The Freebox binding requests your Freebox Revolution Server for various operational informations. + Gaël L'hopital + + diff --git a/addons/binding/org.openhab.binding.freebox/ESH-INF/thing/thing-types.xml b/addons/binding/org.openhab.binding.freebox/ESH-INF/thing/thing-types.xml new file mode 100644 index 0000000000000..23afe893d85dd --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/ESH-INF/thing/thing-types.xml @@ -0,0 +1,273 @@ + + + + + + Provides various informations regarding the status of the Freebox Server + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + network_address + The IP address / FQDN of the Freebox Server (can include port number) + mafreebox.freebox.fr + false + + + + + Token generated by the Freebox server + true + + + + + The refresh interval in seconds which is used to poll given Freebox Server. + 30 + false + + + + + The refresh interval in seconds which is used to poll given Freebox Server for phone informations. + 2 + false + + + + + + + String + + Version of the Freebox Server Firmware + + + + + Number + + Time since last reboot of the Freebox Server + + + + + Switch + + Has the Freebox server have restarted during the last poll period + Alarm + + + + + Switch + + Reboots the Freebox server + Switch + + + + Number + + Actual measured CPU Marvell temperature of the Freebox Server + Temperature + + + + + Number + + Actual measured CPU Broadcom (xDSL) temperature of the Freebox Server + Temperature + + + + + Number + + Actual measured switch temperature of the Freebox Server + Temperature + + + + + Number + + Actual measured fan speed (rpm) of the Freebox Server + + + + + Number + + Brightness level of the screen in percent + DimmableLight + + + + + Number + + Screen Orientation in degrees + + + + + + + + + + + + Switch + + Indicates whether the screen orientation forced + Switch + + + + Switch + + Indicates whether the wifi network is enabled + Switch + + + + String + + Status of the xDSL line + + + + + String + + Status of network line connexion + + + + + String + + Public IP Address of the Freebox Server + + + + + Number + + Current upload rate in byte/s + + + + + Number + + Current download rate in byte/s + + + + + Number + + Total uploaded bytes since last connection + + + + + Number + + Total downloaded bytes since last connection + + + + + Switch + + Indicates whether the phone is on hook + Switch + + + + + Switch + + Is the phone ringing + Alarm + + + + + String + + Callee number for outgoing calls. Caller number for incoming calls + + + + + Number + + Call duration in seconds + + + + + String + + Call creation timestamp + + + + + String + + Call Type (ingoing, outgoing, missed) + + + + + + + + + + + String + + Callee name for outgoing calls. Caller name for incoming calls + + + diff --git a/addons/binding/org.openhab.binding.freebox/META-INF/MANIFEST.MF b/addons/binding/org.openhab.binding.freebox/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000..74bd49f23262e --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/META-INF/MANIFEST.MF @@ -0,0 +1,33 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Freebox Binding +Bundle-SymbolicName: org.openhab.binding.freebox;singleton:=true +Bundle-Vendor: openHAB +Bundle-Version: 2.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-ClassPath: ., + lib/json-simple-1.1.jar, + lib/httpmime-4.3.1.jar, + lib/freeboxos-client-0.3.5.jar, + lib/jackson-core-asl-1.9.13.jar, + lib/jackson-mapper-asl-1.9.13.jar, + lib/httpclient-4.3.1.jar, + lib/httpcore-4.3.jar +Import-Package: com.google.common.collect, + org.apache.commons.logging, + org.eclipse.smarthome.config.core, + org.eclipse.smarthome.config.discovery, + org.eclipse.smarthome.core.common.registry, + org.eclipse.smarthome.core.library.types, + org.eclipse.smarthome.core.thing, + org.eclipse.smarthome.core.thing.binding, + org.eclipse.smarthome.core.types, + org.openhab.library.tel.items, + org.osgi.framework;version="1.8.0", + org.slf4j +Service-Component: OSGI-INF/* +Export-Package: org.openhab.binding.freebox, + org.openhab.binding.freebox.handler +Require-Bundle: com.google.guava;bundle-version="15.0.0", + org.apache.commons.io;bundle-version="2.2.0", + org.apache.commons.codec;bundle-version="1.6.0" diff --git a/addons/binding/org.openhab.binding.freebox/OSGI-INF/FreeboxHandlerFactory.xml b/addons/binding/org.openhab.binding.freebox/OSGI-INF/FreeboxHandlerFactory.xml new file mode 100644 index 0000000000000..8779687a92bc1 --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/OSGI-INF/FreeboxHandlerFactory.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + diff --git a/addons/binding/org.openhab.binding.freebox/build.properties b/addons/binding/org.openhab.binding.freebox/build.properties new file mode 100644 index 0000000000000..c763caf2bdf81 --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/build.properties @@ -0,0 +1,14 @@ +source.. = src/main/java/ +output.. = target/classes +bin.includes = META-INF/,\ + .,\ + OSGI-INF/,\ + ESH-INF/,\ + lib/json-simple-1.1.jar,\ + lib/httpmime-4.3.1.jar,\ + lib/freeboxos-client-0.3.5.jar,\ + lib/jackson-core-asl-1.9.13.jar,\ + lib/jackson-mapper-asl-1.9.13.jar,\ + lib/httpclient-4.3.1.jar,\ + lib/httpcore-4.3.jar + diff --git a/addons/binding/org.openhab.binding.freebox/lib/freeboxos-client-0.3.5.jar b/addons/binding/org.openhab.binding.freebox/lib/freeboxos-client-0.3.5.jar new file mode 100644 index 0000000000000..7607b290fa3d4 Binary files /dev/null and b/addons/binding/org.openhab.binding.freebox/lib/freeboxos-client-0.3.5.jar differ diff --git a/addons/binding/org.openhab.binding.freebox/lib/httpclient-4.3.1.jar b/addons/binding/org.openhab.binding.freebox/lib/httpclient-4.3.1.jar new file mode 100644 index 0000000000000..cdd1e3874c4b4 Binary files /dev/null and b/addons/binding/org.openhab.binding.freebox/lib/httpclient-4.3.1.jar differ diff --git a/addons/binding/org.openhab.binding.freebox/lib/httpcore-4.3.jar b/addons/binding/org.openhab.binding.freebox/lib/httpcore-4.3.jar new file mode 100644 index 0000000000000..ddfe6dacbc477 Binary files /dev/null and b/addons/binding/org.openhab.binding.freebox/lib/httpcore-4.3.jar differ diff --git a/addons/binding/org.openhab.binding.freebox/lib/httpmime-4.3.1.jar b/addons/binding/org.openhab.binding.freebox/lib/httpmime-4.3.1.jar new file mode 100644 index 0000000000000..2b26d7a79cc4a Binary files /dev/null and b/addons/binding/org.openhab.binding.freebox/lib/httpmime-4.3.1.jar differ diff --git a/addons/binding/org.openhab.binding.freebox/lib/jackson-core-asl-1.9.13.jar b/addons/binding/org.openhab.binding.freebox/lib/jackson-core-asl-1.9.13.jar new file mode 100644 index 0000000000000..bb4fe1da11865 Binary files /dev/null and b/addons/binding/org.openhab.binding.freebox/lib/jackson-core-asl-1.9.13.jar differ diff --git a/addons/binding/org.openhab.binding.freebox/lib/jackson-mapper-asl-1.9.13.jar b/addons/binding/org.openhab.binding.freebox/lib/jackson-mapper-asl-1.9.13.jar new file mode 100644 index 0000000000000..0f2073fc7eaf3 Binary files /dev/null and b/addons/binding/org.openhab.binding.freebox/lib/jackson-mapper-asl-1.9.13.jar differ diff --git a/addons/binding/org.openhab.binding.freebox/lib/json-simple-1.1.jar b/addons/binding/org.openhab.binding.freebox/lib/json-simple-1.1.jar new file mode 100644 index 0000000000000..f395f41471a79 Binary files /dev/null and b/addons/binding/org.openhab.binding.freebox/lib/json-simple-1.1.jar differ diff --git a/addons/binding/org.openhab.binding.freebox/pom.xml b/addons/binding/org.openhab.binding.freebox/pom.xml new file mode 100644 index 0000000000000..7700621c07a5d --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/pom.xml @@ -0,0 +1,24 @@ + + + + 4.0.0 + + + org.openhab + binding + 2.0.0-SNAPSHOT + + + + org.openhab.binding.freebox + org.openhab.binding.freebox + + + org.openhab.binding + org.openhab.binding.freebox + 2.0.0-SNAPSHOT + + Freebox Binding + eclipse-plugin + + diff --git a/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/FreeboxBindingConstants.java b/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/FreeboxBindingConstants.java new file mode 100644 index 0000000000000..b962414e18407 --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/FreeboxBindingConstants.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2014 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.freebox; + +import java.util.Set; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import com.google.common.collect.ImmutableSet; + +/** + * The {@link FreeboxBinding} class defines common constants, which are + * used across the whole binding. + * + * @author Gaël L'hopital - Initial contribution + */ +public class FreeboxBindingConstants { + + public static final String BINDING_ID = "freebox"; + + // List of all Thing Type UIDs + public final static ThingTypeUID FREEBOX_THING_TYPE_SERVER = new ThingTypeUID(BINDING_ID, "server"); + + public final static Set SUPPORTED_THING_TYPES_UIDS =ImmutableSet.of( + FREEBOX_THING_TYPE_SERVER); + + // List of all Channel ids + public final static String FWVERSION = "fwversion"; + public final static String UPTIME = "uptime"; + public final static String RESTARTED = "restarted"; + public final static String TEMPCPUM = "tempcpum"; + public final static String TEMPCPUB = "tempcpub"; + public final static String TEMPSWITCH = "tempswitch"; + public final static String FANSPEED = "fanspeed"; + public final static String LCDBRIGHTNESS = "lcd_brightness"; + public final static String LCDORIENTATION = "lcd_orientation"; + public final static String LCDFORCED = "lcd_forced"; + public final static String WIFISTATUS = "wifi_status"; + public final static String XDSLSTATUS = "xdsl_status"; + public final static String LINESTATUS = "line_status"; + public final static String IPV4 = "ipv4"; + public final static String RATEUP = "rate_up"; + public final static String RATEDOWN = "rate_down"; + public final static String BYTESUP = "bytes_up"; + public final static String BYTESDOWN = "bytes_down"; + public final static String ONHOOK = "onhook"; + public final static String RINGING = "ringing"; + public final static String CALLNUMBER = "call_number"; + public final static String CALLDURATION = "call_duration"; + public final static String CALLTIMESTAMP = "call_timestamp"; + public final static String CALLSTATUS = "call_status"; + public final static String CALLNAME = "call_name"; + public final static String REBOOT = "reboot"; +} diff --git a/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/config/FreeboxServerConfiguration.java b/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/config/FreeboxServerConfiguration.java new file mode 100644 index 0000000000000..2e3e6d7805778 --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/config/FreeboxServerConfiguration.java @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.freebox.config; + +/** + * The {@link FreeboxServerConfiguration} is responsible for holding + * configuration informations needed to access/poll the freebox server + * + * @author Gaël L'hopital + */ +public class FreeboxServerConfiguration { + + public static final String IP_ADDRESS = "ipAddress"; + public static final String APP_TOKEN = "appToken"; + public static final String REFRESH_INTERVAL = "refreshInterval"; + public static final String REFRESH_PHONE_INTERVAL = "refreshPhoneInterval"; + + public String ipAddress; + public String appToken; + public Integer refreshInterval; + public Integer refreshPhoneInterval; + +} + diff --git a/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/handler/FreeboxHandler.java b/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/handler/FreeboxHandler.java new file mode 100644 index 0000000000000..5906650c324d1 --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/handler/FreeboxHandler.java @@ -0,0 +1,388 @@ +/** + * Copyright (c) 2014 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.freebox.handler; + +import java.util.List; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import org.eclipse.smarthome.core.library.types.DateTimeType; +import org.eclipse.smarthome.core.library.types.DecimalType; +import org.eclipse.smarthome.core.library.types.IncreaseDecreaseType; +import org.eclipse.smarthome.core.library.types.OnOffType; +import org.eclipse.smarthome.core.library.types.OpenClosedType; +import org.eclipse.smarthome.core.library.types.PercentType; +import org.eclipse.smarthome.core.library.types.StringType; +import org.eclipse.smarthome.core.library.types.UpDownType; +import org.eclipse.smarthome.core.thing.ChannelUID; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingStatus; +import org.eclipse.smarthome.core.thing.binding.BaseThingHandler; +import org.eclipse.smarthome.core.types.Command; +import org.matmaul.freeboxos.FreeboxException; +import org.matmaul.freeboxos.FreeboxOsClient; +import org.matmaul.freeboxos.call.CallEntry; +import org.matmaul.freeboxos.connection.ConnectionStatus; +import org.matmaul.freeboxos.connection.xDslStatus; +import org.matmaul.freeboxos.lcd.LCDConfig; +import org.matmaul.freeboxos.login.Authorize; +import org.matmaul.freeboxos.login.LoginManager; +import org.matmaul.freeboxos.login.TrackAuthorizeStatus; +import org.matmaul.freeboxos.phone.PhoneStatus; +import org.matmaul.freeboxos.system.SystemConfiguration; +import org.matmaul.freeboxos.wifi.WifiGlobalConfig; +import org.openhab.binding.freebox.config.FreeboxServerConfiguration; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.openhab.binding.freebox.FreeboxBindingConstants.*; + +/** + * The {@link FreeboxHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Gaël L'hopital - Initial contribution + */ +public class FreeboxHandler extends BaseThingHandler { + + private Logger logger = LoggerFactory.getLogger(FreeboxHandler.class); + private ScheduledFuture globalJob; + private ScheduledFuture phoneJob; + + private static FreeboxOsClient fbClient = null; + private long uptime = -1; + + public FreeboxHandler(Thing thing) { + super(thing); + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + try { + switch (channelUID.getId()) { + case LCDBRIGHTNESS : setBrightness(command); + break; + case LCDORIENTATION : setOrientation(command); + break; + case LCDFORCED : setForced(command); + break; + case WIFISTATUS : setWifiStatus(command); + break; + case REBOOT : setReboot(command); + } + } catch (FreeboxException e) { + logger.error(e.getMessage()); + } + } + + /** + * Handles connection to the Freebox, including validation of the Apptoken + * if none is provided in configuration + * @throws FreeboxException + */ + private boolean authorize() { + + FreeboxServerConfiguration configuration = getConfigAs(FreeboxServerConfiguration.class); + + Bundle bundle = FrameworkUtil.getBundle(getClass()); + + fbClient = new FreeboxOsClient( + bundle.getSymbolicName(), /* org.openhab.binding.freebox */ + configuration.ipAddress); + + + LoginManager loginManager = fbClient.getLoginManager(); + TrackAuthorizeStatus authorizeStatus = TrackAuthorizeStatus.UNKNOWN; + try { + + if (configuration.appToken == null || configuration.appToken.isEmpty()) { + + Authorize authorize = loginManager.newAuthorize( + bundle.getHeaders().get("Bundle-Name"), // Freebox Binding + String.format("%d.%d",bundle.getVersion().getMajor(),bundle.getVersion().getMinor()), // eg. 1.5 + bundle.getHeaders().get("Bundle-Vendor")); + + + configuration.appToken = authorize.getAppToken(); + + logger.info("####################################################################"); + logger.info("# Please accept activation request directly on your freebox #"); + logger.info("# Once done, record Apptoken in the Freebox Item configuration #"); + logger.info("# " + configuration.appToken +" #"); + logger.info("####################################################################"); + + do { + Thread.sleep(2000); + authorizeStatus = loginManager.trackAuthorize(); + } while (authorizeStatus == TrackAuthorizeStatus.PENDING); + } else { + authorizeStatus = TrackAuthorizeStatus.GRANTED; + } + + if (authorizeStatus != TrackAuthorizeStatus.GRANTED) + return false; + + logger.debug("Apptoken valide : [" + configuration.appToken + "]"); + loginManager.setAppToken(configuration.appToken); + loginManager.openSession(); + return true; + } catch (FreeboxException | InterruptedException e) { + logger.error(e.getMessage()); + return false; + } + } + + @Override + public void initialize() { + if (authorize()) { + getThing().setStatus(ThingStatus.ONLINE); + + if (globalJob == null || globalJob.isCancelled()) { + long polling_interval = getConfigAs(FreeboxServerConfiguration.class).refreshInterval; + globalJob = scheduler.scheduleAtFixedRate(globalRunnable, 1, polling_interval, TimeUnit.SECONDS); + } + + if (phoneJob == null || phoneJob.isCancelled()) { + long polling_interval = getConfigAs(FreeboxServerConfiguration.class).refreshPhoneInterval; + phoneJob = scheduler.scheduleAtFixedRate(phoneRunnable, 1, polling_interval, TimeUnit.SECONDS); + } + } else { + getThing().setStatus(ThingStatus.OFFLINE); + } + } + + private Runnable phoneRunnable = new Runnable() { + @Override + public void run() { + List phoneStatus; + try { + phoneStatus = fbClient.getPhoneManager().getPhoneStatus(); + updateState(new ChannelUID(getThing().getUID(), ONHOOK), + phoneStatus.get(0).getOn_hook() ? OnOffType.ON : OnOffType.OFF); + updateState(new ChannelUID(getThing().getUID(), RINGING), + phoneStatus.get(0).getIs_ringing() ? OnOffType.ON : OnOffType.OFF); + } catch (FreeboxException e) { + logger.error(e.getMessage()); + getThing().setStatus(ThingStatus.OFFLINE); + } + + } + }; + + private Runnable globalRunnable = new Runnable() { + @Override + public void run() { + + try { + fetchSystemConfig(); + fetchLCDConfig(); + fetchWifiConfig(); + fetchxDslStatus(); + fetchConnectionStatus(); + fetchNewCalls(); + + } catch (FreeboxException e) { + logger.error(e.getMessage()); + getThing().setStatus(ThingStatus.OFFLINE); + } + + } + }; + + @Override + public void dispose() { + logger.debug("Disposing Freebox Server handler."); + if (globalJob != null && !globalJob.isCancelled()) { + globalJob.cancel(true); + globalJob = null; + } + if (phoneJob != null && !phoneJob.isCancelled()) { + phoneJob.cancel(true); + phoneJob = null; + } + getThing().setStatus(ThingStatus.OFFLINE); + } + + private void fetchNewCalls() throws FreeboxException { + List callEntries = fbClient.getCallManager().getCallEntries(); + for (CallEntry call: callEntries) { + if (call.is_new_()) { + updateState(new ChannelUID(getThing().getUID(), CALLNUMBER), + new StringType(call.getNumber())); + updateState(new ChannelUID(getThing().getUID(), CALLDURATION), + new DecimalType(call.getDuration())); + updateState(new ChannelUID(getThing().getUID(), CALLTIMESTAMP), + new DateTimeType(call.getTimeStamp())); + updateState(new ChannelUID(getThing().getUID(), CALLSTATUS), + new StringType(call.getType())); + updateState(new ChannelUID(getThing().getUID(), CALLNAME), + new StringType(call.getName())); + + call.setNew(false); + fbClient.getCallManager().setCallEntry(call); + } + } + } + + private void fetchConnectionStatus() throws FreeboxException { + ConnectionStatus connectionStatus = fbClient.getConnectionManager().getStatus(); + updateState(new ChannelUID(getThing().getUID(), LINESTATUS), + new StringType(connectionStatus.getState())); + updateState(new ChannelUID(getThing().getUID(), IPV4), + new StringType(connectionStatus.getIpv4())); + updateState(new ChannelUID(getThing().getUID(), RATEUP), + new DecimalType(connectionStatus.getRate_up())); + updateState(new ChannelUID(getThing().getUID(), RATEDOWN), + new DecimalType(connectionStatus.getRate_down())); + updateState(new ChannelUID(getThing().getUID(), BYTESUP), + new DecimalType(connectionStatus.getBytes_up())); + updateState(new ChannelUID(getThing().getUID(), BYTESDOWN), + new DecimalType(connectionStatus.getBytes_down())); + } + + private void fetchxDslStatus() throws FreeboxException { + xDslStatus xdslStatus = fbClient.getConnectionManager().getxDslStatus(); + updateState(new ChannelUID(getThing().getUID(), XDSLSTATUS), + new StringType(xdslStatus.getStatus())); + } + + private void fetchWifiConfig() throws FreeboxException { + WifiGlobalConfig wifiConfiguration = fbClient.getWifiManager().getGlobalConfig(); + updateState(new ChannelUID(getThing().getUID(), WIFISTATUS), + wifiConfiguration.getEnabled() ? OnOffType.ON : OnOffType.OFF); + } + + private void fetchLCDConfig() throws FreeboxException { + LCDConfig lcdConfiguration = fbClient.getLCDManager().getLCDConfig(); + updateState(new ChannelUID(getThing().getUID(), LCDBRIGHTNESS), + new DecimalType(lcdConfiguration.getBrightness())); + updateState(new ChannelUID(getThing().getUID(), LCDORIENTATION), + new DecimalType(lcdConfiguration.getOrientation())); + updateState(new ChannelUID(getThing().getUID(), LCDFORCED), + lcdConfiguration.getOrientationForced() ? OnOffType.ON : OnOffType.OFF); + } + + private void fetchSystemConfig() throws FreeboxException { + SystemConfiguration systemConfiguration = fbClient.getSystemManager().getConfiguration(); + + updateState(new ChannelUID(getThing().getUID(), FWVERSION), + new StringType(systemConfiguration.getFirmware_version())); + + long newUptime = systemConfiguration.getUptimeVal(); + updateState(new ChannelUID(getThing().getUID(), RESTARTED), + newUptime < uptime ? OnOffType.ON : OnOffType.OFF ); + uptime = newUptime; + + updateState(new ChannelUID(getThing().getUID(), UPTIME), + new DecimalType(uptime)); + updateState(new ChannelUID(getThing().getUID(), TEMPCPUM), + new DecimalType(systemConfiguration.getTemp_cpum())); + updateState(new ChannelUID(getThing().getUID(), TEMPCPUB), + new DecimalType(systemConfiguration.getTemp_cpub())); + updateState(new ChannelUID(getThing().getUID(), TEMPSWITCH), + new DecimalType(systemConfiguration.getTemp_sw())); + updateState(new ChannelUID(getThing().getUID(), FANSPEED), + new DecimalType(systemConfiguration.getFan_rpm())); + } + + public void setBrightness(Command command) throws FreeboxException { + if (command != null) { + if (command instanceof OnOffType || command instanceof IncreaseDecreaseType || + command instanceof DecimalType || command instanceof PercentType) { + + LCDConfig lcd = fbClient.getLCDManager().getLCDConfig(); + int value = 0; + int newValue = 0; + + if (command instanceof IncreaseDecreaseType) { + value = lcd.getBrightness(); + if (command == IncreaseDecreaseType.INCREASE) { + newValue = Math.min(100, value + 1); + } else { + newValue = Math.max(0, value - 1); + } + } else if (command instanceof OnOffType) { + newValue = (command == OnOffType.ON) ? 100 : 0; + } else if (command instanceof DecimalType) { + newValue = Math.min(100, ((DecimalType) command).intValue()); + newValue = Math.max(newValue, 0); + } else { + return; + } + lcd.setBrightness(newValue); + fbClient.getLCDManager().setLCDConfig(lcd); + fetchLCDConfig(); + } + } + } + + private void setOrientation(Command command) throws FreeboxException { + if (command != null && command instanceof DecimalType) { + LCDConfig lcd = fbClient.getLCDManager().getLCDConfig(); + int newValue = Math.min(360, ((DecimalType) command).intValue()); + newValue = Math.max(newValue, 0); + lcd.setOrientation(newValue); + lcd.setOrientationForced(true); + fbClient.getLCDManager().setLCDConfig(lcd); + fetchLCDConfig(); + } + } + + private void setForced(Command command) throws FreeboxException { + if (command != null) { + if (command instanceof OnOffType + || command instanceof OpenClosedType + || command instanceof UpDownType) { + + LCDConfig lcd = fbClient.getLCDManager().getLCDConfig(); + + lcd.setOrientationForced( + command.equals(OnOffType.ON) || + command.equals(UpDownType.UP) || + command.equals(OpenClosedType.OPEN) + ); + fbClient.getLCDManager().setLCDConfig(lcd); + fetchLCDConfig(); + } + } + } + + private void setWifiStatus(Command command) throws FreeboxException { + if (command != null) { + if (command instanceof OnOffType + || command instanceof OpenClosedType + || command instanceof UpDownType) { + + WifiGlobalConfig wifiConfiguration = fbClient.getWifiManager().getGlobalConfig(); + + wifiConfiguration.setEnabled( + command.equals(OnOffType.ON) || + command.equals(UpDownType.UP) || + command.equals(OpenClosedType.OPEN) + ); + + fbClient.getWifiManager().setGlobalConfig(wifiConfiguration); + fetchWifiConfig(); + } + } + } + + private void setReboot(Command command) throws FreeboxException { + if (command != null) { + if ( command.equals(OnOffType.ON) || + command.equals(UpDownType.UP) || + command.equals(OpenClosedType.OPEN) ) { + + fbClient.getSystemManager().Reboot(); + } + } + } + +} diff --git a/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxHandlerFactory.java b/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxHandlerFactory.java new file mode 100644 index 0000000000000..59b21010b2da8 --- /dev/null +++ b/addons/binding/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxHandlerFactory.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2014 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.freebox.internal; + +import static org.openhab.binding.freebox.FreeboxBindingConstants.*; + +import java.util.Collections; +import java.util.Set; + +import org.openhab.binding.freebox.handler.FreeboxHandler; + +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; +import org.eclipse.smarthome.core.thing.binding.ThingHandler; + +/** + * The {@link FreeboxHandlerFactory} is responsible for creating things and thing + * handlers. + * + * @author Gaël L'hopital - Initial contribution + */ +public class FreeboxHandlerFactory extends BaseThingHandlerFactory { + + private final static Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(FREEBOX_THING_TYPE_SERVER); + + @Override + public boolean supportsThingType(ThingTypeUID thingTypeUID) { + return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); + } + + @Override + protected ThingHandler createHandler(Thing thing) { + + ThingTypeUID thingTypeUID = thing.getThingTypeUID(); + + if (thingTypeUID.equals(FREEBOX_THING_TYPE_SERVER)) { + return new FreeboxHandler(thing); + } + + return null; + } +} + diff --git a/addons/binding/pom.xml b/addons/binding/pom.xml index 68de6fa733663..e87e7412b37b2 100644 --- a/addons/binding/pom.xml +++ b/addons/binding/pom.xml @@ -2,8 +2,8 @@ - org.openhab - addons + org.openhab.addons + pom 2.0.0-SNAPSHOT @@ -17,6 +17,10 @@ org.openhab.binding.sonos + org.openhab.binding.max + org.openhab.binding.networkhealth + org.openhab.binding.freebox + diff --git a/targetplatform/openHAB_Runtime.launch b/targetplatform/openHAB_Runtime.launch index 095fe12096de0..31afd4d81550b 100644 --- a/targetplatform/openHAB_Runtime.launch +++ b/targetplatform/openHAB_Runtime.launch @@ -22,8 +22,8 @@ - - + +