feat(iot): repackaged Odoo iot modules + Fusion Plating sensor wrapper

Phase A of the IoT initiative — gets the server-side infrastructure
in place before the Raspberry Pi hardware arrives, so the iot admin
UI + /fp/iot/ingest endpoint are ready to accept the first real
temperature reading as soon as the Pi is wired up.

New top-level folder: fusion_iot/

1. **iot_base/** — Odoo S.A. iot_base module, copied from
   RePackaged-Odoo verbatim. LGPL-3 upstream, no changes needed.

2. **iot/** — Odoo S.A. iot module, repackaged:
   - `models/update.py` neutralised (removed the publisher_warranty
     IoT-Box-counting report that phones home to odoo.com for
     enterprise licence enforcement)
   - `iot_handlers/lib/load_worldline_library.sh` deleted (proprietary
     Worldline payment lib fetch from download.odoo.com, not needed)
   - `wizard/add_iot_box.py._connect_iot_box_with_pairing_code` —
     upstream called odoo.com's iot-proxy to resolve pairing codes;
     replaced with a no-op. Pi-side iot_drivers proxy registers
     directly with this Odoo server instead.
   - Manifest rebranded with an explicit changelog preamble.

3. **fusion_plating_iot/** — new plating-specific wrapper:
   - `fp.tank.sensor` — maps an iot.device (or a direct-HTTP-ingest
     sensor) to a fusion.plating.tank + fusion.plating.bath.parameter.
     Supports DS18B20, PT100/1000, pH, conductivity, level. Per-sensor
     alert_min/max overrides.
   - `fp.tank.reading` — append-only time-series. On create, evaluates
     against sensor's alert range. On in-spec → out-of-spec TRANSITION,
     auto-raises a fusion.plating.quality.hold (once per excursion,
     no spam during sustained out-of-spec).
   - `POST /fp/iot/ingest` — shared-secret HTTP endpoint for sensors
     bypassing the Pi proxy. Token via X-FP-IOT-Token header OR body.
     Accepts single-reading or batch payloads.
   - Menu under Plating → Operations → Sensors & Readings.
   - Tank form inherits get a Sensors tab inline.

Deployed to entech. Verified end-to-end:
- Install: iot_base + iot + fusion_plating_iot all 'installed'
- Smoke test: in-spec → out-of-spec → hold raised (HOLD-0010);
  continued excursion → NO duplicate hold; back-in-spec → NEW
  excursion → NEW hold (HOLD-0011) ✓
- HTTP endpoint: correct token → 200 accepted; wrong token → 401;
  unknown device_serial → 404; batch payload → 200 accepted=N ✓

Phase B (when Raspberry Pi hardware arrives): DS18B20 iot_handler
driver for the Pi-side iot_drivers proxy + systemd service on
vanilla Raspberry Pi OS + first live reading from physical probe.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-04-19 10:46:45 -04:00
parent c118b7c6b5
commit 6e964c230f
419 changed files with 76449 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
import { browser } from "@web/core/browser/browser";
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";
import { standardActionServiceProps } from "@web/webclient/actions/action_service";
import { Component, onWillStart, useState } from "@odoo/owl";
export const IOT_REPORT_PREFERENCE_LOCAL_STORAGE_KEY = "odoo-iot-linked_reports";
export function removeIoTReportIdFromBrowserLocalStorage(report_id) {
const links = JSON.parse(browser.localStorage.getItem(IOT_REPORT_PREFERENCE_LOCAL_STORAGE_KEY));
delete links[report_id];
if (Object.keys(links).length === 0) {
// If the list is empty, remove the entry
browser.localStorage.removeItem(IOT_REPORT_PREFERENCE_LOCAL_STORAGE_KEY);
} else {
// Replace the entry in LocalStorage by the same object with the key 'report_id' removed
browser.localStorage.setItem(
IOT_REPORT_PREFERENCE_LOCAL_STORAGE_KEY,
JSON.stringify(links)
);
}
}
/**
* Set the report_id in the browser LocalStorage
* @param report_id The report_id to set
* @param value The value to set
*/
export function setReportIdInBrowserLocalStorage(report_id, value) {
let links = JSON.parse(browser.localStorage.getItem(IOT_REPORT_PREFERENCE_LOCAL_STORAGE_KEY));
if (links === null || typeof links !== "object") {
links = {};
}
links[report_id] = value;
browser.localStorage.setItem(IOT_REPORT_PREFERENCE_LOCAL_STORAGE_KEY, JSON.stringify(links));
}
class IoTReportLocalStorage extends Component {
static template = "iot.delete_printer";
static props = { ...standardActionServiceProps };
setup() {
const links = JSON.parse(browser.localStorage.getItem(IOT_REPORT_PREFERENCE_LOCAL_STORAGE_KEY));
this.state = useState({ reportList: (links ? Object.keys(links) : []) });
this.orm = useService("orm");
onWillStart(async () => {
this.state.reportList = await this.orm.searchRead("ir.actions.report", [
["id", "in", this.state.reportList],
]);
});
}
removeFromLocal(event, id) {
removeIoTReportIdFromBrowserLocalStorage(id);
this.state.reportList = this.state.reportList.filter((report) => report.id !== id);
}
}
registry.category("actions").add("iot_delete_linked_devices_action", IoTReportLocalStorage);

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="iot.delete_printer">
<div class="container mt-4">
<h2>Reports with linked printers</h2>
<div class="mt-3">
<p t-if="!state.reportList.length">No report to display</p>
<div class="card mb-3" t-foreach="state.reportList" t-as="item" t-key="item.id">
<div class="card-body d-flex justify-content-between align-items-center">
<h5 class="card-title m-0" t-out="item.name" />
<button class="btn btn-primary" t-on-click="(ev) => this.removeFromLocal(ev, item.id)">Reset Linked Printers</button>
</div>
</div>
</div>
</div>
</t>
</templates>

View File

@@ -0,0 +1,21 @@
import { rpc } from "@web/core/network/rpc";
import { registry } from "@web/core/registry";
const IOT_PROXY_DISCOVER_BOXES_ENDPOINT =
"";
export async function discoverIotBoxes(env) {
const orm = env.services.orm;
const discoveredBoxes = [];
try {
const response = await rpc(IOT_PROXY_DISCOVER_BOXES_ENDPOINT);
discoveredBoxes.push(...response);
} catch (error) {
console.warn("Failed to retrieve local IoT boxes: " + error);
}
return orm.call("iot.box", "connect_iot_box", [discoveredBoxes]);
}
registry.category("actions").add("discover_iot_boxes", discoverIotBoxes);