mwings.parsers.app_cue Module
Parsers for packets sent from the TWELITE CUE mode and data structures to store their contents.
PacketParser
Static class for parsing packets representing data sent from the Cue app (TWELITE CUE mode).
Inherits from:
common.PacketParserBase
is_valid()
is_valid(bare_packet)
Checks whether the given bare packet is valid.
Parameters
| Name | Type | Description |
|---|---|---|
bare_packet | common.BarePacket | Raw packet data |
Returns
| Type | Value | Description |
|---|---|---|
bool | True | Valid and parsable |
False | Invalid and unparsable |
parse()
parse(bare_packet)
Parses the given bare packet.
Parameters
| Name | Type | Description |
|---|---|---|
bare_packet | common.BarePacket | Raw packet data |
Returns
| Type | Value | Description |
|---|---|---|
optional ParsedPacket | ParsedPacket typed data | Parsed data |
None | Unparsable |
ParsedPacket
Structure to store the result of parsing packets representing data sent from the Cue app (TWELITE CUE mode).
Inherits from:
common.ParsedPacketBase
ParsedPacket()
ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, sample_count=10, samples_x=<mwings.common.TimeSeries object>, samples_y=<mwings.common.TimeSeries object>, samples_z=<mwings.common.TimeSeries object>, has_accel_event=False, accel_event=AccelEvent.NONE, magnet_state=MagnetState.NOT_DETECTED, magnet_state_changed=False)
Parameters
Including properties inherited from the base class.
| Name | Type | Description |
|---|---|---|
time_parsed | optional AwareDatetime | Parsing timestamp |
packet_type | common.PacketType | Packet type |
sequence_number | optional common.UInt16 | Sequence number |
source_serial_id | common.UInt32 | Source serial ID |
source_logical_id | common.UInt8 | Source logical device ID |
lqi | optional common.UInt8 | Radio communication quality |
supply_voltage | optional common.UInt16 | Supply voltage (mV) |
router_serial_id | common.UInt32 | Serial ID of the first relay device (no relay is 0x80000000) v1.0.13+ |
sample_count | common.UInt8 | Number of accelerometer samples per axis |
samples_x | common.TimeSeries[common.Int16] | X-axis accelerometer samples |
samples_y | common.TimeSeries[common.Int16] | Y-axis accelerometer samples |
samples_z | common.TimeSeries[common.Int16] | Z-axis accelerometer samples |
has_accel_event | bool | Presence of accelerometer event |
accel_event | common.AccelEvent | Accelerometer event |
magnet_state | common.MagnetState | Magnet state |
magnet_state_changed | bool | Whether magnet state has changed |
You can also pass a dictionary unpacked with
**.
In addition to the variables specified as constructor arguments, the following @computed_field are also available.
| Name | Type | Description |
|---|---|---|
mwings_implementation | str | MWings implementation (only "python") |
mwings_version | str | MWings version (in PEP440 format) |
hostname | str | Host machine name |
system_type | str | System type (e.g., "Linux") |
Applicable field_validator
source_logical_id: Automatically validates the value rangecheck_source_logical_id(lid)
time_parsed: Automatically validates that a timezone is attacheddatetime_must_be_clear(dt)
Applicable field_serializer
packet_type: Serializes the enum name as is in JSON etc.serialize_packet_type(packet_type)
source_serial_id: Serializes as a hexadecimal string in JSON etc.serialize_source_serial_id(source_serial_id)
time_parsed: Serializes as an ISO 8601 string in JSON etc.serialize_time_parsed(dt)
accel_event: Serializes the enum name as is in JSON etc.serialize_accel_event(accel_event)
magnet_state: Serializes the enum name as is in JSON etc.serialize_magnet_state(magnet_state)
to_df()
to_df(include=None, exclude=None, verbose=True)
Converts the parsed data to a pandas DataFrame.
Parameters
| Name | Type | Description |
|---|---|---|
include | optional set[str] | Set of columns (members) to include in the DataFrame |
exclude | optional set[str] | Set of columns (members) to exclude from the DataFrame |
verbose | bool | Whether to include system information (only when other arguments are None) |
Returns
| Type | Value | Description |
|---|---|---|
pd.DataFrame | - | Converted DataFrame |
Exceptions
EnvironmentErrorif pandas is not installed
to_dict()
to_dict(include=None, exclude=None, verbose=True, spread=False, sort_keys=False)
Converts the parsed data to a dictionary.
Parameters
| Name | Type | Description |
|---|---|---|
include | optional set[str] | Set of keys (members) to include in the dictionary |
exclude | optional set[str] | Set of keys (members) to exclude from the dictionary |
verbose | bool | Whether to include system information (only when other arguments are None) |
spread | bool | Whether to split non-time-series list-like data |
sort_keys | bool | Whether to sort keys |
spread is set, time-series data of type common.TimeSeries[T] will not be split.Returns
| Type | Value | Description |
|---|---|---|
dict[str, Any] | - | Converted dictionary |
to_json()
to_json(include=None, exclude=None, verbose=True, spread=False, indent=2, sort_keys=False)
Converts the parsed data to JSON format.
Parameters
| Name | Type | Description |
|---|---|---|
include | optional set[str] | Set of keys (members) to include in the JSON |
exclude | optional set[str] | Set of keys (members) to exclude from the JSON |
verbose | bool | Whether to include system information (only when other arguments are None) |
spread | bool | Whether to split non-time-series list-like data |
indent | optional int | Number of spaces for indentation (None for no newline) |
sort_keys | bool | Whether to sort keys |
spread is set, time-series data of type common.TimeSeries[T] will not be split.Returns
| Type | Value | Description |
|---|---|---|
str | - | Converted JSON string |
model_*()
pydantic.BaseModel.