Skip to content

Commit

Permalink
Merge pull request #946 from NordicSemiconductor/fix/regression-cli-a…
Browse files Browse the repository at this point in the history
…utoconnect-persisted-data

Fix/regression cli autoconnect persisted data
  • Loading branch information
kylebonnici authored Oct 4, 2024
2 parents bce2590 + da70b8b commit 1b31a4f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 38 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ This project does _not_ adhere to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html) but contrary to it
every new version is a new major version.

## 187.0.0 - 2024-10-04

### Fixed

- Auto connecting from CLI for device that has persisted data.

## 186.0.0 - 2024-10-03

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nordicsemiconductor/pc-nrfconnect-shared",
"version": "186.0.0",
"version": "187.0.0",
"description": "Shared commodities for developing pc-nrfconnect-* packages",
"repository": {
"type": "git",
Expand Down
44 changes: 43 additions & 1 deletion src/Device/deviceLister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import logger from '../logging';
import type { AppThunk, RootState } from '../store';
import simplifyDevice from '../telemetry/simplifyDevice';
import telemetry from '../telemetry/telemetry';
import {
getPersistedIsFavorite,
getPersistedNickname,
getPersistedSerialPortSettings,
} from '../utils/persistentStore';
import {
clearWaitForDevice,
clearWaitForDeviceTimeout,
Expand Down Expand Up @@ -161,6 +166,36 @@ const removeDeviceFromList =
* library for available traits. Whenever devices are attached/detached, this
* will dispatch AddDevice or removeDevice and trigger events.
*/

const setPersistedData = (device: Device) => {
if (device.serialNumber) {
const newDevice = { ...device };
newDevice.favorite = getPersistedIsFavorite(device.serialNumber);
newDevice.nickname = getPersistedNickname(device.serialNumber);

const persistedSerialPortSettings = getPersistedSerialPortSettings(
device.serialNumber
);

if (persistedSerialPortSettings) {
const path =
newDevice.serialPorts?.[persistedSerialPortSettings.vComIndex]
?.comName;

if (path) {
newDevice.persistedSerialPortOptions = {
...persistedSerialPortSettings.serialPortOptions,
path,
};
}
}

return newDevice;
}

return device;
};

export const startWatchingDevices =
(
deviceListing: DeviceTraits,
Expand Down Expand Up @@ -404,13 +439,20 @@ export const startWatchingDevices =
const operation = await NrfutilDeviceLib.list(
deviceListing,
d => {
d = d.map(setPersistedData);
d.forEach(onDeviceArrived);
autoSelectDeviceCLI(d, doSelectDevice);
},
error => {
logger.error(error);
},
{ onDeviceArrived, onDeviceLeft }
{
onDeviceArrived: d => {
d = setPersistedData(d);
onDeviceArrived(d);
},
onDeviceLeft,
}
);

stopNrfutilDevice = (callback?: () => void) => {
Expand Down
38 changes: 2 additions & 36 deletions src/Device/deviceSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import { DeviceInfo } from '../../nrfutil/device';
import { NrfutilDevice } from '../../nrfutil/device/common';
import type { RootState } from '../store';
import {
getPersistedIsFavorite,
getPersistedNickname,
getPersistedSerialPortSettings,
persistIsFavorite,
persistNickname,
persistSerialPortSettings as persistSerialPortSettingsToStore,
Expand Down Expand Up @@ -69,35 +66,6 @@ const initialState: DeviceState = {
devices: [],
};

const setPersistedData = (device: Device) => {
if (device.serialNumber) {
const newDevice = { ...device };
newDevice.favorite = getPersistedIsFavorite(device.serialNumber);
newDevice.nickname = getPersistedNickname(device.serialNumber);

const persistedSerialPortSettings = getPersistedSerialPortSettings(
device.serialNumber
);

if (persistedSerialPortSettings) {
const path =
newDevice.serialPorts?.[persistedSerialPortSettings.vComIndex]
?.comName;

if (path) {
newDevice.persistedSerialPortOptions = {
...persistedSerialPortSettings.serialPortOptions,
path,
};
}
}

return newDevice;
}

return device;
};

const slice = createSlice({
name: 'device',
initialState,
Expand Down Expand Up @@ -130,12 +98,10 @@ const slice = createSlice({
item.serialNumber === action.payload.serialNumber ||
item.id === action.payload.id
);

const device = setPersistedData(action.payload);
if (index !== -1) {
state.devices[index] = device;
state.devices[index] = action.payload;
} else {
state.devices.push(device);
state.devices.push(action.payload);
}
},

Expand Down

0 comments on commit 1b31a4f

Please sign in to comment.