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

Commit

Permalink
[homematic] Enable configuration of device parameters (#5963)
Browse files Browse the repository at this point in the history
Made the parameters of a HmDevice that do not belong to one of its
HmChannels available in the thing configuration.
These parameters, which were previously ignored by the binding, are now
treated as parameters of the non-existing HmChannel with number "-1".

Signed-off-by: Florian Stolte <fstolte@itemis.de>
  • Loading branch information
FStolte authored and kaikreuzer committed Aug 2, 2018
1 parent 491ecd1 commit 95df5cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Expand Up @@ -172,7 +172,7 @@ public Collection<HmDevice> listDevices(HmInterface hmInterface) throws IOExcept
*/
public void addChannelDatapoints(HmChannel channel, HmParamsetType paramsetType) throws IOException {
RpcRequest<T> request = createRpcRequest("getParamsetDescription");
request.addArg(getRpcAddress(channel.getDevice().getAddress()) + ":" + channel.getNumber());
request.addArg(getRpcAddress(channel.getDevice().getAddress()) + getChannelSuffix(channel));
request.addArg(paramsetType.toString());
new GetParamsetDescriptionParser(channel, paramsetType).parse(sendMessage(config.getRpcPort(channel), request));
}
Expand All @@ -182,7 +182,7 @@ public void addChannelDatapoints(HmChannel channel, HmParamsetType paramsetType)
*/
public void setChannelDatapointValues(HmChannel channel, HmParamsetType paramsetType) throws IOException {
RpcRequest<T> request = createRpcRequest("getParamset");
request.addArg(getRpcAddress(channel.getDevice().getAddress()) + ":" + channel.getNumber());
request.addArg(getRpcAddress(channel.getDevice().getAddress()) + getChannelSuffix(channel));
request.addArg(paramsetType.toString());
if (channel.getDevice().getHmInterface() == HmInterface.CUXD && paramsetType == HmParamsetType.VALUES) {
setChannelDatapointValues(channel);
Expand Down Expand Up @@ -210,7 +210,7 @@ private void setChannelDatapointValues(HmChannel channel) throws IOException {
for (HmDatapoint dp : channel.getDatapoints()) {
if (dp.isReadable() && !dp.isVirtual() && dp.getParamsetType() == HmParamsetType.VALUES) {
RpcRequest<T> request = createRpcRequest("getValue");
request.addArg(getRpcAddress(channel.getDevice().getAddress()) + ":" + channel.getNumber());
request.addArg(getRpcAddress(channel.getDevice().getAddress()) + getChannelSuffix(channel));
request.addArg(dp.getName());
new GetValueParser(dp).parse(sendMessage(config.getRpcPort(channel), request));
}
Expand Down Expand Up @@ -288,12 +288,12 @@ public void setDatapointValue(HmDatapoint dp, Object value) throws IOException {
RpcRequest<T> request;
if (HmParamsetType.VALUES == dp.getParamsetType()) {
request = createRpcRequest("setValue");
request.addArg(getRpcAddress(dp.getChannel().getDevice().getAddress()) + ":" + dp.getChannel().getNumber());
request.addArg(getRpcAddress(dp.getChannel().getDevice().getAddress()) + getChannelSuffix(dp.getChannel()));
request.addArg(dp.getName());
request.addArg(value);
} else {
request = createRpcRequest("putParamset");
request.addArg(getRpcAddress(dp.getChannel().getDevice().getAddress()) + ":" + dp.getChannel().getNumber());
request.addArg(getRpcAddress(dp.getChannel().getDevice().getAddress()) + getChannelSuffix(dp.getChannel()));
request.addArg(HmParamsetType.MASTER.toString());
Map<String, Object> paramSet = new HashMap<String, Object>();
paramSet.put(dp.getName(), value);
Expand Down Expand Up @@ -389,4 +389,13 @@ public List<HmRssiInfo> loadRssiInfo(HmInterface hmInterface) throws IOException
return new RssiInfoParser(config).parse(sendMessage(config.getRpcPort(hmInterface), request));
}

/**
* Returns the address suffix that specifies the channel for a given HmChannel. This is either a colon ":" followed
* by the channel number, or the empty string. The empty string is returned for the channel -1, since this channel
* encapsulates the ParamSets of a device that do not belong to one of its channels.
*/
private String getChannelSuffix(HmChannel channel) {
return channel.getNumber() != -1 ? ":" + channel.getNumber() : "";
}

}
Expand Up @@ -54,8 +54,10 @@ public Collection<HmDevice> parse(Object[] message) throws IOException {
String id = toString(data.get("ID"));
String firmware = toString(data.get("FIRMWARE"));

devices.put(address,
new HmDevice(address, hmInterface, type, config.getGatewayInfo().getId(), id, firmware));
HmDevice device = new HmDevice(address, hmInterface, type, config.getGatewayInfo().getId(), id,
firmware);
device.addChannel(new HmChannel(type, -1));
devices.put(address, device);
} else {
// channel
String deviceAddress = getSanitizedAddress(data.get("PARENT"));
Expand Down

0 comments on commit 95df5cd

Please sign in to comment.