()
| 15522 | except Exception as exc: # noqa: BLE001 |
| 15523 | logger.warning(f"[cellular] module unavailable: {exc}") |
| 15524 | return |
| 15525 | _cellular_monitor = cellular_uplink.Monitor(log=logger) |
| 15526 | try: |
| 15527 | # Self-provision the NM/dhcpcd hooks so web-updated boxes get them too. |
| 15528 | for change in cellular_uplink.install(shared_data.config): |
| 15529 | logger.info(f"[cellular] {change}") |
| 15530 | except Exception as exc: # noqa: BLE001 |
| 15531 | logger.warning(f"[cellular] hook install failed: {exc}") |
| 15532 | while not getattr(shared_data, 'webapp_should_exit', False): |
| 15533 | try: |
| 15534 | for t in _cellular_monitor.tick(shared_data.config): |
| 15535 | po = _rusense_pushover() |
| 15536 | if po: |
| 15537 | po.notify_cellular_uplink(t['msg'], priority=t.get('priority', 0)) |
| 15538 | except Exception as exc: # noqa: BLE001 |
| 15539 | logger.debug(f"[cellular] tick failed: {exc}") |
| 15540 | time.sleep(10) |
| 15541 | |
| 15542 | |
| 15543 | @app.route('/api/cellular/status', methods=['GET']) |
| 15544 | def api_cellular_status(): |
| 15545 | try: |
| 15546 | import cellular_uplink |
| 15547 | data = cellular_uplink.status(shared_data.config) |
| 15548 | data['events'] = list(_cellular_monitor.events[-20:]) if _cellular_monitor else [] |
| 15549 | data['heartbeat'] = _cellular_monitor.snapshot() if _cellular_monitor else None |
| 15550 | return jsonify(data) |
| 15551 | except Exception as e: |
| 15552 | logger.error(f"Cellular status error: {e}") |
| 15553 | return jsonify({'success': False, 'error': str(e)}), 500 |
| 15554 | |
| 15555 | |
| 15556 | @app.route('/api/cellular/settings', methods=['POST']) |
| 15557 | def api_cellular_settings(): |
| 15558 | try: |
| 15559 | import cellular_uplink |
| 15560 | body = request.get_json(silent=True) or {} |
| 15561 | cfg = shared_data.config |
| 15562 | if 'enabled' in body: |
| 15563 | cfg['cellular_fallback_enabled'] = bool(body['enabled']) |
| 15564 | if 'allow_scan' in body: |
| 15565 | cfg['cellular_allow_scan'] = bool(body['allow_scan']) |
| 15566 | if 'metric' in body: |
| 15567 | try: |
| 15568 | metric = int(body['metric']) |
| 15569 | except (TypeError, ValueError): |
| 15570 | return jsonify({'success': False, 'error': 'metric must be a number'}), 400 |
| 15571 | if not 1000 <= metric <= 65535: |
| 15572 | return jsonify({'success': False, 'error': 'metric must be 1000-65535'}), 400 |
| 15573 | cfg['cellular_route_metric'] = metric |
| 15574 | for key in ('force_ifaces', 'exclude_ifaces'): |
| 15575 | if key in body: |
| 15576 | names = cellular_uplink._split_list(body[key]) |
| 15577 | cfg[f'cellular_{key}'] = ' '.join(sorted(names)) |
| 15578 | if 'heartbeat_enabled' in body: |
| 15579 | cfg['cellular_heartbeat_enabled'] = bool(body['heartbeat_enabled']) |
| 15580 | if 'heartbeat_targets' in body: |
| 15581 | targets = cellular_uplink.parse_targets(body['heartbeat_targets']) |
nothing calls this directly
no test coverage detected