whitebox-plugin-device-status 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,35 @@
1
+ import { useEffect } from "react";
2
+ import useDevicesStore from "./stores/devices";
3
+ const { importWhiteboxComponent } = Whitebox;
4
+
5
+ const DeviceConnection = importWhiteboxComponent(
6
+ "device-wizard.device-connection"
7
+ );
8
+
9
+ const GPSStatus = () => {
10
+ const gpsConnected = useDevicesStore((state) => state.gpsConnected);
11
+ const gpsSolution = useDevicesStore((state) => state.gpsSolution);
12
+ const gpsAccuracy = useDevicesStore((state) => state.gpsAccuracy);
13
+ const updateGPSStatus = useDevicesStore((state) => state.updateGPSStatus);
14
+
15
+ useEffect(() => {
16
+ return Whitebox.sockets.addEventListener("flight", "message", (event) => {
17
+ const data = JSON.parse(event.data);
18
+ if (data.type === "status_update") {
19
+ updateGPSStatus({ data });
20
+ }
21
+ });
22
+ });
23
+
24
+ const getDeviceName = () => {
25
+ if (!gpsConnected) return "GPS - " + gpsSolution;
26
+ return `GPS - ${gpsSolution}, ${gpsAccuracy.toFixed(2)}m`;
27
+ };
28
+
29
+ return (
30
+ <DeviceConnection deviceName={getDeviceName()} isConnected={gpsConnected} />
31
+ );
32
+ };
33
+
34
+ export { GPSStatus };
35
+ export default GPSStatus;
@@ -0,0 +1,96 @@
1
+ import { act, render, screen, cleanup } from "@testing-library/react";
2
+ import { GPSStatus } from "./GPSStatus";
3
+
4
+ afterEach(cleanup);
5
+
6
+ describe("GPSStatus Component", () => {
7
+ let messageHandler;
8
+
9
+ beforeAll(() => {
10
+ // Mock Whitebox.sockets
11
+ window.Whitebox = {
12
+ sockets: {
13
+ addEventListener: vi.fn((channel, type, handler) => {
14
+ if (channel === "flight" && type === "message") {
15
+ messageHandler = handler;
16
+ }
17
+ }),
18
+ removeEventListener: vi.fn(),
19
+ },
20
+ };
21
+ });
22
+
23
+ it("renders without crashing", () => {
24
+ render(<GPSStatus />);
25
+ expect(screen.getByText("GPS - Not communicating")).toBeInTheDocument();
26
+ });
27
+
28
+ it("displays GPS connection status", () => {
29
+ render(<GPSStatus />);
30
+ expect(screen.getByText("GPS - Not communicating")).toBeInTheDocument();
31
+
32
+ act(() => {
33
+ // Simulate receiving a message
34
+ messageHandler({
35
+ data: JSON.stringify({
36
+ type: "status_update",
37
+ GPS_connected: true,
38
+ GPS_solution: "3D GPS + SBAS",
39
+ GPS_position_accuracy: 5.0,
40
+ }),
41
+ });
42
+ });
43
+
44
+ expect(screen.getByText("GPS - 3D GPS + SBAS, 5.00m")).toBeInTheDocument();
45
+ });
46
+
47
+ it("updates GPS status on new messages", () => {
48
+ render(<GPSStatus />);
49
+
50
+ act(() => {
51
+ // First message
52
+ messageHandler({
53
+ data: JSON.stringify({
54
+ type: "status_update",
55
+ GPS_connected: true,
56
+ GPS_solution: "3D GPS + SBAS",
57
+ GPS_position_accuracy: 5.0,
58
+ }),
59
+ });
60
+ });
61
+
62
+ expect(screen.getByText("GPS - 3D GPS + SBAS, 5.00m")).toBeInTheDocument();
63
+
64
+ act(() => {
65
+ // Second message with different data
66
+ messageHandler({
67
+ data: JSON.stringify({
68
+ type: "status_update",
69
+ GPS_connected: true,
70
+ GPS_solution: "2D GPS",
71
+ GPS_position_accuracy: 10.0,
72
+ }),
73
+ });
74
+ });
75
+
76
+ expect(screen.getByText("GPS - 2D GPS, 10.00m")).toBeInTheDocument();
77
+ });
78
+
79
+ it("handles GPS disconnection", () => {
80
+ render(<GPSStatus />);
81
+
82
+ act(() => {
83
+ // Simulate GPS disconnection
84
+ messageHandler({
85
+ data: JSON.stringify({
86
+ type: "status_update",
87
+ GPS_connected: false,
88
+ GPS_solution: "Not communicating",
89
+ GPS_position_accuracy: 0.0,
90
+ }),
91
+ });
92
+ });
93
+
94
+ expect(screen.getByText("GPS - Not communicating")).toBeInTheDocument();
95
+ });
96
+ });
@@ -0,0 +1,36 @@
1
+ import { useEffect } from "react";
2
+ import useDevicesStore from "./stores/devices";
3
+ const { importWhiteboxComponent } = Whitebox;
4
+
5
+ const DeviceConnection = importWhiteboxComponent(
6
+ "device-wizard.device-connection"
7
+ );
8
+
9
+ const SDRStatus = () => {
10
+ const sdrDeviceCount = useDevicesStore((state) => state.sdrDeviceCount);
11
+ const updateStatus = useDevicesStore((state) => state.updateSDRStatus);
12
+
13
+ useEffect(() => {
14
+ return Whitebox.sockets.addEventListener("flight", "message", (event) => {
15
+ const data = JSON.parse(event.data);
16
+ if (data.type === "status_update") {
17
+ updateStatus({ data });
18
+ }
19
+ });
20
+ });
21
+
22
+ return (
23
+ <>
24
+ {Array.from({ length: sdrDeviceCount }, (_, index) => (
25
+ <DeviceConnection
26
+ key={index}
27
+ deviceName={`SDR #${index + 1}`}
28
+ isConnected
29
+ />
30
+ ))}
31
+ </>
32
+ );
33
+ };
34
+
35
+ export { SDRStatus };
36
+ export default SDRStatus;
@@ -0,0 +1,78 @@
1
+ import { act, render, screen, cleanup } from "@testing-library/react";
2
+ import { SDRStatus } from "./SDRStatus";
3
+
4
+ afterEach(cleanup);
5
+
6
+ describe("SDRStatus Component", () => {
7
+ let messageHandler;
8
+
9
+ beforeAll(() => {
10
+ // Mock Whitebox.sockets
11
+ window.Whitebox = {
12
+ sockets: {
13
+ addEventListener: vi.fn((channel, type, handler) => {
14
+ if (channel === "flight" && type === "message") {
15
+ messageHandler = handler;
16
+ }
17
+ }),
18
+ removeEventListener: vi.fn(),
19
+ },
20
+ };
21
+ });
22
+
23
+ it("renders nothing when no SDR devices found", () => {
24
+ render(<SDRStatus />);
25
+ expect(screen.queryByText("SDR #1")).not.toBeInTheDocument();
26
+ });
27
+
28
+ it("renders SDR devices when count is greater than 0", () => {
29
+ render(<SDRStatus />);
30
+ expect(screen.queryByText("SDR #1")).not.toBeInTheDocument();
31
+
32
+ act(() => {
33
+ // Simulate receiving a message
34
+ messageHandler({
35
+ data: JSON.stringify({
36
+ type: "status_update",
37
+ Devices: "2", // Simulate 2 SDR devices
38
+ }),
39
+ });
40
+ });
41
+
42
+ expect(screen.getByText("SDR #1")).toBeInTheDocument();
43
+ expect(screen.getByText("SDR #2")).toBeInTheDocument();
44
+ });
45
+
46
+ it("updates SDR device count on new messages", () => {
47
+ render(<SDRStatus />);
48
+ expect(screen.queryByText("SDR #1")).not.toBeInTheDocument();
49
+
50
+ act(() => {
51
+ // Simulate receiving a message
52
+ messageHandler({
53
+ data: JSON.stringify({
54
+ type: "status_update",
55
+ Devices: "3",
56
+ }),
57
+ });
58
+ });
59
+
60
+ expect(screen.getByText("SDR #1")).toBeInTheDocument();
61
+ expect(screen.getByText("SDR #2")).toBeInTheDocument();
62
+ expect(screen.getByText("SDR #3")).toBeInTheDocument();
63
+
64
+ act(() => {
65
+ // Simulate receiving another message with a different count
66
+ messageHandler({
67
+ data: JSON.stringify({
68
+ type: "status_update",
69
+ Devices: "1", // Simulate 1 SDR device
70
+ }),
71
+ });
72
+ });
73
+
74
+ expect(screen.getByText("SDR #1")).toBeInTheDocument();
75
+ expect(screen.queryByText("SDR #2")).not.toBeInTheDocument();
76
+ expect(screen.queryByText("SDR #3")).not.toBeInTheDocument();
77
+ });
78
+ });
@@ -0,0 +1,33 @@
1
+ import { create } from "zustand";
2
+
3
+ const createSDRDeviceSlice = (set) => ({
4
+ sdrDeviceCount: 0,
5
+
6
+ updateSDRStatus({ data }) {
7
+ const numDevices = parseInt(data.Devices);
8
+ set({ sdrDeviceCount: numDevices });
9
+ },
10
+ });
11
+
12
+ const createGPSDeviceSlice = (set) => ({
13
+ gpsConnected: false,
14
+ gpsSolution: "Not communicating",
15
+ gpsAccuracy: 0,
16
+
17
+ updateGPSStatus({ data }) {
18
+ const gpsConnected = data.GPS_connected === true;
19
+ const gpsSolution = data.GPS_solution;
20
+ const gpsAccuracy = data.GPS_position_accuracy;
21
+
22
+ set({ gpsConnected });
23
+ set({ gpsSolution });
24
+ set({ gpsAccuracy });
25
+ },
26
+ });
27
+
28
+ const useDevicesStore = create((...a) => ({
29
+ ...createSDRDeviceSlice(...a),
30
+ ...createGPSDeviceSlice(...a),
31
+ }));
32
+
33
+ export default useDevicesStore;
@@ -0,0 +1,91 @@
1
+ import useDevicesStore from "./devices";
2
+
3
+ describe("useDevicesStore", () => {
4
+ beforeEach(() => {
5
+ // Reset store to initial state before each test
6
+ useDevicesStore.setState({
7
+ sdrDeviceCount: 0,
8
+ gpsConnected: false,
9
+ gpsSolution: "Not communicating",
10
+ gpsAccuracy: 0,
11
+ });
12
+ });
13
+
14
+ describe("Initial State", () => {
15
+ test("should have correct initial state", () => {
16
+ const state = useDevicesStore.getState();
17
+
18
+ expect(state.sdrDeviceCount).toBe(0);
19
+ expect(state.gpsConnected).toBe(false);
20
+ expect(state.gpsSolution).toBe("Not communicating");
21
+ expect(state.gpsAccuracy).toBe(0);
22
+ });
23
+
24
+ test("should have all required methods", () => {
25
+ const state = useDevicesStore.getState();
26
+
27
+ expect(typeof state.updateSDRStatus).toBe("function");
28
+ expect(typeof state.updateGPSStatus).toBe("function");
29
+ });
30
+ });
31
+
32
+ describe("SDR Device Slice", () => {
33
+ describe("updateSDRStatus", () => {
34
+ test("should update SDR device count with valid number", () => {
35
+ const { updateSDRStatus } = useDevicesStore.getState();
36
+
37
+ updateSDRStatus({ data: { Devices: "3" } });
38
+
39
+ const state = useDevicesStore.getState();
40
+ expect(state.sdrDeviceCount).toBe(3);
41
+ });
42
+
43
+ test("should handle actual number values", () => {
44
+ const { updateSDRStatus } = useDevicesStore.getState();
45
+
46
+ updateSDRStatus({ data: { Devices: 7 } });
47
+
48
+ const state = useDevicesStore.getState();
49
+ expect(state.sdrDeviceCount).toBe(7);
50
+ });
51
+ });
52
+ });
53
+
54
+ describe("GPS Device Slice", () => {
55
+ describe("updateGPSStatus", () => {
56
+ test("should update GPS status with all fields", () => {
57
+ const { updateGPSStatus } = useDevicesStore.getState();
58
+
59
+ const gpsData = {
60
+ GPS_connected: true,
61
+ GPS_solution: "3D GPS + SBAS",
62
+ GPS_position_accuracy: 7.02,
63
+ };
64
+
65
+ updateGPSStatus({ data: gpsData });
66
+
67
+ const state = useDevicesStore.getState();
68
+ expect(state.gpsConnected).toBe(true);
69
+ expect(state.gpsSolution).toBe("3D GPS + SBAS");
70
+ expect(state.gpsAccuracy).toBe(7.02);
71
+ });
72
+
73
+ test("should handle GPS disconnected state", () => {
74
+ const { updateGPSStatus } = useDevicesStore.getState();
75
+
76
+ const gpsData = {
77
+ GPS_connected: false,
78
+ GPS_solution: "No Fix",
79
+ GPS_position_accuracy: 0,
80
+ };
81
+
82
+ updateGPSStatus({ data: gpsData });
83
+
84
+ const state = useDevicesStore.getState();
85
+ expect(state.gpsConnected).toBe(false);
86
+ expect(state.gpsSolution).toBe("No Fix");
87
+ expect(state.gpsAccuracy).toBe(0);
88
+ });
89
+ });
90
+ });
91
+ });
@@ -0,0 +1,20 @@
1
+ import whitebox
2
+
3
+
4
+ class WhiteboxPluginDeviceStatus(whitebox.Plugin):
5
+ name = "Device Status"
6
+
7
+ provides_capabilities = ["device-status"]
8
+ slot_component_map = {
9
+ "device-status.sdr": "SDRStatus",
10
+ "device-status.gps": "GPSStatus",
11
+ }
12
+ exposed_component_map = {
13
+ "device-status": {
14
+ "sdr": "SDRStatus",
15
+ "gps": "GPSStatus",
16
+ }
17
+ }
18
+
19
+
20
+ plugin_class = WhiteboxPluginDeviceStatus