use of org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice in project openhab1-addons by openhab.
the class FritzahaBinding method internalReceiveCommand.
/**
* @{inheritDoc
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
logger.debug("internalReceiveCommand() is called!");
FritzahaBindingProvider commandProvider = null;
FritzahaSwitchedOutlet switchDevice = null;
for (FritzahaBindingProvider currentProvider : providers) {
if (!currentProvider.getItemNames().contains(itemName)) {
continue;
}
FritzahaDevice device = currentProvider.getDeviceConfig(itemName);
if (!(device instanceof FritzahaSwitchedOutlet)) {
continue;
}
switchDevice = (FritzahaSwitchedOutlet) device;
commandProvider = currentProvider;
break;
}
if (commandProvider == null || switchDevice == null) {
logger.error("No provider found for item " + itemName);
return;
}
if (command instanceof OnOffType) {
String deviceHostID = switchDevice.getHost();
Host host = hostCache.get(deviceHostID);
if (host != null) {
FritzahaWebInterface deviceHost = host.getConnection();
boolean valueToSet = (command == OnOffType.ON);
switchDevice.setSwitchState(valueToSet, itemName, deviceHost);
}
} else {
logger.debug("Unsupported command type for item " + itemName);
}
}
use of org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice in project openhab1-addons by openhab.
the class FritzahaGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
FritzahaDevice config = null;
TimeDef timedef = null;
String[] configParts = bindingConfig.trim().split(",");
if (configParts.length < 2) {
throw new BindingConfigParseException("FritzAHA items must start with <hostID>,<deviceID/AIN>");
}
if (item instanceof SwitchItem) {
if (configParts.length != 2) {
throw new BindingConfigParseException("FritzAHA switches must be of format <hostID>,<deviceID/AIN>");
}
if (configParts[1].length() > 8) {
config = new FritzahaWebserviceSwitch(configParts[0], configParts[1]);
} else {
config = new FritzahaQueryscriptSwitch(configParts[0], configParts[1]);
}
} else if (item instanceof NumberItem) {
if (configParts.length < 3 || configParts.length > 4) {
throw new BindingConfigParseException("FritzAHA meters must be of format <hostID>,<deviceID/AIN>,<valueToMeasure>[,timespec]");
} else if (configParts.length == 4 && !"energy".equalsIgnoreCase(configParts[2])) {
throw new BindingConfigParseException("FritzAHA non-energy meters must be of format <hostID>,<deviceID/AIN>,<valueToMeasure>");
} else if (configParts[1].length() > 8) {
if ("power".equalsIgnoreCase(configParts[2])) {
config = new FritzahaWebserviceMeter(configParts[0], configParts[1], MeterType.POWER);
} else if ("energy".equalsIgnoreCase(configParts[2])) {
config = new FritzahaWebserviceMeter(configParts[0], configParts[1], MeterType.ENERGY);
} else if ("temperature".equalsIgnoreCase(configParts[2])) {
config = new FritzahaWebserviceMeter(configParts[0], configParts[1], MeterType.TEMPERATURE);
} else {
logger.warn("Could not configure item " + item + " - Unsupported meter type for webservice");
return;
}
} else {
if ("voltage".equalsIgnoreCase(configParts[2])) {
config = new FritzahaQueryscriptMeter(configParts[0], configParts[1], MeterType.VOLTAGE);
} else if ("current".equalsIgnoreCase(configParts[2])) {
config = new FritzahaQueryscriptMeter(configParts[0], configParts[1], MeterType.CURRENT);
} else if ("power".equalsIgnoreCase(configParts[2])) {
config = new FritzahaQueryscriptMeter(configParts[0], configParts[1], MeterType.POWER);
} else if ("energy".equalsIgnoreCase(configParts[2])) {
if (configParts.length > 3) {
if ("mins".equalsIgnoreCase(configParts[3])) {
timedef = TimeDef.MINUTES;
} else if ("day".equalsIgnoreCase(configParts[3])) {
timedef = TimeDef.DAY;
} else if ("month".equalsIgnoreCase(configParts[3])) {
timedef = TimeDef.MONTH;
} else if ("year".equalsIgnoreCase(configParts[3])) {
timedef = TimeDef.YEAR;
} else {
timedef = TimeDef.YEAR;
logger.warn("Timedef of item " + item + "is set to default YEAR. " + "Please check your syntax. Shall be year, month, day or mins.");
}
} else {
timedef = TimeDef.YEAR;
logger.debug("Timedef of item " + item + "is set to default YEAR because no timespec was given.");
}
config = new FritzahaQueryscriptMeter(configParts[0], configParts[1], MeterType.ENERGY, timedef);
} else {
logger.warn("Could not configure item " + item + " - Unsupported meter type for query script");
return;
}
}
} else {
logger.warn("Could not configure item " + item + " - Unsupported item type");
}
if (config != null) {
addBindingConfig(item, config);
} else {
logger.error("Could not configure item " + item + " - An error occurred");
}
}
use of org.openhab.binding.fritzaha.internal.hardware.interfaces.FritzahaDevice in project openhab1-addons by openhab.
the class FritzahaBinding method execute.
/**
* @{inheritDoc
*/
@Override
protected void execute() {
logger.debug("execute() method is called!");
for (FritzahaBindingProvider currentProvider : providers) {
for (String currentItem : currentProvider.getItemNames()) {
FritzahaDevice currentDevice = currentProvider.getDeviceConfig(currentItem);
String currentHostId = currentDevice.getHost();
if (!hostCache.containsKey(currentHostId)) {
continue;
}
FritzahaWebInterface currentHost = hostCache.get(currentHostId).getConnection();
if (currentDevice instanceof FritzahaSwitchedOutlet) {
FritzahaSwitchedOutlet currentSwitch = (FritzahaSwitchedOutlet) currentDevice;
currentSwitch.updateSwitchState(currentItem, currentHost);
} else if (currentDevice instanceof FritzahaOutletMeter) {
FritzahaOutletMeter currentMeter = (FritzahaOutletMeter) currentDevice;
currentMeter.updateMeterValue(currentItem, currentHost);
}
}
}
}
Aggregations