Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Neighbor Info Module Config #141

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/components/PageComponents/ModuleConfig/NeighborInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useDevice } from "@app/core/stores/deviceStore.js";
import type { NeighborInfoValidation } from "@app/validation/moduleConfig/neighborInfo.js";
import { DynamicForm } from "@components/Form/DynamicForm.js";
import { Protobuf } from "@meshtastic/meshtasticjs";

export const NeighborInfo = (): JSX.Element => {
const { moduleConfig, setWorkingModuleConfig } = useDevice();

const onSubmit = (data: NeighborInfoValidation) => {
setWorkingModuleConfig(
new Protobuf.ModuleConfig({
payloadVariant: {
case: "neighborInfo",
value: data,
},
}),
);
};

return (
<DynamicForm<NeighborInfoValidation>
onSubmit={onSubmit}
defaultValues={moduleConfig.neighborInfo}
fieldGroups={[
{
label: "Neighbor Info Settings",
description: "Settings for the Neighbor Info module",
fields: [
{
type: "toggle",
name: "enabled",
label: "Enabled",
description: "Enable or disable Neighbor Info Module",
},
{
type: "number",
name: "updateInterval",
label: "Update Interval",
description: "Interval in seconds of how often we should try to send our Neighbor Info to the mesh",
disabledBy: [
{
fieldName: "enabled",
},
],
},
],
},
]}
/>
);
};
9 changes: 6 additions & 3 deletions src/core/stores/deviceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({

if (device) {
switch (config.payloadVariant.case) {
case "detectionSensor":
device.moduleConfig.detectionSensor = config.payloadVariant.value;
break;
case "mqtt":
device.moduleConfig.mqtt = config.payloadVariant.value;
break;
Expand Down Expand Up @@ -216,6 +213,12 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
break;
case "audio":
device.moduleConfig.audio = config.payloadVariant.value;
break;
case "detectionSensor":
device.moduleConfig.detectionSensor = config.payloadVariant.value;
break;
case "neighborInfo":
device.moduleConfig.neighborInfo = config.payloadVariant.value;
}
}
}),
Expand Down
5 changes: 5 additions & 0 deletions src/pages/Config/ModuleConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NeighborInfo } from "@app/components/PageComponents/ModuleConfig/NeighborInfo.js";
import { DetectionSensor } from "@app/components/PageComponents/ModuleConfig/DetectionSensor.js";
import { Audio } from "@components/PageComponents/ModuleConfig/Audio.js";
import { CannedMessage } from "@components/PageComponents/ModuleConfig/CannedMessage.js";
Expand Down Expand Up @@ -48,6 +49,10 @@ export const ModuleConfig = (): JSX.Element => {
label: "Audio",
element: Audio,
},
{
label: "Neighbor Info",
element: NeighborInfo,
},
{
label: "Detection Sensor",
element: DetectionSensor,
Expand Down
17 changes: 17 additions & 0 deletions src/validation/moduleConfig/neighborInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IsBoolean, IsInt, Length } from "class-validator";

import type { Protobuf } from "@meshtastic/meshtasticjs";

export class NeighborInfoValidation
implements
Omit<
Protobuf.ModuleConfig_NeighborInfoConfig,
keyof Protobuf.native.Message
>
{
@IsBoolean()
enabled: boolean;

@IsInt()
updateInterval: number;
}