Skip to content

Commit

Permalink
Fix: Empty Multi-Copy Source/Target as Default and Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelius-koepp committed Nov 16, 2024
1 parent f32c9d4 commit 91145ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
35 changes: 20 additions & 15 deletions src/ConfigTransfer.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,19 @@ function _uctBtnCopy(device, online, progress, context) {
if (mode == 0) {
var sourceChannel = device.getParameterByName(context.p_channelSource).value;
var targetChannels = uctParseRangesString(device.getParameterByName(context.p_channelTargetString).value);
if (targetChannels.length == 0) {
throw new Error('Kein Ziel-Kanal definiert!');
}
// => targetChannels are NOT empty

Log.info("OpenKNX ConfigTransfer: Copy single channel " + sourceChannel + " to " + targetChannels.join(","));
uctProgressText(progress, "Kanalkopie " + module + "/" + sourceChannel + " -> " + targetChannels.join(","));

// precheck channels:
// uctGetModuleParamsDef(module, targetChannel[targetChannel.length - 1]);
if (targetChannels.length > 0) {
// ignore result, but expect error for non-existing channel
uctGetModuleParamsDef(module, targetChannels[targetChannels.length - 1]);
if (!uctIsDisjoint([sourceChannel], targetChannels)) {
throw new Error('Quell- und Ziel-Kanal dürfen NICHT identisch sein!');
}
// ignore result, but expect error for non-existing channel
uctGetModuleParamsDef(module, targetChannels[targetChannels.length - 1]);
if (!uctIsDisjoint([sourceChannel], targetChannels)) {
throw new Error('Quell- und Ziel-Kanal dürfen NICHT identisch sein!');
}

// inline without duplicate export: result.push(uctCopyModuleChannel(device, module, sourceChannel, targetChannels[i]));
Expand All @@ -278,24 +280,27 @@ function _uctBtnCopy(device, online, progress, context) {
uctProgress(progress, 97);
} else if (mode == 1) {
var sourceChannels = uctParseRangesString(device.getParameterByName(context.p_channelSourceString).value);
if (sourceChannels.length == 0) {
throw new Error('Kein Quell-Kanal definiert!');
}

var targetChannel = device.getParameterByName(context.p_channelTarget).value;
var offset = targetChannel - sourceChannels[0];
Log.info("OpenKNX ConfigTransfer: Copy channel group " + sourceChannels.join(",") + " to channels starting at " + targetChannel + "; offset=" + offset);
uctProgressText(progress, "Kanalkopie " + module + "/" + sourceChannels.join(",") + " -> ...");

if (sourceChannels.length > 0) {
// ignore result, but expect error for non-existing channel
uctGetModuleParamsDef(module, sourceChannels[sourceChannels.length - 1]);
}
// ignore result, but expect error for non-existing channel
uctGetModuleParamsDef(module, sourceChannels[sourceChannels.length - 1]);

var targetChannels = [];
for (var i = 0; i < sourceChannels.length; i++) {
targetChannels.push(sourceChannels[i] + offset);
}
if (targetChannels.length > 0) {
// ignore result, but expect error for non-existing channel
uctGetModuleParamsDef(module, targetChannels[targetChannels.length - 1]);
}
// sourceChannels NOT empty => targetChannels NOT empty

// ignore result, but expect error for non-existing channel
uctGetModuleParamsDef(module, targetChannels[targetChannels.length - 1]);

uctProgressText(progress, "Kanalkopie " + module + "/" + sourceChannels.join(",") + " -> " + targetChannels.join(","));
uctProgress(progress, 1);

Expand Down
4 changes: 2 additions & 2 deletions src/ConfigTransfer.share.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@
<Parameter Id="%AID%_P-%TT%00300" Name="CopyModul" ParameterType="%AID%_PT-ModuleSelectorWithChannels" Text="Modul" Value="255" />
<Parameter Id="%AID%_P-%TT%00306" Name="CopyMode" ParameterType="%AID%_PT-CopyMode" Text="Kopier-Modus" Value="0" />
<Parameter Id="%AID%_P-%TT%00301" Name="CopySource" ParameterType="%AID%_PT-ModuleChannel" Text="Quell-Kanal" Value="1" />
<Parameter Id="%AID%_P-%TT%00304" Name="CopySourceString" ParameterType="%AID%_PT-ChannelNot0SelectionString" Text="Quell-Kanäle" Value="1" />
<Parameter Id="%AID%_P-%TT%00304" Name="CopySourceString" ParameterType="%AID%_PT-ChannelNot0SelectionString" Text="Quell-Kanäle" Value="" />
<Parameter Id="%AID%_P-%TT%00302" Name="CopyTarget" ParameterType="%AID%_PT-ModuleChannel" Text="Ziel-Kanal" Value="1" />
<Parameter Id="%AID%_P-%TT%00305" Name="CopyTargetString" ParameterType="%AID%_PT-ChannelNot0SelectionString" Text="Ziel-Kanäle" Value="1" />
<Parameter Id="%AID%_P-%TT%00305" Name="CopyTargetString" ParameterType="%AID%_PT-ChannelNot0SelectionString" Text="Ziel-Kanäle" Value="" />
<Parameter Id="%AID%_P-%TT%00303" Name="CopyUserLog" ParameterType="%AID%_PT-Text32KiB" Text="" Value="" /><!-- Kopier-Resultat / Vorschau -->
<Parameter Id="%AID%_P-%TT%00390" Name="CopyModulChannelCount" ParameterType="%AID%_PT-ModuleChannelCount" Text="" Value="0" Access="Read" SuffixText="Kanäle" /><!-- Kanal-Anzahl im Modul -->
<Parameter Id="%AID%_P-%TT%00391" Name="CopySourceError" ParameterType="%AID%_PT-CheckBox" Text="Fehler: Quell-Kanal" Value="0" Access="None" />
Expand Down

0 comments on commit 91145ab

Please sign in to comment.