use of org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException in project smarthome by eclipse.
the class HomematicThingHandler method handleConfigurationUpdate.
@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) throws ConfigValidationException {
super.handleConfigurationUpdate(configurationParameters);
try {
HomematicGateway gateway = getHomematicGateway();
HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));
for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
String key = configurationParameter.getKey();
Object newValue = configurationParameter.getValue();
if (key.startsWith("HMP_")) {
key = StringUtils.removeStart(key, "HMP_");
Integer channelNumber = NumberUtils.toInt(StringUtils.substringBefore(key, "_"));
String dpName = StringUtils.substringAfter(key, "_");
HmDatapointInfo dpInfo = new HmDatapointInfo(device.getAddress(), HmParamsetType.MASTER, channelNumber, dpName);
HmDatapoint dp = device.getChannel(channelNumber).getDatapoint(dpInfo);
if (dp != null) {
try {
if (newValue != null) {
if (newValue instanceof BigDecimal) {
final BigDecimal decimal = (BigDecimal) newValue;
if (dp.isIntegerType()) {
newValue = decimal.intValue();
} else if (dp.isFloatType()) {
newValue = decimal.doubleValue();
}
}
if (ObjectUtils.notEqual(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(), newValue)) {
sendDatapoint(dp, new HmDatapointConfig(), newValue);
}
}
} catch (IOException ex) {
logger.error("Error setting thing property {}: {}", dpInfo, ex.getMessage());
}
} else {
logger.error("Can't find datapoint for thing property {}", dpInfo);
}
}
}
gateway.triggerDeviceValuesReload(device);
} catch (HomematicClientException | GatewayNotAvailableException ex) {
logger.error("Error setting thing properties: {}", ex.getMessage(), ex);
}
}
use of org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException in project smarthome by eclipse.
the class AbstractHomematicGateway method getDatapoint.
@Override
public HmDatapoint getDatapoint(HmDatapointInfo dpInfo) throws HomematicClientException {
HmDevice device = getDevice(dpInfo.getAddress());
HmChannel channel = device.getChannel(dpInfo.getChannel());
if (channel == null) {
throw new HomematicClientException(String.format("Channel %s in device '%s' not found on gateway '%s'", dpInfo.getChannel(), dpInfo.getAddress(), id));
}
HmDatapoint dp = channel.getDatapoint(dpInfo);
if (dp == null) {
throw new HomematicClientException(String.format("Datapoint '%s' not found on gateway '%s'", dpInfo, id));
}
return dp;
}
use of org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException in project smarthome by eclipse.
the class AbstractHomematicGateway method updateRssiInfo.
private void updateRssiInfo(String address, String datapointName, Integer value) {
HmDatapointInfo dpInfo = new HmDatapointInfo(address, HmParamsetType.VALUES, 0, datapointName);
HmChannel channel;
try {
channel = getDevice(dpInfo.getAddress()).getChannel(0);
if (channel != null) {
eventReceived(dpInfo, value);
}
} catch (HomematicClientException e) {
// ignore
}
}
use of org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException in project smarthome by eclipse.
the class AbstractHomematicGateway method setInstallMode.
@Override
public void setInstallMode(boolean enable, int seconds) throws IOException {
HmDevice gwExtrasHm = devices.get(HmDevice.ADDRESS_GATEWAY_EXTRAS);
if (gwExtrasHm != null) {
// since the homematic virtual device exist: try setting install mode via its dataPoints
HmDatapoint installModeDataPoint = null;
HmDatapoint installModeDurationDataPoint = null;
// collect virtual datapoints to be accessed
HmChannel hmChannel = gwExtrasHm.getChannel(HmChannel.CHANNEL_NUMBER_EXTRAS);
HmDatapointInfo installModeDurationDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE_DURATION);
if (enable) {
installModeDurationDataPoint = hmChannel.getDatapoint(installModeDurationDataPointInfo);
}
HmDatapointInfo installModeDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE);
installModeDataPoint = hmChannel.getDatapoint(installModeDataPointInfo);
// first set duration on the datapoint
if (installModeDurationDataPoint != null) {
try {
VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDurationDataPoint, null);
handler.handleCommand(this, installModeDurationDataPoint, new HmDatapointConfig(), seconds);
// notify thing if exists
gatewayAdapter.onStateUpdated(installModeDurationDataPoint);
} catch (HomematicClientException ex) {
logger.warn("Failed to send datapoint {}", installModeDurationDataPoint, ex);
}
}
// now that the duration is set, we can enable / disable
if (installModeDataPoint != null) {
try {
VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDataPoint, null);
handler.handleCommand(this, installModeDataPoint, new HmDatapointConfig(), enable);
// notify thing if exists
gatewayAdapter.onStateUpdated(installModeDataPoint);
return;
} catch (HomematicClientException ex) {
logger.warn("Failed to send datapoint {}", installModeDataPoint, ex);
}
}
}
// no gwExtrasHm available (or previous approach failed), therefore use rpc client directly
for (HmInterface hmInterface : availableInterfaces.keySet()) {
if (hmInterface == HmInterface.RF || hmInterface == HmInterface.CUXD) {
getRpcClient(hmInterface).setInstallMode(hmInterface, enable, seconds);
}
}
}
use of org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException in project smarthome by eclipse.
the class HomematicBridgeHandler method reloadAllDeviceValues.
@Override
public void reloadAllDeviceValues() {
for (Thing hmThing : getThing().getThings()) {
try {
HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(hmThing));
gateway.triggerDeviceValuesReload(device);
} catch (HomematicClientException ex) {
logger.warn("{}", ex.getMessage());
}
}
}
Aggregations