trading_agent.devices.device_store
¶
The phones that receive push notifications, kept in one JSON file.
The Android app registers its Firebase Cloud Messaging token after signing in, with the gateway's access token, so only the owner's phones are added. The user can remove a phone on the Settings page. The file sits in workspace/shared, which the desks can read but never write.
Typical usage example:
store = DeviceStore(layout.phone_devices_file) phone = store.register(firebase_token, 'Galaxy M53') store.remove(phone.device_id)
DeviceError
¶
Bases: ValueError
A phone that is not registered, or one more phone than the store keeps.
PhoneDevice
dataclass
¶
One phone that receives notifications.
Attributes:
| Name | Type | Description |
|---|---|---|
device_id |
str
|
A short random id for the phone, used to remove it. |
token |
str
|
The Firebase Cloud Messaging token that addresses the app on this phone. |
name |
str
|
The phone's name as the app reports it, such as "Samsung SM-M536B". |
registered_at |
str
|
When it was first registered, as an ISO 8601 string in UTC. |
DeviceStore
¶
The registered phones, kept in one JSON file.
Creates the store without reading the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The JSON file. |
required |
clock
|
Callable[[], datetime] | None
|
Returns the current time in UTC; None uses the system clock. |
None
|
Source code in src/trading_agent/devices/device_store.py
register
¶
Adds a phone, or renames it when its token is already known.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
The phone's Firebase Cloud Messaging token. |
required |
name
|
str
|
The phone's name. |
required |
Returns:
| Type | Description |
|---|---|
PhoneDevice
|
The phone as stored. |
Raises:
| Type | Description |
|---|---|
DeviceError
|
The token is empty, or ten phones are already registered. |
Source code in src/trading_agent/devices/device_store.py
remove
¶
Removes a phone, so it gets no more notifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_id
|
str
|
The phone's id. |
required |
Returns:
| Type | Description |
|---|---|
PhoneDevice
|
The phone that was removed. |
Raises:
| Type | Description |
|---|---|
DeviceError
|
No phone has that id. |
Source code in src/trading_agent/devices/device_store.py
forget_token
¶
Removes the phone with a token Firebase says is no longer valid, such as after the app was uninstalled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
The token. |
required |
Source code in src/trading_agent/devices/device_store.py
devices
¶
Every registered phone.
Returns:
| Type | Description |
|---|---|
list[PhoneDevice]
|
The phones, in the order they were registered. |