Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Protocolhash from PerlModule instead from textfile #522

Merged
merged 25 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
42c7131
00_SIGNALduino.pm
sidey79 Feb 23, 2019
33017f8
Unittest
sidey79 Feb 23, 2019
d4fe5b0
00_SIGNALduino.pm
sidey79 Feb 24, 2019
04ca2d2
signalduino_protocols.pm
sidey79 Feb 24, 2019
b2244e0
00_SIGNALduino.pm
sidey79 Feb 24, 2019
b2df75c
CHANGED
sidey79 Feb 24, 2019
b0dd362
Update signalduino_protocols.pm (#525)
HomeAutoUser Feb 24, 2019
2569955
signalduino_protocols.pm removed temporary
sidey79 Feb 24, 2019
35f7fd0
Rename signalduino_protocols.hash to signalduino_protocols.pm
sidey79 Feb 24, 2019
10d0f36
Made packae out of signalduino_protocols.pm
sidey79 Feb 24, 2019
3b77e84
Travis automatic update controls file. Build (1234) [skip ci]
Feb 24, 2019
9332606
signalduino_protocols.pm
sidey79 Feb 24, 2019
36994a6
CHANGED
sidey79 Feb 24, 2019
70dd5a5
test/test_defineDefaults-definition.txt
sidey79 Feb 24, 2019
5a10b0b
test/test_loadprotohash-definition.txt
sidey79 Feb 24, 2019
7652b39
Travis automatic update controls file. Build (1236) [skip ci]
Feb 24, 2019
09db6f5
test/test_MS_2-definition.txt
sidey79 Feb 24, 2019
53c221a
Merge branch 'dev-r34_protocolsIntoHash' of https://github.com/RFD-FH…
sidey79 Feb 24, 2019
3a9c34b
test/test_MS_2-definition.txt
sidey79 Feb 24, 2019
2837a5a
test_loadprotohash-ok.pm
sidey79 Feb 24, 2019
91fb0cf
signalduino_protocols.pm
sidey79 Feb 24, 2019
c764fa0
Travis automatic update controls file. Build (1240) [skip ci]
Feb 24, 2019
f24c6bc
00_SIGNALduino.pm
sidey79 Feb 25, 2019
ac2797b
Travis automatic update controls file. Build (1242) [skip ci]
Feb 25, 2019
4513739
Makefile
sidey79 Feb 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGED
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
25.02.2019
00_SIGNALduino: change: load protocolData from another PerlModule instead of
a text file. Fixes update via svn
24.02.2019
00_SIGNALduino: feature: last bit of transmission is tried to be reconstructed
if there is enough data available
Expand Down
29 changes: 12 additions & 17 deletions FHEM/00_SIGNALduino.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ eval "use Time::HiRes qw(gettimeofday);1" ;


use constant {
SDUINO_VERSION => "v3.4.0-dev_18.02",
SDUINO_VERSION => "v3.4.0-dev_25.02",
SDUINO_INIT_WAIT_XQ => 1.5, # wait disable device
SDUINO_INIT_WAIT => 2,
SDUINO_INIT_MAXRETRY => 3,
Expand Down Expand Up @@ -252,7 +252,7 @@ SIGNALduino_Initialize($)

#ours %attr{};

%ProtocolListSIGNALduino = SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/signalduino_protocols.hash");
%ProtocolListSIGNALduino = SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/signalduino_protocols.pm");
if (exists($ProtocolListSIGNALduino{error}) ) {
Log3 "SIGNALduino", 1, "Error loading Protocol Hash. Module is in inoperable mode error message:($ProtocolListSIGNALduino{error})";
delete($ProtocolListSIGNALduino{error});
Expand All @@ -275,25 +275,19 @@ our $FW_detail;
# First Parameter is for filename (full or relativ path) to be loaded
#
# returns a hash with protocols if loaded without error. Returns a hash with {eror} => errormessage if there was an error

sub SIGNALduino_LoadProtocolHash($)
{

sub SIGNALduino_LoadProtocolHash($)
{
if (! -e $_[0]) {
return %{ {"error" => "File does not exsits"}};
}

my $protocol_data = do {
open my $fh, '<', $_[0] ;
local $/; # Undefine $/ for this scope...
<$fh>; # so <> slurps up the entire file
};

my %evalret= eval $protocol_data ;
if (!%evalret) {
return %{ {"error" => $@}};
}
return %evalret;
use Symbol 'delete_package';
delete_package 'SD_Protocols';
delete($INC{$_[0]});
if( ! eval { require "$_[0]"; 1 } ) {
return %{ {"error" => $@}};
}
return %{SD_Protocols->getProtocolList};
}


Expand Down Expand Up @@ -369,6 +363,7 @@ SIGNALduino_Define($$)
$hash->{LASTDMSG} = "nothing";
$hash->{TIME}=time();
$hash->{versionmodul} = SDUINO_VERSION;
$hash->{versionProtocols} =SD_Protocols->VERSION();
#notifyRegexpChanged($hash,"^$name$:^opened\$"); # Auf das Event opened der eigenen Definition reagieren
#notifyRegexpChanged($hash,"sduino:opened"); # Auf das Event opened der eigenen Definition reagieren
#$hash->{NOTIFYDEV}="$name";
Expand Down
2,206 changes: 0 additions & 2,206 deletions FHEM/lib/signalduino_protocols.hash

This file was deleted.

2,212 changes: 2,212 additions & 0 deletions FHEM/lib/signalduino_protocols.pm

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/opt/fhem/FHEM/%.pm: FHEM/%.pm
sudo cp $< $@
/opt/fhem/FHEM/lib/%.hash: FHEM/lib/%.hash
sudo cp $< $@
98_UnitTest.pm: test/98_unittest.pm
sudo cp $< /opt/fhem/FHEM/$@

## deploylocal: /opt/fhem/FHEM/00_SIGNALduino.pm /opt/fhem/FHEM/10_FS10.pm /opt/fhem/FHEM/14_SD_WS.pm 98_UnitTest.pm /opt/fhem/FHEM/90_SIGNALduino_un.pm /opt/fhem/FHEM/lib/signalduino_protocols.hash
deploylocal : 98_UnitTest.pm
sudo cp FHEM/*.pm /opt/fhem/FHEM/
sudo cp FHEM/lib/*.hash /opt/fhem/FHEM/lib
sudo cp test/*.hash /opt/fhem/FHEM/lib
sudo cp FHEM/lib/*.pm /opt/fhem/FHEM/lib
sudo cp test/*.json /opt/fhem/FHEM/lib
sudo cp test/*.pm /opt/fhem/FHEM/lib
sudo timeout 3 killall -qws2 perl || sudo killall -qws9 perl || true
sudo rm /opt/fhem/log/fhem-*.log || true
sudo cp test/fhem.cfg /opt/fhem/fhem.cfg
Expand Down
4 changes: 2 additions & 2 deletions controls_signalduino.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
UPD 2019-02-24_23:32:15 198612 FHEM/00_SIGNALduino.pm
UPD 2019-02-25_20:52:07 198607 FHEM/00_SIGNALduino.pm
UPD 2017-06-23_17:43:38 14541 FHEM/10_FS10.pm
UPD 2016-09-18_21:22:06 10111 FHEM/14_BresserTemeo.pm
UPD 2018-11-11_22:35:33 13616 FHEM/14_FLAMINGO.pm
Expand All @@ -14,7 +14,7 @@ UPD 2019-02-12_21:37:35 14297 FHEM/14_SD_WS_Maverick.pm
UPD 2019-02-12_21:37:35 50246 FHEM/14_SD_WS.pm
UPD 2018-07-04_21:56:16 37910 FHEM/41_OREGON.pm
UPD 2019-02-24_22:56:57 17027 FHEM/90_SIGNALduino_un.pm
UPD 2019-02-24_23:32:15 119622 FHEM/lib/signalduino_protocols.hash
UPD 2019-02-25_00:33:04 122030 FHEM/lib/signalduino_protocols.pm
MOV FHEM/firmware/SIGNALduino_nano328.hex unused
MOV FHEM/firmware/SIGNALduino_nanoCC1101.hex unused
MOV FHEM/firmware/SIGNALduino_promini328.hex unused
Expand Down
5 changes: 4 additions & 1 deletion test/test_MS_2-definition.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmod test_MS_2 UnitTest dummyDuino (
my $mock = Mock::Sub->new;
my $SD_Dispatch = $mock->mock("SIGNALduno_Dispatch");

my %ProtocolListTest = SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/test_loadprotohash-ok.hash");
my %ProtocolListTest = SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/test_loadprotohash-ok.pm");
my $local_ProtocolListSIGNALduino = SIGNALduino_getProtocolList();
%{$local_ProtocolListSIGNALduino} = ( %ProtocolListTest);

Expand All @@ -26,5 +26,8 @@ defmod test_MS_2 UnitTest dummyDuino (
};
}
}
CommandReload(undef,"00_SIGNALduino.pm");
SIGNALduino_IdList("x:$target","","","");

}
);
5 changes: 3 additions & 2 deletions test/test_defineDefaults-definition.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
defmod test_defineDefaults UnitTest dummyDuino (
{
CommandDefMod(undef,"-temporary testDuino SIGNALduino none");


subtest 'Check internal defaults ' => sub {
plan tests => 4;
plan tests => 5;
my $name ="testDuino";

is(InternalVal($name,"DeviceName", undef),"none","check DeviceName");
is(InternalVal($name,"DMSG", undef),"nothing","check DMSG");
is(InternalVal($name,"LASTDMSG", undef),"nothing","check LASTDMSG");
is(InternalVal($name,"versionmodul", undef),SDUINO_VERSION,"check versionmodul");
is(InternalVal($name,"versionProtocols", undef),SD_Protocols->VERSION(),"check versionProtocols");
};

};
Expand Down
2 changes: 1 addition & 1 deletion test/test_developid_1-definition.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmod test_developid_1 UnitTest dummyDuino (
{

my %ProtocolListTest = SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/test_loadprotohash-ok.hash");
my %ProtocolListTest = SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/test_loadprotohash-ok.pm");
is($ProtocolListTest{error},undef,"load test protocol hash ");


Expand Down
12 changes: 8 additions & 4 deletions test/test_loadprotohash-definition.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
defmod test_loadprotohash UnitTest dummyDuino
(
{
plan tests => 3;
my %ret= SIGNALduino_LoadProtocolHash("dummy.hash");
ok(exists($ret{error}),"check wrong filename");

%ret= SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/test_loadprotohash-ok.hash");
is($ret{error},undef,"check filename and syntax ok ");

%ret= SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/test_loadprotohash-nok.hash");
%ret= SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/test_loadprotohash-ok.pm");
is($ret{error},undef,"check filename and syntax ok ");

%ret= SIGNALduino_LoadProtocolHash("$attr{global}{modpath}/FHEM/lib/test_loadprotohash-nok.pm");
ok(exists($ret{error}),"check filename and syntax not ok "); }

CommandReload(undef,"00_SIGNALduino.pm");
SIGNALduino_IdList("x:$target","","","");
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(
package SD_Protocols;
{
my %signalduino_protocols = (
"9999" =>
{
name => 'Unittest MS Protocol',
Expand All @@ -7,4 +9,6 @@
},


);
);
sub getProtocolList { return \%signalduino_protocols; }
}
203 changes: 0 additions & 203 deletions test/test_loadprotohash-ok.hash

This file was deleted.

Loading