diff --git a/fhem/contrib/AutomowerConnect/Common.pm b/fhem/contrib/AutomowerConnect/Common.pm index fe87d2211..064af6570 100644 --- a/fhem/contrib/AutomowerConnect/Common.pm +++ b/fhem/contrib/AutomowerConnect/Common.pm @@ -25,7 +25,7 @@ ################################################################################ package FHEM::Devices::AMConnect::Common; -my $cvsid = '$Id: Common.pm 28823b 2024-04-26 13:14:53Z Ellert $'; +my $cvsid = '$Id: Common.pm 28823c 2024-04-26 13:14:53Z Ellert $'; use strict; use warnings; use POSIX; @@ -1207,7 +1207,7 @@ sub Set { my $calendarjson = eval { require JSON::PP; - my %ORDER=(start=>1,duration=>2,monday=>3,tuesday=>4,wednesday=>5,thursday=>6,friday=>7,saturday=>8,sunday=>9); + my %ORDER=(start=>1,duration=>2,monday=>3,tuesday=>4,wednesday=>5,thursday=>6,friday=>7,saturday=>8,sunday=>9,workAreaId=>10); JSON::PP->new->sort_by( sub {($ORDER{$JSON::PP::a} // 999) <=> ($ORDER{$JSON::PP::b} // 999) or $JSON::PP::a cmp $JSON::PP::b}) ->pretty(1)->utf8( not $unicodeEncoding )->encode( $hash->{helper}{mower}{attributes}{calendar}{tasks} ) @@ -1289,7 +1289,7 @@ sub Set { return "$iam decode error: $@ \n $setVal" if ($@); $calendarjson = eval { require JSON::PP; - my %ORDER=(start=>1,duration=>2,monday=>3,tuesday=>4,wednesday=>5,thursday=>6,friday=>7,saturday=>8,sunday=>9); + my %ORDER=(start=>1,duration=>2,monday=>3,tuesday=>4,wednesday=>5,thursday=>6,friday=>7,saturday=>8,sunday=>9,workAreaId=>10); JSON::PP->new->sort_by( sub {($ORDER{$JSON::PP::a} // 999) <=> ($ORDER{$JSON::PP::b} // 999) or $JSON::PP::a cmp $JSON::PP::b}) ->pretty(1)->utf8( not $unicodeEncoding )->encode( $calendarjson ) @@ -1801,7 +1801,7 @@ sub Attr { $attrVal = eval { require JSON::PP; - my %ORDER=(start=>1,duration=>2,monday=>3,tuesday=>4,wednesday=>5,thursday=>6,friday=>7,saturday=>8,sunday=>9); + my %ORDER=(start=>1,duration=>2,monday=>3,tuesday=>4,wednesday=>5,thursday=>6,friday=>7,saturday=>8,sunday=>9,workAreaId=>10); JSON::PP->new->sort_by( sub {($ORDER{$JSON::PP::a} // 999) <=> ($ORDER{$JSON::PP::b} // 999) or $JSON::PP::a cmp $JSON::PP::b}) ->pretty(1)->encode( $perl ) @@ -2908,7 +2908,7 @@ sub getDefaultScheduleAsJSON { my $hash = $defs{$name}; my $json = eval { require JSON::PP; - my %ORDER=(start=>1,duration=>2,monday=>3,tuesday=>4,wednesday=>5,thursday=>6,friday=>7,saturday=>8,sunday=>9); + my %ORDER=(start=>1,duration=>2,monday=>3,tuesday=>4,wednesday=>5,thursday=>6,friday=>7,saturday=>8,sunday=>9,workAreaId=>10); JSON::PP->new->sort_by( sub {($ORDER{$JSON::PP::a} // 999) <=> ($ORDER{$JSON::PP::b} // 999) or $JSON::PP::a cmp $JSON::PP::b}) ->utf8( not $unicodeEncoding )->encode( $hash->{helper}{mower}{attributes}{calendar}{tasks} ) diff --git a/fhem/contrib/AutomowerConnect/automowerconnect.js b/fhem/contrib/AutomowerConnect/automowerconnect.js index d43def22e..bba42d35a 100644 --- a/fhem/contrib/AutomowerConnect/automowerconnect.js +++ b/fhem/contrib/AutomowerConnect/automowerconnect.js @@ -1,6 +1,6 @@ if ( !(typeof FW_version === 'undefined') ) - FW_version["automowerconnect.js"] = "$Id: automowerconnect.js 28823a 2024-04-26 13:14:53Z Ellert $"; + FW_version["automowerconnect.js"] = "$Id: automowerconnect.js 28823c 2024-04-26 13:14:53Z Ellert $"; { window.onload = ( ()=>{ let room = document.querySelector("#content"); @@ -481,13 +481,20 @@ function AutomowerConnectPanelCmd ( panelcmd ) { FW_cmd( FW_root+"?cmd="+panelcmd+"&XHR=1" ); } -function AutomowerConnectHandleInput ( dev ) { +function AutomowerConnectHandleInput ( dev, hasWorkAreaId, workAreaId ) { let cal = JSON.parse( document.querySelector( '#amc_'+dev+'_schedule_div' ).getAttribute( 'data-amc_schedule' ) ); let cali = document.querySelector('#amc_'+dev+'_index').value || cal.length; if ( cali > cal.length ) cali = cal.length; if ( cali > 13 ) cali = 13; + - for (let i=cal.length;i<=cali;i++) { cal.push( { "start":0, "duration":1439, "monday":false, "tuesday":false, "wednesday":false, "thursday":false, "friday":false, "saturday":false, "sunday":false } ) } + for (let i=cal.length;i<=cali;i++) { + if ( hasWorkAreaId ) { + cal.push( { "start":0, "duration":1439, "monday":false, "tuesday":false, "wednesday":false, "thursday":false, "friday":false, "saturday":false, "sunday":false, "workAreaId":workAreaId } ) + } else { + cal.push( { "start":0, "duration":1439, "monday":false, "tuesday":false, "wednesday":false, "thursday":false, "friday":false, "saturday":false, "sunday":false } ) + } + } //~ console.log('cali: '+cali+' cal.length: '+cal.length); let elements = ["start", "duration"]; @@ -498,7 +505,7 @@ function AutomowerConnectHandleInput ( dev ) { if ( isNaN( hour ) && item == "start" ) hour = 0; if ( isNaN( min ) && item == "start" ) min = 0; - if ( isNaN( hour ) && item == "duration" ) hour = 23; + if ( isNaN( hour ) && item == "duration" ) hour = 23*60; if ( isNaN( min ) && item == "duration" ) min = 59; cal[cali][item] = hour + min; @@ -547,7 +554,11 @@ function AutomowerConnectHandleInput ( dev ) { if ( cali > cal.length -1 ) cali = cal.length -1; if ( !cal[cali] ) { - cal = [ { "start":0, "duration":1440, "monday":true, "tuesday":true, "wednesday":true, "thursday":true, "friday":true, "saturday":true, "sunday":true } ]; + if ( hasWorkAreaId ) { + cal = [ { "start":0, "duration":1440, "monday":true, "tuesday":true, "wednesday":true, "thursday":true, "friday":true, "saturday":true, "sunday":true, "workAreaId":workAreaId } ]; + } else { + cal = [ { "start":0, "duration":1440, "monday":true, "tuesday":true, "wednesday":true, "thursday":true, "friday":true, "saturday":true, "sunday":true } ]; + } cali = 0; } @@ -557,8 +568,11 @@ function AutomowerConnectHandleInput ( dev ) { shdl += ""; - shdl += ""; + shdl += "
"; + //~ if ( hasWorkAreaId ) shdl += ""; + if ( hasWorkAreaId ) shdl += ""; shdl += ""; + shdl += ""; shdl += ""; shdl += ""; shdl += ""; @@ -570,7 +584,7 @@ function AutomowerConnectHandleInput ( dev ) { shdl += ""; shdl += ""; shdl += ""; - shdl += ""; + shdl += ""; shdl += ""; for (let i=0; i< cal.length; i++){ @@ -584,13 +598,15 @@ function AutomowerConnectHandleInput ( dev ) { shdl += ""; shdl += ""; shdl += ""; - shdl += ""; + shdl += ""; + if ( hasWorkAreaId ) shdl += ""; + shdl += ""; shdl += ""; } shdl += ""; - let nrows = cal.length*11+2; - shdl += ""; + let nrows = cal.length*(hasWorkAreaId?12:11)+2; + shdl += ""; shdl += ""; shdl += "
Calendar for Work Area Id: "+workAreaId+"
IndexStartDurationMon.Tue.Wed.Thu.Fri.Sat.Sun.
 "+(cal[i].thursday?"☑":"☐")+" "+(cal[i].friday?"☑":"☐")+" "+(cal[i].saturday?"☑":"☐")+" "+(cal[i].sunday?"☑":"☐")+" "+(cal[i].sunday?"☑":"☐")+" "+workAreaId+"
