From 2d60ebbd5d9fb7d58d03920d680fe955c94d076f Mon Sep 17 00:00:00 2001 From: Bernd Gewehr Date: Thu, 17 Mar 2016 10:01:00 +0100 Subject: [PATCH 1/9] Update 99_fronthemUtils.pm first steps to new JSON evaluation --- FHEM/99_fronthemUtils.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/FHEM/99_fronthemUtils.pm b/FHEM/99_fronthemUtils.pm index 9371e4e..a4199c2 100644 --- a/FHEM/99_fronthemUtils.pm +++ b/FHEM/99_fronthemUtils.pm @@ -36,6 +36,15 @@ sub UZSU_execute($$) for(my $i=0; $i < @{$uzsu->{list}}; $i++) { my $weekdays = $uzsu->{list}[$i]->{rrule}; $weekdays = substr($weekdays,18,50); + # if the structure contains the holidays list, use it! + if {list}[$i]->{holidays} { + if {list}[$i]->{holiday}->{weekend} { + $weekdays = $weekdays . ',$we'; + } + if {list}[$i]->{holiday}->{work} { + $weekdays = $weekdays . ',$!we'; + } + } if (($uzsu->{list}[$i]->{active})) { if ($uzsu->{list}[$i]->{event} eq 'time'){ $weekdays_part = $weekdays_part.' '.$weekdays.'|'.$uzsu->{list}[$i]->{time}.'|'.$uzsu->{list}[$i]->{value}; @@ -50,6 +59,14 @@ sub UZSU_execute($$) } } } + if {list}[$i]->{condition} { + if {list}[$i]->{condition}->{conditionType} eq 'Perl' { + $weekdays_part = $weekdayspart.'|('.{list}[$i]->{condition}->{conditionDevicePerl}.')' + } + else { + $weekdays_part = $weekdayspart.'|(ReadingsVal("'.{list}[$i]->{condition}->{conditionDevicePerl}.'","'.{list}[$i]->{condition}->{conditionType}.'","") eq "'.{list}[$i]->{condition}->{conditionValue}.'")' + } + } } fhem('defmod wdt_uzsu_'.$device.' WeekdayTimer '.$device.' en '.$weekdays_part); if ($uzsu->{active}){ From fc9e33aa72e7790299602f1985527ee2410c996c Mon Sep 17 00:00:00 2001 From: Bernd Gewehr Date: Thu, 17 Mar 2016 19:05:49 +0100 Subject: [PATCH 2/9] Update 99_fronthemUtils.pm --- FHEM/99_fronthemUtils.pm | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/FHEM/99_fronthemUtils.pm b/FHEM/99_fronthemUtils.pm index a4199c2..aefd1a2 100644 --- a/FHEM/99_fronthemUtils.pm +++ b/FHEM/99_fronthemUtils.pm @@ -59,6 +59,7 @@ sub UZSU_execute($$) } } } + # if the structure contains a condition, use it! if {list}[$i]->{condition} { if {list}[$i]->{condition}->{conditionType} eq 'Perl' { $weekdays_part = $weekdayspart.'|('.{list}[$i]->{condition}->{conditionDevicePerl}.')' @@ -67,16 +68,16 @@ sub UZSU_execute($$) $weekdays_part = $weekdayspart.'|(ReadingsVal("'.{list}[$i]->{condition}->{conditionDevicePerl}.'","'.{list}[$i]->{condition}->{conditionType}.'","") eq "'.{list}[$i]->{condition}->{conditionValue}.'")' } } - } - fhem('defmod wdt_uzsu_'.$device.' WeekdayTimer '.$device.' en '.$weekdays_part); - if ($uzsu->{active}){ - fhem('attr wdt_uzsu_'.$device.' disable 0'); -} else { - fhem('attr wdt_uzsu_'.$device.' disable 1'); -} - fhem('attr wdt_uzsu_'.$device.' room UZSU'); - #fhem('save'); # use only if you want to save WDT settings immediately. - + fhem('defmod wdt_uzsu_'.$device.' WeekdayTimer '.$device.' en '.$weekdays_part); + if ($uzsu->{active}){ + fhem('attr wdt_uzsu_'.$device.' disable 0'); + } else { + fhem('attr wdt_uzsu_'.$device.' disable 1'); + } + fhem('attr wdt_uzsu_'.$device.'-'.$i.' room UZSU'); + fhem('attr wdt_uzsu_'.$device.'-'.$i.' group '.$device); + #fhem('save'); # use only if you want to save WDT settings immediately. + } } package fronthem; From 67bd1f9e396ab518d2dcc7cbb1acc34bf656fde1 Mon Sep 17 00:00:00 2001 From: Bernd Gewehr Date: Thu, 17 Mar 2016 20:03:58 +0100 Subject: [PATCH 3/9] Update 99_fronthemUtils.pm --- FHEM/99_fronthemUtils.pm | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/FHEM/99_fronthemUtils.pm b/FHEM/99_fronthemUtils.pm index aefd1a2..592721b 100644 --- a/FHEM/99_fronthemUtils.pm +++ b/FHEM/99_fronthemUtils.pm @@ -37,12 +37,12 @@ sub UZSU_execute($$) my $weekdays = $uzsu->{list}[$i]->{rrule}; $weekdays = substr($weekdays,18,50); # if the structure contains the holidays list, use it! - if {list}[$i]->{holidays} { - if {list}[$i]->{holiday}->{weekend} { + if ({list}[$i]->{holidays}) { + if ({list}[$i]->{holiday}->{weekend}) { $weekdays = $weekdays . ',$we'; } - if {list}[$i]->{holiday}->{work} { - $weekdays = $weekdays . ',$!we'; + if ({list}[$i]->{holiday}->{work}) { + $weekdays = $weekdays . ',!$we'; } } if (($uzsu->{list}[$i]->{active})) { @@ -53,22 +53,20 @@ sub UZSU_execute($$) # Bugfix below: because sunset_abs from 99_sunrise_el does not work if max-time = "" if ($uzsu->{list}[$i]->{timeMin} ne '' and $uzsu->{list}[$i]->{timeMax} ne '') { $weekdays_part = $weekdays_part.' '.$weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',"'.$uzsu->{list}[$i]->{timeMin}.'","'.$uzsu->{list}[$i]->{timeMax}.'")}|'.$uzsu->{list}[$i]->{value}; - } - else { + } else { $weekdays_part = $weekdays_part.' '.$weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',,)}|'.$uzsu->{list}[$i]->{value}; } } } # if the structure contains a condition, use it! - if {list}[$i]->{condition} { - if {list}[$i]->{condition}->{conditionType} eq 'Perl' { - $weekdays_part = $weekdayspart.'|('.{list}[$i]->{condition}->{conditionDevicePerl}.')' - } - else { - $weekdays_part = $weekdayspart.'|(ReadingsVal("'.{list}[$i]->{condition}->{conditionDevicePerl}.'","'.{list}[$i]->{condition}->{conditionType}.'","") eq "'.{list}[$i]->{condition}->{conditionValue}.'")' + if ({list}[$i]->{condition}) { + if ({list}[$i]->{condition}->{conditionType} eq 'Perl') { + $weekdays_part = $weekdayspart.'|('.{list}[$i]->{condition}->{conditionDevicePerl}.')'; + } else { + $weekdays_part = $weekdayspart.'|(ReadingsVal("'.{list}[$i]->{condition}->{conditionDevicePerl}.'","'.{list}[$i]->{condition}->{conditionType}.'","") eq "'.{list}[$i]->{condition}->{conditionValue}.'")'; } } - fhem('defmod wdt_uzsu_'.$device.' WeekdayTimer '.$device.' en '.$weekdays_part); + fhem('defmod wdt_uzsu_'.$device.'-'.$i.' WeekdayTimer '.$device.' en '.$weekdays_part); if ($uzsu->{active}){ fhem('attr wdt_uzsu_'.$device.' disable 0'); } else { From 9f651c1cf536f8838d95c22369cd0375d3e58e97 Mon Sep 17 00:00:00 2001 From: Bernd Gewehr Date: Thu, 17 Mar 2016 21:37:19 +0100 Subject: [PATCH 4/9] Update 99_fronthemUtils.pm adopted the uzsu_execute to the dev 4.3 JSON of MWORIONs UZSU_widget --- FHEM/99_fronthemUtils.pm | 72 +++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/FHEM/99_fronthemUtils.pm b/FHEM/99_fronthemUtils.pm index 592721b..7f8b944 100644 --- a/FHEM/99_fronthemUtils.pm +++ b/FHEM/99_fronthemUtils.pm @@ -29,53 +29,57 @@ sub fronthem_encodejson($) { sub UZSU_execute($$) { my ($device, $uzsu) = @_; + my $weekdays = ""; $uzsu = decode_json($uzsu); - my $weekdays_part = " "; + fhem('delete wdt_uzsu_'.$device.'_.*'); + for(my $i=0; $i < @{$uzsu->{list}}; $i++) { - my $weekdays = $uzsu->{list}[$i]->{rrule}; + $weekdays = $uzsu->{list}[$i]->{rrule}; $weekdays = substr($weekdays,18,50); + # if the structure contains the holidays list, use it! - if ({list}[$i]->{holidays}) { - if ({list}[$i]->{holiday}->{weekend}) { - $weekdays = $weekdays . ',$we'; - } - if ({list}[$i]->{holiday}->{work}) { - $weekdays = $weekdays . ',!$we'; - } + if ($uzsu->{list}[$i]->{holiday}->{weekend}) { + if ($weekdays ne '') { + $weekdays = $weekdays . ','; + } + $weekdays = $weekdays . '$we'; } - if (($uzsu->{list}[$i]->{active})) { - if ($uzsu->{list}[$i]->{event} eq 'time'){ - $weekdays_part = $weekdays_part.' '.$weekdays.'|'.$uzsu->{list}[$i]->{time}.'|'.$uzsu->{list}[$i]->{value}; + if ($uzsu->{list}[$i]->{holiday}->{work}) { + if ($weekdays ne '') { + $weekdays = $weekdays . ','; + } + $weekdays = $weekdays . '!$we'; + } + + if ($uzsu->{list}[$i]->{event} eq 'time'){ + $weekdays = $weekdays.'|'.$uzsu->{list}[$i]->{time}.'|'.$uzsu->{list}[$i]->{value}; + } else { + # Bugfix below: because sunset_abs from 99_sunrise_el does not work if max-time = "" + if ($uzsu->{list}[$i]->{timeMin} ne '' and $uzsu->{list}[$i]->{timeMax} ne '') { + $weekdays = $weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',"'.$uzsu->{list}[$i]->{timeMin}.'","'.$uzsu->{list}[$i]->{timeMax}.'")}|'.$uzsu->{list}[$i]->{value}; + } else { + $weekdays = $weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',,)}|'.$uzsu->{list}[$i]->{value}; } - else { - # Bugfix below: because sunset_abs from 99_sunrise_el does not work if max-time = "" - if ($uzsu->{list}[$i]->{timeMin} ne '' and $uzsu->{list}[$i]->{timeMax} ne '') { - $weekdays_part = $weekdays_part.' '.$weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',"'.$uzsu->{list}[$i]->{timeMin}.'","'.$uzsu->{list}[$i]->{timeMax}.'")}|'.$uzsu->{list}[$i]->{value}; - } else { - $weekdays_part = $weekdays_part.' '.$weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',,)}|'.$uzsu->{list}[$i]->{value}; - } - } } + # if the structure contains a condition, use it! - if ({list}[$i]->{condition}) { - if ({list}[$i]->{condition}->{conditionType} eq 'Perl') { - $weekdays_part = $weekdayspart.'|('.{list}[$i]->{condition}->{conditionDevicePerl}.')'; + if ($uzsu->{list}[$i]->{condition}->{conditionActive}) { + if ($uzsu->{list}[$i]->{condition}->{conditionType} eq 'Perl') { + $weekdays = $weekdays.' ('.$uzsu->{list}[$i]->{condition}->{conditionDevicePerl}.')'; } else { - $weekdays_part = $weekdayspart.'|(ReadingsVal("'.{list}[$i]->{condition}->{conditionDevicePerl}.'","'.{list}[$i]->{condition}->{conditionType}.'","") eq "'.{list}[$i]->{condition}->{conditionValue}.'")'; + $weekdays = $weekdays.' (ReadingsVal("'.$uzsu->{list}[$i]->{condition}->{conditionDevicePerl}.'","state","") '.$uzsu->{list}[$i]->{condition}->{conditionType}.' "'.$uzsu->{list}[$i]->{condition}->{conditionValue}.'")'; } } - fhem('defmod wdt_uzsu_'.$device.'-'.$i.' WeekdayTimer '.$device.' en '.$weekdays_part); - if ($uzsu->{active}){ - fhem('attr wdt_uzsu_'.$device.' disable 0'); - } else { - fhem('attr wdt_uzsu_'.$device.' disable 1'); - } - fhem('attr wdt_uzsu_'.$device.'-'.$i.' room UZSU'); - fhem('attr wdt_uzsu_'.$device.'-'.$i.' group '.$device); - #fhem('save'); # use only if you want to save WDT settings immediately. - } + + if ($uzsu->{list}[$i]->{active}){ + fhem('defmod wdt_uzsu_'.$device.'_'.$i.' WeekdayTimer '.$device.' en '.$weekdays); + fhem('attr wdt_uzsu_'.$device.'_'.$i.' room UZSU'); + fhem('attr wdt_uzsu_'.$device.'_'.$i.' group '.$device); + } + #fhem('save'); # use only if you want to save WDT settings immediately. + } } package fronthem; From e2a62b12a02a82bc25f8065410e2c9dc538a2307 Mon Sep 17 00:00:00 2001 From: Bernd Gewehr Date: Mon, 21 Mar 2016 18:22:52 +0100 Subject: [PATCH 5/9] Update 99_fronthemUtils.pm --- FHEM/99_fronthemUtils.pm | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/FHEM/99_fronthemUtils.pm b/FHEM/99_fronthemUtils.pm index 7f8b944..1991cf7 100644 --- a/FHEM/99_fronthemUtils.pm +++ b/FHEM/99_fronthemUtils.pm @@ -30,11 +30,12 @@ sub UZSU_execute($$) { my ($device, $uzsu) = @_; my $weekdays = ""; - + my $perlString = ""; + $uzsu = decode_json($uzsu); - fhem('delete wdt_uzsu_'.$device.'_.*'); - + fhem('delete wdt_uzsu_'.$device.'.*'); + for(my $i=0; $i < @{$uzsu->{list}}; $i++) { $weekdays = $uzsu->{list}[$i]->{rrule}; $weekdays = substr($weekdays,18,50); @@ -65,10 +66,17 @@ sub UZSU_execute($$) } # if the structure contains a condition, use it! - if ($uzsu->{list}[$i]->{condition}->{conditionActive}) { - if ($uzsu->{list}[$i]->{condition}->{conditionType} eq 'Perl') { - $weekdays = $weekdays.' ('.$uzsu->{list}[$i]->{condition}->{conditionDevicePerl}.')'; + if ($uzsu->{list}[$i]->{condition}->{conditionActive}) { + if ($uzsu->{list}[$i]->{condition}->{conditionType} eq 'Perl') { + print 'Perl-Condition\n'; + $perlString = $uzsu->{list}[$i]->{condition}->{conditionDevicePerl}; + print $perlString; + #$perlString =~ s/\\"/"/ig; + #print $perlString; + $weekdays = $weekdays.' ('.$perlString.')'; + print $weekdays; } else { + print 'non-Perl-Condition\n'; $weekdays = $weekdays.' (ReadingsVal("'.$uzsu->{list}[$i]->{condition}->{conditionDevicePerl}.'","state","") '.$uzsu->{list}[$i]->{condition}->{conditionType}.' "'.$uzsu->{list}[$i]->{condition}->{conditionValue}.'")'; } } @@ -114,13 +122,14 @@ sub UZSU(@) if ($param->{cmd} eq 'send') { $param->{gad} = $gad; - $param->{gadval} = main::fronthem_decodejson(main::ReadingsVal($device, $reading, '')); + $param->{gadval} = main::fronthem_decodejson(main::ReadingsVal($device, $reading, '{}')); $param->{gads} = []; return undef; } elsif ($param->{cmd} eq 'rcv') { $gadval = main::fronthem_encodejson($gadval); + main::UZSU_execute($device, $gadval); $gadval =~ s/;/;;/ig; $param->{result} = main::fhem("setreading $device $reading $gadval"); $param->{results} = []; From 215d40ca56a4a39ea2993ea2b0f98be07f512eca Mon Sep 17 00:00:00 2001 From: Bernd Gewehr Date: Mon, 21 Mar 2016 18:55:39 +0100 Subject: [PATCH 6/9] Update 99_fronthemUtils.pm --- FHEM/99_fronthemUtils.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/FHEM/99_fronthemUtils.pm b/FHEM/99_fronthemUtils.pm index 1991cf7..d5b0167 100644 --- a/FHEM/99_fronthemUtils.pm +++ b/FHEM/99_fronthemUtils.pm @@ -68,15 +68,15 @@ sub UZSU_execute($$) # if the structure contains a condition, use it! if ($uzsu->{list}[$i]->{condition}->{conditionActive}) { if ($uzsu->{list}[$i]->{condition}->{conditionType} eq 'Perl') { - print 'Perl-Condition\n'; - $perlString = $uzsu->{list}[$i]->{condition}->{conditionDevicePerl}; - print $perlString; - #$perlString =~ s/\\"/"/ig; - #print $perlString; + Log 4, 'uzsu Perl-Condition\n'; + $perlString = $uzsu->{list}[$i]->{condition}->{conditionDevicePerl}; + Log 4, 'uzsu ' . $perlString; + #$perlString =~ s/\\"/"/ig; + #Log 4, 'uzsu ' . $perlString; $weekdays = $weekdays.' ('.$perlString.')'; - print $weekdays; + Log 4, 'uzsu ' , $weekdays; } else { - print 'non-Perl-Condition\n'; + Log 4, 'uzsu non-Perl-Condition\n'; $weekdays = $weekdays.' (ReadingsVal("'.$uzsu->{list}[$i]->{condition}->{conditionDevicePerl}.'","state","") '.$uzsu->{list}[$i]->{condition}->{conditionType}.' "'.$uzsu->{list}[$i]->{condition}->{conditionValue}.'")'; } } From dddffce6d00e6cf5ff114d5b73fff9ff7366cd9f Mon Sep 17 00:00:00 2001 From: Bernd Gewehr Date: Sat, 26 Mar 2016 23:12:47 +0100 Subject: [PATCH 7/9] Update 99_fronthemUtils.pm Passt zur V4.5 --- FHEM/99_fronthemUtils.pm | 172 +++++++++++++++++++++++++-------------- 1 file changed, 110 insertions(+), 62 deletions(-) diff --git a/FHEM/99_fronthemUtils.pm b/FHEM/99_fronthemUtils.pm index d5b0167..c0d62b1 100644 --- a/FHEM/99_fronthemUtils.pm +++ b/FHEM/99_fronthemUtils.pm @@ -20,76 +20,124 @@ sub fronthem_encodejson($) { return encode_json($_[0]); } - ############################################################################### # # Umsetzen der UZSU-Settings für ein device +# for use with UZSU widget V4.4 # ############################################################################### -sub UZSU_execute($$) +sub UZSU_execute($@) { - my ($device, $uzsu) = @_; - my $weekdays = ""; - my $perlString = ""; - - $uzsu = decode_json($uzsu); - - fhem('delete wdt_uzsu_'.$device.'.*'); - - for(my $i=0; $i < @{$uzsu->{list}}; $i++) { - $weekdays = $uzsu->{list}[$i]->{rrule}; - $weekdays = substr($weekdays,18,50); - - # if the structure contains the holidays list, use it! - if ($uzsu->{list}[$i]->{holiday}->{weekend}) { - if ($weekdays ne '') { - $weekdays = $weekdays . ','; - } - $weekdays = $weekdays . '$we'; - } - if ($uzsu->{list}[$i]->{holiday}->{work}) { - if ($weekdays ne '') { - $weekdays = $weekdays . ','; - } - $weekdays = $weekdays . '!$we'; - } - - if ($uzsu->{list}[$i]->{event} eq 'time'){ - $weekdays = $weekdays.'|'.$uzsu->{list}[$i]->{time}.'|'.$uzsu->{list}[$i]->{value}; - } else { - # Bugfix below: because sunset_abs from 99_sunrise_el does not work if max-time = "" - if ($uzsu->{list}[$i]->{timeMin} ne '' and $uzsu->{list}[$i]->{timeMax} ne '') { - $weekdays = $weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',"'.$uzsu->{list}[$i]->{timeMin}.'","'.$uzsu->{list}[$i]->{timeMax}.'")}|'.$uzsu->{list}[$i]->{value}; - } else { - $weekdays = $weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',,)}|'.$uzsu->{list}[$i]->{value}; - } - } - - # if the structure contains a condition, use it! - if ($uzsu->{list}[$i]->{condition}->{conditionActive}) { - if ($uzsu->{list}[$i]->{condition}->{conditionType} eq 'Perl') { - Log 4, 'uzsu Perl-Condition\n'; - $perlString = $uzsu->{list}[$i]->{condition}->{conditionDevicePerl}; - Log 4, 'uzsu ' . $perlString; - #$perlString =~ s/\\"/"/ig; - #Log 4, 'uzsu ' . $perlString; - $weekdays = $weekdays.' ('.$perlString.')'; - Log 4, 'uzsu ' , $weekdays; - } else { - Log 4, 'uzsu non-Perl-Condition\n'; - $weekdays = $weekdays.' (ReadingsVal("'.$uzsu->{list}[$i]->{condition}->{conditionDevicePerl}.'","state","") '.$uzsu->{list}[$i]->{condition}->{conditionType}.' "'.$uzsu->{list}[$i]->{condition}->{conditionValue}.'")'; - } - } - - if ($uzsu->{list}[$i]->{active}){ - fhem('defmod wdt_uzsu_'.$device.'_'.$i.' WeekdayTimer '.$device.' en '.$weekdays); - fhem('attr wdt_uzsu_'.$device.'_'.$i.' room UZSU'); - fhem('attr wdt_uzsu_'.$device.'_'.$i.' group '.$device); - } - #fhem('save'); # use only if you want to save WDT settings immediately. - } +my ($device, $uzsu) = @_; +my $weekdays = ""; +my $condition = ""; +my $delayedExec =""; +my $perlString = ""; + +$uzsu = decode_json($uzsu); + +fhem('delete wdt_uzsu_'.$device.'.*'); + +for(my $i=0; $i < @{$uzsu->{list}}; $i++) { + $weekdays = $uzsu->{list}[$i]->{rrule}; + $weekdays = substr($weekdays,18,50); + $delayedExec = ""; + $condition = ""; + + # if the structure contains the holidays list, use it! + if ($uzsu->{list}[$i]->{holiday}->{weekend}) { + if ($weekdays ne '') { + $weekdays = $weekdays . ','; + } + $weekdays = $weekdays . '$we'; + } + if ($uzsu->{list}[$i]->{holiday}->{work}) { + if ($weekdays ne '') { + $weekdays = $weekdays . ','; + } + $weekdays = $weekdays . '!$we'; + } + + if ($uzsu->{list}[$i]->{event} eq 'time'){ + $weekdays = $weekdays.'|'.$uzsu->{list}[$i]->{time}.'|'.$uzsu->{list}[$i]->{value}; + } else { + # Bugfix below: because sunset_abs from 99_sunrise_el does not work if max-time = "" + if ($uzsu->{list}[$i]->{timeMin} ne '' and $uzsu->{list}[$i]->{timeMax} ne '') { + $weekdays = $weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',"'.$uzsu->{list}[$i]->{timeMin}.'","'.$uzsu->{list}[$i]->{timeMax}.'")}|'.$uzsu->{list}[$i]->{value}; + } else { + $weekdays = $weekdays.'|{'.$uzsu->{list}[$i]->{event}.'_abs("REAL",'.$uzsu->{list}[$i]->{timeOffset} * 60 .',,)}|'.$uzsu->{list}[$i]->{value}; + } + } + + # if the structure contains a condition, use it! + if ($uzsu->{list}[$i]->{condition}->{active}) { + if ($uzsu->{list}[$i]->{condition}->{type} eq 'Perl') { + Log 4, 'uzsu Perl-Condition\n'; + $perlString = trim($uzsu->{list}[$i]->{condition}->{devicePerl}); + Log 4, 'uzsu ' . $perlString; + #$perlString =~ s/\\"/"/ig; + #Log 4, 'uzsu ' . $perlString; + # remove leading '{' and trailing '}' + if (substr($perlString,0,1) eq "{" && substr($perlString,length($perlString)-1,1) eq "}") { + $perlString = trim(substr($perlString,1,length($perlString)-2)); + } + # remove leading '(' and trailing ')' + if (substr($perlString,0,1) eq "(" && substr($perlString,length($perlString)-1,1) eq ")") { + $perlString = trim(substr($perlString,1,length($perlString)-2)); + } + if (substr($perlString,0,4) eq "fhem") { + $condition = ' {'.$perlString.'}'; + } else { + $condition = ' ('.$perlString.')'; + } + Log 4, 'uzsu '.$weekdays.' '.$condition; + } else { + Log 4, 'uzsu non-Perl-Condition\n'; + $condition = ' (ReadingsVal("'.$uzsu->{list}[$i]->{condition}->{devicePerl}.'","state","") '.$uzsu->{list}[$i]->{condition}->{type}.' "'.$uzsu->{list}[$i]->{condition}->{value}.'")'; + } + } + + # if the structure contains a delayedExec, use it! + if ($uzsu->{list}[$i]->{delayedExec}->{active}) { + if ($uzsu->{list}[$i]->{delayedExec}->{type} eq 'Perl') { + Log 4, 'uzsu Perl-Condition\n'; + $perlString = trim($uzsu->{list}[$i]->{delayedExec}->{devicePerl}); + Log 4, 'uzsu ' . $perlString; + #$perlString =~ s/\\"/"/ig; + #Log 4, 'uzsu ' . $perlString; + # remove leading '{' and trailing '}' + if (substr($perlString,0,1) eq "{" && substr($perlString,length($perlString)-1,1) eq "}") { + $perlString = trim(substr($perlString,1,length($perlString)-2)); + } + # remove leading '(' and trailing ')' + if (substr($perlString,0,1) eq "(" && substr($perlString,length($perlString)-1,1) eq ")") { + $perlString = trim(substr($perlString,1,length($perlString)-2)); + } + $delayedExec = '{ ('.$perlString.') }'; + #Log 4, 'uzsu ' , $delayedExec; + } else { + Log 4, 'uzsu non-Perl-Condition\n'; + $delayedExec = '{ (ReadingsVal("'.$uzsu->{list}[$i]->{delayedExec}->{devicePerl}.'","state","") '.$uzsu->{list}[$i]->{delayedExec}->{type}.' "'.$uzsu->{list}[$i]->{delayedExec}->{value}.'") }'; + } + } + + + if ($uzsu->{list}[$i]->{active}){ + fhem('defmod wdt_uzsu_'.$device.'_'.$i.' WeekdayTimer '.$device.' en '.trim($weekdays.$condition)); + fhem('attr wdt_uzsu_'.$device.'_'.$i.' room UZSU'); + fhem('attr wdt_uzsu_'.$device.'_'.$i.' group '.$device); + fhem('setreading wdt_uzsu_'.$device.'_'.$i.' weekdays '.trim($weekdays) ); + fhem('defmod rg_uzsu_'.$device.' readingsgroup wdt_uzsu_'.$device.'.*'); + fhem('attr rg_uzsu_'.$device.' room UZSU'); + if ($delayedExec) { + fhem('attr wdt_uzsu_'.$device.'_'.$i.' delayedExecutionCond '.$delayedExec); + } + } + #fhem('save'); # use only if you want to save WDT settings immediately. +} } + package fronthem; use strict; use warnings; From 420747335cfadfefb040079d49b7368b0be10772 Mon Sep 17 00:00:00 2001 From: Bernd Gewehr Date: Mon, 28 Mar 2016 13:01:34 +0200 Subject: [PATCH 8/9] Update 99_fronthemUtils.pm adopted for UZSU dev V4.6 --- FHEM/99_fronthemUtils.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/FHEM/99_fronthemUtils.pm b/FHEM/99_fronthemUtils.pm index c0d62b1..6a5735a 100644 --- a/FHEM/99_fronthemUtils.pm +++ b/FHEM/99_fronthemUtils.pm @@ -23,7 +23,7 @@ sub fronthem_encodejson($) { ############################################################################### # # Umsetzen der UZSU-Settings für ein device -# for use with UZSU widget V4.4 +# for use with UZSU widget V4.6 # ############################################################################### sub UZSU_execute($@) @@ -71,9 +71,9 @@ for(my $i=0; $i < @{$uzsu->{list}}; $i++) { # if the structure contains a condition, use it! if ($uzsu->{list}[$i]->{condition}->{active}) { - if ($uzsu->{list}[$i]->{condition}->{type} eq 'Perl') { + if ($uzsu->{list}[$i]->{condition}->{type} eq 'String') { Log 4, 'uzsu Perl-Condition\n'; - $perlString = trim($uzsu->{list}[$i]->{condition}->{devicePerl}); + $perlString = trim($uzsu->{list}[$i]->{condition}->{deviceString}); Log 4, 'uzsu ' . $perlString; #$perlString =~ s/\\"/"/ig; #Log 4, 'uzsu ' . $perlString; @@ -93,15 +93,15 @@ for(my $i=0; $i < @{$uzsu->{list}}; $i++) { Log 4, 'uzsu '.$weekdays.' '.$condition; } else { Log 4, 'uzsu non-Perl-Condition\n'; - $condition = ' (ReadingsVal("'.$uzsu->{list}[$i]->{condition}->{devicePerl}.'","state","") '.$uzsu->{list}[$i]->{condition}->{type}.' "'.$uzsu->{list}[$i]->{condition}->{value}.'")'; + $condition = ' (ReadingsVal("'.$uzsu->{list}[$i]->{condition}->{deviceString}.'","state","") '.$uzsu->{list}[$i]->{condition}->{type}.' "'.$uzsu->{list}[$i]->{condition}->{value}.'")'; } } # if the structure contains a delayedExec, use it! if ($uzsu->{list}[$i]->{delayedExec}->{active}) { - if ($uzsu->{list}[$i]->{delayedExec}->{type} eq 'Perl') { + if ($uzsu->{list}[$i]->{delayedExec}->{type} eq 'String') { Log 4, 'uzsu Perl-Condition\n'; - $perlString = trim($uzsu->{list}[$i]->{delayedExec}->{devicePerl}); + $perlString = trim($uzsu->{list}[$i]->{delayedExec}->{deviceString}); Log 4, 'uzsu ' . $perlString; #$perlString =~ s/\\"/"/ig; #Log 4, 'uzsu ' . $perlString; @@ -117,7 +117,7 @@ for(my $i=0; $i < @{$uzsu->{list}}; $i++) { #Log 4, 'uzsu ' , $delayedExec; } else { Log 4, 'uzsu non-Perl-Condition\n'; - $delayedExec = '{ (ReadingsVal("'.$uzsu->{list}[$i]->{delayedExec}->{devicePerl}.'","state","") '.$uzsu->{list}[$i]->{delayedExec}->{type}.' "'.$uzsu->{list}[$i]->{delayedExec}->{value}.'") }'; + $delayedExec = '{ (ReadingsVal("'.$uzsu->{list}[$i]->{delayedExec}->{deviceString}.'","state","") '.$uzsu->{list}[$i]->{delayedExec}->{type}.' "'.$uzsu->{list}[$i]->{delayedExec}->{value}.'") }'; } } From 2a6ba282c820e6ae02a5e6bd589499189f3e321f Mon Sep 17 00:00:00 2001 From: schnmi Date: Mon, 11 Apr 2016 18:58:25 +0200 Subject: [PATCH 9/9] Update 99_fronthemUtils.pm fix for uzsu widget 4.8 --- FHEM/99_fronthemUtils.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FHEM/99_fronthemUtils.pm b/FHEM/99_fronthemUtils.pm index 6a5735a..a02f688 100644 --- a/FHEM/99_fronthemUtils.pm +++ b/FHEM/99_fronthemUtils.pm @@ -51,7 +51,7 @@ for(my $i=0; $i < @{$uzsu->{list}}; $i++) { } $weekdays = $weekdays . '$we'; } - if ($uzsu->{list}[$i]->{holiday}->{work}) { + if ($uzsu->{list}[$i]->{holiday}->{workday}) { if ($weekdays ne '') { $weekdays = $weekdays . ','; }