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 Timezone configuration #255

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"files": {
"ignoreUnknown": true,
"ignore": ["vercel.json"]
"ignore": ["vercel.json", "tz.ts"]
},
"vcs": {
"enabled": true,
Expand Down
5 changes: 5 additions & 0 deletions src/components/Form/DynamicFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import {
type SelectFieldProps,
SelectInput,
SelectStringInput,
} from "@components/Form/FormSelect.js";
import {
type ToggleFieldProps,
Expand Down Expand Up @@ -44,6 +45,10 @@ export function DynamicFormField<T extends FieldValues>({
return (
<SelectInput field={field} control={control} disabled={disabled} />
);
case "stringSelect":
return (
<SelectStringInput field={field} control={control} disabled={disabled} />
);
case "multiSelect":
return <div>tmp</div>;
}
Expand Down
51 changes: 50 additions & 1 deletion src/components/Form/FormSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { Controller, type FieldValues } from "react-hook-form";

export interface SelectFieldProps<T> extends BaseFormBuilderProps<T> {
type: "select" | "multiSelect";
type: "select" | "multiSelect" | "stringSelect";
properties: BaseFormBuilderProps<T>["properties"] & {
enumValue: {
[s: string]: string | number;
Expand Down Expand Up @@ -69,3 +69,52 @@ export function SelectInput<T extends FieldValues>({
/>
);
}

export function SelectStringInput<T extends FieldValues>({
control,
disabled,
field,
}: GenericFormElementProps<T, SelectFieldProps<T>>) {
return (
<Controller
name={field.name}
control={control}
render={({ field: { value, onChange, ...rest } }) => {
const { enumValue, formatEnumName, ...remainingProperties } =
field.properties;
const optionsEnumValues = enumValue
? Object.entries(enumValue).filter(
(value) => typeof value[1] === "string",
)
: [];
return (
<Select
onValueChange={(e) => onChange(e)}
disabled={disabled}
value={value}
{...remainingProperties}
{...rest}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
{optionsEnumValues.map(([name, value]) => (
<SelectItem key={name} value={value.toString()}>
{formatEnumName
? name
.replace(/_/g, " ")
.toLowerCase()
.split(" ")
.map((s) => s.charAt(0).toUpperCase() + s.substring(1))
.join(" ")
: name}
</SelectItem>
))}
</SelectContent>
</Select>
);
}}
/>
);
}
18 changes: 16 additions & 2 deletions src/components/PageComponents/Config/Device.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { tzInfo } from "@app/core/utils/tz";
import type { DeviceValidation } from "@app/validation/config/device.js";
import { DynamicForm } from "@components/Form/DynamicForm.js";
import { useDevice } from "@core/stores/deviceStore.js";
import { Protobuf } from "@meshtastic/js";

export const Device = (): JSX.Element => {
const { config, setWorkingConfig } = useDevice();
const { config, setWorkingConfig, setTzDropdown } = useDevice();

const onSubmit = (data: DeviceValidation) => {
const tzInt = Number.parseInt(data.tzdef);
setWorkingConfig(
new Protobuf.Config.Config({
payloadVariant: {
Expand All @@ -20,7 +22,10 @@ export const Device = (): JSX.Element => {
return (
<DynamicForm<DeviceValidation>
onSubmit={onSubmit}
defaultValues={config.device}
defaultValues={{
//tzdef: toTzDropdown(config.device?.tzdef ?? ""),
...config.device,
}}
fieldGroups={[
{
label: "Device Settings",
Expand All @@ -36,6 +41,15 @@ export const Device = (): JSX.Element => {
formatEnumName: true,
},
},
{
type: "stringSelect",
name: "tzdef",
label: "Timezone",
description: "What timezone is the device in",
properties: {
enumValue: tzInfo,
},
},
{
type: "toggle",
name: "serialEnabled",
Expand Down
29 changes: 29 additions & 0 deletions src/core/utils/tz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export enum tzInfo {
"UTC +12" = "<-12>12",
"UTC +11" = "<-11>11",
"UTC +10" = "<-10>10",
"UTC +9" = "<-09>9",
"UTC +8" = "<-08>8",
"UTC +7" = "<-07>7",
"UTC +6" = "<-06>6",
"UTC +5" = "<-05>5",
"UTC +4" = "<-04>4",
"UTC +3" = "<-03>3",
"UTC +2" = "<-02>2",
"UTC +1" = "<-01>1",
"UTC" = "GMT0",
"UTC -1" = "<+01>-1",
"UTC -2" = "<+02>-2",
"UTC -3" = "<+03>-3",
"UTC -4" = "<+04>-4",
"UTC -5" = "<+05>-5",
"UTC -6" = "<+06>-6",
"UTC -7" = "<+07>-7",
"UTC -8" = "<+08>-8",
"UTC -9" = "<+09>-9",
"UTC -10" = "<+10>-10",
"UTC -11" = "<+11>-11",
"UTC -12" = "<+12>-12",
"UTC -13" = "<+13>-13",
"UTC -14" = "<+14>-14",
}
8 changes: 7 additions & 1 deletion src/validation/config/device.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { Message } from "@bufbuild/protobuf";
import { Protobuf } from "@meshtastic/js";
import { IsBoolean, IsEnum, IsInt } from "class-validator";
import { IsBoolean, IsEnum, IsInt, IsString } from "class-validator";

export class DeviceValidation
implements Omit<Protobuf.Config.Config_DeviceConfig, keyof Message>
{
@IsEnum(Protobuf.Config.Config_DeviceConfig_Role)
role: Protobuf.Config.Config_DeviceConfig_Role;

@IsString()
tzdef: string;

@IsBoolean()
serialEnabled: boolean;

Expand All @@ -34,4 +37,7 @@ export class DeviceValidation

@IsBoolean()
disableTripleClick: boolean;

@IsBoolean()
ledHeartbeatDisabled: boolean;
}
5 changes: 4 additions & 1 deletion src/validation/config/display.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Message } from "@bufbuild/protobuf";
import { Protobuf } from "@meshtastic/js";
import { IsBoolean, IsEnum, IsInt } from "class-validator";
import { IsBoolean, IsEnum, IsInt, IsNumber } from "class-validator";

export class DisplayValidation
implements Omit<Protobuf.Config.Config_DisplayConfig, keyof Message>
Expand Down Expand Up @@ -34,4 +34,7 @@ export class DisplayValidation

@IsBoolean()
wakeOnTapOrMotion: boolean;

@IsInt()
compassOrientation: number;
}
6 changes: 6 additions & 0 deletions src/validation/moduleConfig/paxcounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ export class PaxcounterValidation

@IsInt()
paxcounterUpdateInterval: number;

@IsInt()
wifiThreshold: number;

@IsInt()
bleThreshold: number;
}
Loading