Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1369 from clinique/master
Browse files Browse the repository at this point in the history
Updated FreeboxOS API to v3.0, added i18n to Transformation files
  • Loading branch information
teichsta committed Aug 27, 2014
2 parents 0b79d2c + 173a56a commit 1c91a83
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 25 deletions.
3 changes: 2 additions & 1 deletion bundles/binding/org.openhab.binding.freebox/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry exported="true" kind="lib" path="lib/freeboxos-0.3.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-codec-1.6.jar"/>
<classpathentry exported="true" kind="lib" path="lib/freeboxos-0.2.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/guava-15.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpclient-4.3.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpcore-4.3.2.jar"/>
Expand All @@ -13,5 +13,6 @@
<classpathentry exported="true" kind="lib" path="lib/json_simple-1.1.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/home/sysadmin/projects/openhab/bundles/binding/org.openhab.binding.freebox/lib/freeboxos-0.3.1.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ Bundle-ClassPath: .,
lib/jackson-core-asl-1.9.13.jar,
lib/jackson-mapper-asl-1.9.13.jar,
lib/json_simple-1.1.jar,
lib/freeboxos-0.2.0.jar,
lib/commons-codec-1.6.jar
lib/commons-codec-1.6.jar,
lib/freeboxos-0.3.1.jar
4 changes: 2 additions & 2 deletions bundles/binding/org.openhab.binding.freebox/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ bin.includes = META-INF/,\
lib/jackson-core-asl-1.9.13.jar,\
lib/jackson-mapper-asl-1.9.13.jar,\
lib/json_simple-1.1.jar,\
lib/freeboxos-0.2.0.jar,\
lib/commons-codec-1.6.jar
lib/commons-codec-1.6.jar,\
lib/freeboxos-0.3.1.jar
output.. = target/classes/
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ public enum CommandType {
CALLNUMBER("call_number"),
CALLDURATION("call_duration"),
CALLTIMESTAMP("call_timestamp"),
CALLSTATUS("call_status");

CALLSTATUS("call_status"),
// xDSL Status
XDSLSTATUS("xdsl_status"),
// LCD Configuration
LCDBRIGHTNESS("lcd_brightness"),
LCDORIENTATION("lcd_orientation"),
LCDFORCED("lcd_forced");


String command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.matmaul.freeboxos.system.SystemConfiguration;
import org.matmaul.freeboxos.call.CallEntry;
import org.matmaul.freeboxos.wifi.*;
import org.matmaul.freeboxos.lcd.*;
import org.matmaul.freeboxos.connection.xDslStatus;

/**
* Freebox binding for openHAB
Expand Down Expand Up @@ -64,6 +66,8 @@ public class FreeboxBinding extends AbstractActiveBinding<FreeboxBindingProvider
private static SystemConfiguration sc;
private static ConnectionStatus cs;
private static WifiGlobalConfig wc;
private static LCDConfig lcd;
private static xDslStatus xdsl;

/**
* the refresh interval which is used to poll values from the Freebox
Expand Down Expand Up @@ -133,6 +137,9 @@ protected void execute() {
sc = fbClient.getSystemManager().getConfiguration();
cs = fbClient.getConnectionManager().getStatus();
wc = fbClient.getWifiManager().getGlobalConfig();
lcd = fbClient.getLCDManager().getLCDConfig();
xdsl = fbClient.getConnectionManager().getxDslStatus();

List<CallEntry> appels = fbClient.getCallManager().getCallEntries();

for (FreeboxBindingProvider provider : providers) {
Expand Down Expand Up @@ -190,6 +197,14 @@ protected void execute() {
break;
case WIFISTATUS : setItemValue(bindingConfig.item,wc.getEnabled());
break;
case LCDBRIGHTNESS : setItemValue(bindingConfig.item,(long)lcd.getBrightness());
break;
case LCDORIENTATION : setItemValue(bindingConfig.item,(long)lcd.getOrientation());
break;
case LCDFORCED : setItemValue(bindingConfig.item,lcd.getOrientationForced());
break;
case XDSLSTATUS : setItemValue(bindingConfig.item,xdsl.getStatus());
break;
default:
break;
}
Expand All @@ -204,27 +219,45 @@ protected void execute() {
/**
* @{inheritDoc}
*/
@SuppressWarnings("incomplete-switch")
@Override
protected void internalReceiveCommand(String itemName, Command command) {
for (FreeboxBindingProvider provider : providers) {
FreeboxBindingConfig config = provider.getConfig(itemName);
if (config == null) continue;

if (config.commandType == CommandType.WIFISTATUS) {
try {
wc = fbClient.getWifiManager().getGlobalConfig();
wc.setEnabled(command.equals(OnOffType.ON) ? true : false);
fbClient.getWifiManager().setGlobalConfig(wc);
} catch (FreeboxException e) {
logger.error(e.toString());
}
}
if (config.commandType == CommandType.REBOOT) {
try {
fbClient.getSystemManager().Reboot();
} catch (FreeboxException e) {
logger.error(e.toString());
try {
switch (config.commandType) {
case LCDBRIGHTNESS : if (command instanceof DecimalType) {
lcd = fbClient.getLCDManager().getLCDConfig();
int valeur = ((DecimalType)command).intValue();
lcd.setBrightness(new Integer(valeur));
fbClient.getLCDManager().setLCDConfig(lcd);
}
break;
case LCDORIENTATION : if (command instanceof DecimalType) {
lcd = fbClient.getLCDManager().getLCDConfig();
int valeur = ((DecimalType)command).intValue();
lcd.setOrientation(new Integer(valeur));
lcd.setOrientationForced(true);
fbClient.getLCDManager().setLCDConfig(lcd);
}
break;
case LCDFORCED :
lcd = fbClient.getLCDManager().getLCDConfig();
lcd.setOrientationForced(command.equals(OnOffType.ON) ? true : false);
fbClient.getLCDManager().setLCDConfig(lcd);
break;
case WIFISTATUS :
wc = fbClient.getWifiManager().getGlobalConfig();
wc.setEnabled(command.equals(OnOffType.ON) ? true : false);
fbClient.getWifiManager().setGlobalConfig(wc);
break;
case REBOOT :
fbClient.getSystemManager().Reboot();
break;
}
} catch (Exception e) {
logger.error(e.toString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import java.io.IOException;
import java.io.Reader;
import java.util.Properties;
import java.util.Locale;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.FilenameUtils;
import org.openhab.config.core.ConfigDispatcher;
import org.openhab.core.transform.TransformationException;
import org.openhab.core.transform.TransformationService;
Expand Down Expand Up @@ -55,10 +57,25 @@ public String transform(String filename, String source) throws TransformationExc
if (filename == null || source == null) {
throw new TransformationException("the given parameters 'filename' and 'source' must not be null");
}


String basename = FilenameUtils.getBaseName(filename);
String extension = FilenameUtils.getExtension(filename);
String locale = Locale.getDefault().getLanguage();
String basePath = ConfigDispatcher.getConfigFolder() + File.separator + TransformationActivator.TRANSFORM_FOLDER_NAME + File.separator;

String path = basePath + filename;
// eg : /home/sysadmin/projects/openhab/distribution/openhabhome/configurations/transform/test.map
String alternatePath = basePath + basename + "_" + locale + "." + extension;
// eg : /home/sysadmin/projects/openhab/distribution/openhabhome/configurations/transform/test-en.map

File f = new File(alternatePath);
if (f.exists()) {
path = alternatePath;
}
logger.debug("Transformation file found '{}'",path);

Reader reader = null;
try {
String path = ConfigDispatcher.getConfigFolder() + File.separator + TransformationActivator.TRANSFORM_FOLDER_NAME + File.separator + filename;
try {
Properties properties = new Properties();
reader = new FileReader(path);
properties.load(reader);
Expand Down

0 comments on commit 1c91a83

Please sign in to comment.