feat(v4): confirm feedback with device reads
This commit is contained in:
@@ -10,9 +10,13 @@ namespace Belevo\EnelixEMS {
|
||||
function hrtime($asNumber=true) { return (int)($GLOBALS['mono']*1e9); }
|
||||
function IPS_SemaphoreEnter($key,$wait) { if (!empty($GLOBALS['locks'][$key])) return false;$GLOBALS['locks'][$key]=true;return true; }
|
||||
function IPS_SemaphoreLeave($key) { unset($GLOBALS['locks'][$key]); }
|
||||
function IPS_InstanceExists($id) { return isset($GLOBALS['objects'][$id]); }
|
||||
function IPS_GetInstance($id) { return ['InstanceStatus'=>$GLOBALS['objects'][$id]->ready?102:201,
|
||||
'ModuleInfo'=>['ModuleID'=>$id===44234?'{437FB683-517F-4FEC-8CCB-FE6B0A62B69E}':'{6F771B18-59D4-4C8A-B951-3B2FE9F6A2C4}']]; }
|
||||
function IPS_InstanceExists($id) { return $id===200 || isset($GLOBALS['objects'][$id]); }
|
||||
function IPS_GetInstance($id) {
|
||||
if ($id===200) return ['InstanceStatus'=>102,'ModuleInfo'=>['ModuleID'=>'{90BF9234-B44C-7EB3-280B-FBD6075ADDAA}']];
|
||||
return ['InstanceStatus'=>$GLOBALS['objects'][$id]->ready?102:201,
|
||||
'ModuleInfo'=>['ModuleID'=>$id===44234?'{437FB683-517F-4FEC-8CCB-FE6B0A62B69E}':'{6F771B18-59D4-4C8A-B951-3B2FE9F6A2C4}']];
|
||||
}
|
||||
function ModBus_RequestRead($id) { return $id===200 && ($GLOBALS['deviceReadOk']??true); }
|
||||
function IPS_GetProperty($id,$key) { return $GLOBALS['objects'][$id]->props[$key]; }
|
||||
function IPS_VariableExists($id) { return in_array($id,[50001,50002],true); }
|
||||
function IPS_GetVariable($id) { $t=$GLOBALS['feedbackAt'][$id]??$GLOBALS['clock'];return ['VariableUpdated'=>$t,'VariableChanged'=>$t]; }
|
||||
@@ -102,7 +106,7 @@ namespace {
|
||||
function check($ok,$name) { global $count;if (!$ok) throw new RuntimeException('FAIL '.$name);$count++;echo "PASS $name\n"; }
|
||||
function rejects(callable $call,$name) { try {$call();}catch(Throwable $e){check(true,$name);return;}throw new RuntimeException('FAIL did not reject '.$name); }
|
||||
function fixture($permissions=true,$serverAuthority=true): array {
|
||||
[$r,$id,$op,$now]=receiverFixture();$GLOBALS['clock']=$now;$GLOBALS['mono']=1000.;$GLOBALS['locks']=[];$GLOBALS['calls']=[];
|
||||
[$r,$id,$op,$now]=receiverFixture();$GLOBALS['clock']=$now;$GLOBALS['mono']=1000.;$GLOBALS['locks']=[];$GLOBALS['calls']=[];$GLOBALS['deviceReadOk']=true;
|
||||
$r['plan']['inputQuality']=['loadBasis'=>'base_load','accountingEvidenceId'=>'synthetic-meter-boundary-v1'];
|
||||
$r['plan']['peakCostIsEstimate']=true;
|
||||
$a=['kind'=>'controlled_trial_authority','version'=>1,'sourcePlanRemainsShadow'=>true,
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// Run through actual Manager/Battery trial traits, fresh read helper, and simulated register driver.
|
||||
[$m,$b,$s]=fixture();$b->props['NetzfahrplanV4RueckmeldungKonfiguration']='{}';
|
||||
rejects(fn()=>start($m,$s),'trial cannot use old filtered feedback when mapping missing');check($b->writes===[],'missing corrected feedback sends no command');
|
||||
[$m,$b,$s]=fixture();start($m,$s);tick($m);$feedbackAt[50002]=$clock-61;
|
||||
$a=tick($m);check(!$m->active()&&!$b->active()&&isset($a['Sollwerte'][44234]),'physical feedback expiry returns battery to normal allocation');
|
||||
check(end($b->writes)===0,'expired physical feedback revokes prior command');
|
||||
[$m,$b,$s]=fixture();start($m,$s);tick($m);$feedbackAt[50002]=$clock-61;$b->watchdog();
|
||||
check(!$b->active()&&end($b->writes)===0,'independent battery read catches staleness without manager tick');
|
||||
[$m,$b,$s]=fixture();start($m,$s);tick($m);$deviceReadOk=false;
|
||||
$a=tick($m);check(!$m->active()&&!$b->active()&&isset($a['Sollwerte'][44234]),'failed confirmed read returns battery to normal allocation');
|
||||
check(end($b->writes)===0,'failed confirmed read revokes prior command');
|
||||
[$m,$b,$s]=fixture();start($m,$s);tick($m);$deviceReadOk=false;$b->watchdog();
|
||||
check(!$b->active()&&end($b->writes)===0,'independent battery read catches device failure without manager tick');
|
||||
[$m,$b,$s]=fixture();start($m,$s);tick($m);$c=json_decode($b->props['NetzfahrplanV4RueckmeldungKonfiguration'],true);$c['trackingToleranceW']=250;
|
||||
$b->props['NetzfahrplanV4RueckmeldungKonfiguration']=json_encode($c);$b->watchdog();
|
||||
check(!$b->active()&&end($b->writes)===0,'mapping revision change revokes active battery session');
|
||||
|
||||
Reference in New Issue
Block a user