"; shdl += ""; @@ -606,17 +622,27 @@ function AutomowerConnectSchedule ( dev ) { let el = document.getElementById('amc_'+dev+'_schedule_div'); if ( el ) el.remove(); + let hasWorkAreaId = false; + let workAreaId = null; + FW_cmd( FW_root+"?cmd={ FHEM::Devices::AMConnect::Common::getDefaultScheduleAsJSON( \""+dev+"\" ) }&XHR=1",( cal ) => { cal = JSON.parse( cal ); - if (cal.length == 0) cal = [ { "start":0, "duration":1440, "monday":true, "tuesday":true, "wednesday":true, "thursday":true, "friday":true, "saturday":true, "sunday":true } ]; + if ( cal.length == 0 ) cal = [ { "start":0, "duration":1440, "monday":true, "tuesday":true, "wednesday":true, "thursday":true, "friday":true, "saturday":true, "sunday":true } ]; + if ( cal[0].workAreaId != null ) { + hasWorkAreaId = true; + workAreaId = cal[0].workAreaId + } let cali = 0; let shdl = "
"; shdl += ""; - shdl += ""; - shdl += ""; + shdl += "
IndexStartDurationMon.Tue.Wed.Thu.Fri.Sat.Sun.
"; + //~ if ( hasWorkAreaId ) shdl += ""; + if ( hasWorkAreaId ) shdl += ""; + shdl += ""; + shdl += ""; shdl += ""; shdl += ""; shdl += ""; @@ -628,7 +654,7 @@ function AutomowerConnectSchedule ( dev ) { shdl += ""; shdl += ""; shdl += ""; - shdl += ""; + shdl += ""; shdl += ""; for (let i=0; i< cal.length; i++){ @@ -642,18 +668,19 @@ function AutomowerConnectSchedule ( dev ) { shdl += ""; shdl += ""; shdl += ""; - shdl += ""; + shdl += ""; + shdl += ""; shdl += ""; } shdl += ""; - let nrows = cal.length*11+2; - shdl += ""; + let nrows = cal.length*(hasWorkAreaId?12:11)+2; + shdl += ""; shdl += ""; shdl += "
Calendar for Work Area Id: "+workAreaId+"
IndexStartDurationMon.Tue.Wed.Thu.Fri.Sat.Sun.
 "+(cal[i].thursday?"☑":"☐")+" "+(cal[i].friday?"☑":"☐")+" "+(cal[i].saturday?"☑":"☐")+" "+(cal[i].sunday?"☑":"☐")+" "+(cal[i].sunday?"☑":"☐")+"
"; shdl += "
"; let schedule = new DOMParser().parseFromString( shdl, "text/html" ).querySelector( '#amc_'+dev+'_schedule_div' ); document.querySelector('body').append( schedule ); - document.querySelector( "#amc_"+dev+"_schedule_button_plus" ).setAttribute( "onclick", "AutomowerConnectHandleInput( '"+dev+"' )" ); + document.querySelector( "#amc_"+dev+"_schedule_button_plus" ).setAttribute( "onclick", "AutomowerConnectHandleInput( '"+dev+"', '"+hasWorkAreaId+"', '"+workAreaId+"' )" ); $(schedule).dialog({ dialogClass:"no-close", modal:true, width:"auto", closeOnEscape:true,