-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (core) [DSDK-218]: Polling on connected device (#78)
- Loading branch information
Showing
19 changed files
with
458 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/device-sdk-core": minor | ||
--- | ||
|
||
Polling on connected device to get device status. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 109 additions & 11 deletions
120
packages/core/src/api/device-session/DeviceSessionState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,115 @@ | ||
import { BatteryStatusFlags } from "@api/command/os/GetBatteryStatusCommand"; | ||
import { DeviceStatus } from "@api/device/DeviceStatus"; | ||
import { DeviceSessionId } from "@api/device-session/types"; | ||
|
||
export type SessionStateConstructorArgs = { | ||
sessionId: DeviceSessionId; | ||
deviceStatus: DeviceStatus; | ||
/** | ||
* The battery status of a device. | ||
*/ | ||
export type BatteryStatus = { | ||
level: number; | ||
voltage: number; | ||
temperature: number; | ||
current: number; | ||
status: BatteryStatusFlags; | ||
}; | ||
|
||
export class DeviceSessionState { | ||
public readonly sessionId: DeviceSessionId; | ||
public readonly deviceStatus: DeviceStatus; | ||
/** | ||
* The firmware version of a device. | ||
*/ | ||
export type FirmwareVersion = { | ||
/** | ||
* Microcontroller Unit version | ||
*/ | ||
mcu: string; | ||
|
||
/** | ||
* Bootloader version | ||
*/ | ||
bootloader: string; | ||
|
||
constructor({ sessionId, deviceStatus }: SessionStateConstructorArgs) { | ||
this.sessionId = sessionId; | ||
this.deviceStatus = deviceStatus; | ||
} | ||
/** | ||
* Operating System version | ||
*/ | ||
os: string; | ||
}; | ||
|
||
/** | ||
* The state types of a device session. | ||
*/ | ||
export enum DeviceSessionStateType { | ||
Connected, | ||
ReadyWithoutSecureChannel, | ||
ReadyWithSecureChannel, | ||
} | ||
|
||
type DeviceSessionBaseState = { | ||
readonly sessionStateType: DeviceSessionStateType; | ||
|
||
/** | ||
* The status of the device. | ||
*/ | ||
deviceStatus: DeviceStatus; | ||
|
||
/** | ||
* The name of the device. | ||
*/ | ||
deviceName?: string; | ||
}; | ||
|
||
type DeviceSessionReadyState = { | ||
/** | ||
* The battery status of the device. | ||
* TODO: This should not be optional, but it is not in the current implementation. | ||
*/ | ||
batteryStatus?: BatteryStatus; | ||
|
||
/** | ||
* The firmware version of the device. | ||
* TODO: This should not be optional, but it is not in the current implementation. | ||
*/ | ||
firmwareVersion?: FirmwareVersion; | ||
|
||
/** | ||
* The current application running on the device. | ||
*/ | ||
currentApp: string; | ||
}; | ||
|
||
/** | ||
* The state of a connected device session. | ||
*/ | ||
export type ConnectedState = DeviceSessionBaseState & { | ||
/** | ||
* The type of the device session state. | ||
*/ | ||
readonly sessionStateType: DeviceSessionStateType.Connected; | ||
}; | ||
|
||
/** | ||
* The state of a device session when it is ready without a secure channel. | ||
*/ | ||
export type ReadyWithoutSecureChannelState = DeviceSessionBaseState & | ||
DeviceSessionReadyState & { | ||
/** | ||
* The type of the device session state. | ||
*/ | ||
readonly sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel; | ||
}; | ||
|
||
/** | ||
* The state of a device session when it is ready with a secure channel. | ||
*/ | ||
export type ReadyWithSecureChannelState = DeviceSessionBaseState & | ||
DeviceSessionReadyState & { | ||
/** | ||
* The type of the device session state. | ||
*/ | ||
readonly sessionStateType: DeviceSessionStateType.ReadyWithSecureChannel; | ||
}; | ||
|
||
/** | ||
* The state of a device session. | ||
*/ | ||
export type DeviceSessionState = | ||
| ConnectedState | ||
| ReadyWithoutSecureChannelState | ||
| ReadyWithSecureChannelState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.