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 default values to static ADR in MAC settings #7512

Merged
merged 1 commit into from
Feb 19, 2025
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
20 changes: 17 additions & 3 deletions pkg/webui/console/components/mac-settings-section/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ const maxDutyCycleOptions = [
{ value: 'DUTY_CYCLE_16384', label: '0.006%' },
]

const encodeAdrMode = value => ({ [value]: {} })
const decodeAdrMode = value => (value !== undefined ? Object.keys(value)[0] : null)

const MacSettingsSection = props => {
const {
activationMode,
Expand Down Expand Up @@ -238,6 +235,20 @@ const MacSettingsSection = props => {
[values],
)

const getEncodedAdrModeValue = useCallback(mode => {
if (mode === 'static') {
return {
data_rate_index: 0,
tx_power_index: 0,
nb_trans: 1,
}
}
return {}
}, [])

const encodeAdrMode = value => ({ [value]: getEncodedAdrModeValue(value) })
const decodeAdrMode = value => (value !== undefined ? Object.keys(value)[0] : null)

return (
<Form.CollapseSection
id="mac-settings"
Expand Down Expand Up @@ -697,13 +708,16 @@ const MacSettingsSection = props => {
component={Input}
type="number"
inputWidth="xs"
max={15}
/>
<Form.Field
title={m.adrUplinks}
name="mac_settings.adr.static.nb_trans"
component={Input}
type="number"
inputWidth="xs"
min={1}
max={15}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,13 @@ const validationSchema = Yup.object()
return Yup.object().shape({
static: Yup.object().shape({
data_rate_index: Yup.number().nullable(),
tx_power_index: Yup.number().nullable(),
nb_trans: Yup.number().nullable(),
tx_power_index: Yup.number()
.nullable()
.max(15, Yup.passValues(sharedMessages.validateNumberLte)),
nb_trans: Yup.number()
.nullable()
.min(1, Yup.passValues(sharedMessages.validateNumberGte))
.max(15, Yup.passValues(sharedMessages.validateNumberLte)),
}),
})
} else if (value && 'disabled' in value) {
Expand Down
4 changes: 2 additions & 2 deletions sdk/js/src/service/devices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Devices {
}
}

if (paths.includes('mac_settings')) {
if (paths.some(path => path.includes('mac_settings'))) {
const { mac_settings = {} } = device

if (
Expand All @@ -137,7 +137,7 @@ class Devices {
}

if (typeof mac_settings.adr.static.nb_trans === 'undefined') {
mac_settings.adr.static.nb_trans = 0
mac_settings.adr.static.nb_trans = 1
}

if (typeof mac_settings.adr.static.tx_power_index === 'undefined') {
Expand Down
Loading