"""Read-only battery/resource HTTP checks. Never starts or connects physical devices.""" import json from verify_cmvr_native import Client,TargetReadOnlyDb,ROOT,require def main(): c=Client().login();db=TargetReadOnlyDb(c) def snapshot():return {table:db.select('SELECT COUNT(*) n FROM '+table)[0]['n'] for table in ('lab_scanner_command','te_task_inst','lab_resource_occupation')} before=snapshot();config=c.native('GET','/scanner/configuration')['data'] raw=c.native('GET','/scanner/device/battery',expected=None) result=c.native('GET','/resource/robots',query={'pageNum':1,'pageSize':1000}) target=next((r for r in result['rows'] if r['robotId']==config['robotId']),None) require(target is not None,'Configured scanner station missing') battery=target.get('scannerBattery');require(isinstance(battery,dict),'Scanner resource has no battery payload') require('scanner' in battery and 'channels' in battery['tracker'],'Battery channels missing') readings=[battery['scanner']]+battery['tracker']['channels'] for row in readings: if row.get('available'): require(row.get('fresh') is True and isinstance(row.get('percent'),int) and not isinstance(row['percent'],bool) and 0<=row['percent']<=100,'Invalid current battery displayed') else:require(row.get('percent') is None,'Unknown battery became a number') require(target.get('batteryLevel')==battery['scanner'].get('percent'),'Scanner overview differs from dedicated reading') other=[r for r in result['rows'] if r['robotId']!=config['robotId']] require(all(r.get('scannerBattery') is None for r in other),'Scanner battery leaked onto another robot') require(snapshot()==before,'Battery reads created task or occupation') report={'passed':True,'batteryEndpointCode':raw.get('code'),'resourceRobotId':config['robotId'],'resourceBattery':battery,'otherRobotsPreserved':len(other),'deviceControlRequests':0,'businessRowsUnchanged':True} (ROOT/'.local/scanner-battery-http.json').write_text(json.dumps(report,ensure_ascii=False,indent=2),encoding='utf-8') db.close();print(json.dumps({'passed':True,'batteryEndpointCode':raw.get('code'),'readings':len(readings),'otherRobotsPreserved':len(other),'deviceControlRequests':0})) if raw.get('code')!=200:print('Scanner service has not exposed the new battery endpoint successfully; resource safely displays unavailable.') if __name__=='__main__':main()