diff --git a/CHANGED b/CHANGED index c14cc6e..1071ca4 100644 --- a/CHANGED +++ b/CHANGED @@ -1,3 +1,4 @@ +2026-04-30 - Fix SIGNALduino protocol loader 2026-04-28 - Support schema-wrapped protocol JSON 2026-04-28 - Bugfix link "check it" (#160) diff --git a/FHEM/88_SIGNALduino_TOOL.pm b/FHEM/88_SIGNALduino_TOOL.pm index f52ea58..eddd404 100644 --- a/FHEM/88_SIGNALduino_TOOL.pm +++ b/FHEM/88_SIGNALduino_TOOL.pm @@ -1177,12 +1177,19 @@ sub SIGNALduino_TOOL_Get { ## create one list in csv format to import in other program ## if ($cmd eq 'TimingsList') { Log3 $name, 4, "$name: Get $cmd - check (1)"; - my %ProtocolListSIGNALduino = SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/lib/FHEM/Devices/SIGNALduino/SD_Protocols/Data.pm"); - if (exists($ProtocolListSIGNALduino{error}) ) { - Log3 "SIGNALduino", 1, "Error loading Protocol Hash. Module is in inoperable mode error message:($ProtocolListSIGNALduino{error})"; - delete($ProtocolListSIGNALduino{error}); + my $protocolObject = FHEM::Devices::SIGNALduino::SD_Protocols->new(); + my $protocolFile = "$attr{global}{modpath}/lib/FHEM/Devices/SIGNALduino/SD_Protocols/Data.pm"; + my $protocolLoadError = $protocolObject->LoadHash($protocolFile); + if (defined $protocolLoadError && $protocolLoadError ne '') { + Log3 "SIGNALduino", 1, "Error loading Protocol Hash. Module is in inoperable mode error message:($protocolLoadError)"; return; } + my $protocolList = $protocolObject->getProtocolList(); + if (!defined $protocolList || ref($protocolList) ne 'HASH') { + Log3 "SIGNALduino", 1, "Error loading Protocol Hash. Module is in inoperable mode error message:(protocol list is not available)"; + return; + } + my %ProtocolListSIGNALduino = %{$protocolList}; my $file = 'timings.txt'; my @value; # for values from hash_list @@ -1197,7 +1204,11 @@ sub SIGNALduino_TOOL_Get { ### max Werte von value_name array ### for my $i (0..scalar(@value_name)-1) { if (not exists $value_max[$i]) { $value_max[$i] = 0; } - if (exists $ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]} && scalar(@{$ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]}}) > $value_max[$i]) { $value_max[$i] = scalar(@{$ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]}}); } + if (exists $ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]} && defined $ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]}) { + my $timing_value = $ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]}; + my $timing_value_count = ref($timing_value) eq 'ARRAY' ? scalar(@{$timing_value}) : 1; + if ($timing_value_count > $value_max[$i]) { $value_max[$i] = $timing_value_count; } + } } } @@ -1222,9 +1233,12 @@ sub SIGNALduino_TOOL_Get { } ### ENDE ### - foreach my $e(@{$ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]}}) { - $value[$valuecount] = $e; - $valuecount++; + if (exists $ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]} && defined $ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]}) { + my $timing_value = $ProtocolListSIGNALduino{$timings_protocol}{$value_name[$i]}; + foreach my $e (ref($timing_value) eq 'ARRAY' ? @{$timing_value} : ($timing_value)) { + $value[$valuecount] = $e; + $valuecount++; + } } if ($i == 0) { diff --git a/controls_SD_TOOL.txt b/controls_SD_TOOL.txt index 4f2b99e..c04b5b0 100644 --- a/controls_SD_TOOL.txt +++ b/controls_SD_TOOL.txt @@ -1,2 +1,2 @@ -UPD 2026-04-28_23:20:13 285940 FHEM/88_SIGNALduino_TOOL.pm +UPD 2026-04-30_20:18:18 286778 FHEM/88_SIGNALduino_TOOL.pm UPD 2026-04-27_22:55:13 362979 FHEM/lib/SD_Device_ProtocolList.json diff --git a/t/FHEM/88_SIGNALduino_TOOL/10_load.t b/t/FHEM/88_SIGNALduino_TOOL/10_load.t index e2681bf..a571fd0 100644 --- a/t/FHEM/88_SIGNALduino_TOOL/10_load.t +++ b/t/FHEM/88_SIGNALduino_TOOL/10_load.t @@ -3,6 +3,8 @@ package main; use strict; use warnings; +use File::Spec; +use File::Temp qw(tempdir); use Test2::V1 qw(-ipP); my $tool_name = 'SIGNALduino_TOOL'; @@ -23,6 +25,33 @@ ok(!FhemTestUtils_gotLog('Unknown module SIGNALduino_TOOL'), 'No unknown-module ok(!FhemTestUtils_gotLog('SIGNALduino_TOOL:.*ERROR'), 'No SIGNALduino_TOOL error was logged during startup'); ok(!FhemTestUtils_gotLog('Cannot load module SIGNALduino_TOOL'), 'FHEM loaded the module successfully'); +my $timings_dir = tempdir(CLEANUP => 1); +CommandAttr(undef, "$tool_name Path $timings_dir/"); + +my $timings_result = eval { CommandGet(undef, "$tool_name TimingsList") }; +my $timings_error = $@; + +is($timings_error, '', 'TimingsList get command did not die'); +like( + $timings_result, + qr/New TimingsList \(timings\.txt\) are created!/, + 'TimingsList get command reports success' +); +is(ReadingsVal($tool_name, 'state', undef), 'TimingsList created', 'TimingsList updates the state reading'); + +my $timings_file = File::Spec->catfile($timings_dir, 'timings.txt'); +ok(-e $timings_file, 'TimingsList created timings.txt'); + +my $timings_content = do { + open my $fh, '<', $timings_file or die "Unable to open $timings_file: $!"; + local $/; + <$fh>; +}; + +like($timings_content, qr/^id;typ;clockabs;/, 'TimingsList writes a CSV header'); +like($timings_content, qr/(?:^|;)2DD4(?:;|\n)/m, 'TimingsList writes scalar sync values'); +ok(!FhemTestUtils_gotLog(q[Can't use string .* as an ARRAY ref]), 'TimingsList did not log scalar-as-array errors'); + done_testing; exit(0); diff --git a/t/load_protocol_package.t b/t/load_protocol_package.t index 7089e05..b41e045 100644 --- a/t/load_protocol_package.t +++ b/t/load_protocol_package.t @@ -39,5 +39,6 @@ my $module_source = do { like($module_source, qr/use FHEM::Devices::SIGNALduino::SD_Protocols;/, 'Module uses the new protocol package'); like($module_source, qr{lib/FHEM/Devices/SIGNALduino/SD_Protocols/Data\.pm}, 'Module references the new protocol data path'); +unlike($module_source, qr/SIGNALduino_LoadProtocolHash/, 'Module no longer calls the removed protocol loader'); done_testing;