mwings.common Module
Contains data and procedures used throughout the library.
AccelEvent
Identifiers for accelerometer events
Inherits from:
enum.IntEnum
DICE_1Dice: 1DICE_2Dice: 2DICE_3Dice: 3DICE_4Dice: 4DICE_5Dice: 5DICE_6Dice: 6SHAKEShakeMOVEMoveNONENo event
AppPalNoticeBlinkSpeed
Identifiers for AppPal notification blink speed
Inherits from:
enum.IntEnum
ALWAYS_ONAlways onSLOWSlow blinkingMEDIUMModerate blinkingFASTFast blinking
AppPalNoticeColor
Identifiers for AppPal notification colors
Inherits from:
enum.IntEnum
REDRedGREENGreenBLUEBlueYELLOWYellowPURPLEPurpleLIGHT_BLUELight blueWHITEWhiteWARM_WHITEWarm white
AppPalNoticeRGBWColor
Notification color expressed in RGBW format
Inherits from:
pydantic.BaseModel
AppPalNoticeRGBWColor()
AppPalNoticeRGBWColor(*, red=0, green=0, blue=0, white=15)
Parameters
| Name | Type | Description |
|---|---|---|
red | common.UInt8 | Red: 0–0xF |
green | common.UInt8 | Green: 0–0xF |
blue | common.UInt8 | Blue: 0–0xF |
white | common.UInt8 | White: 0–0xF |
You may pass a dictionary using
**unpacking.
u16()
u16()
Returns a 16-bit RGBW representation.
Parameters
None
Returns
| Type | Value | Description |
|---|---|---|
common.UInt16 | - | 16-bit RGBW representation |
BarePacket
Raw packet data
Inherits from:
pydantic.BaseModel
BarePacket()
BarePacket(payload, checksum=None, logical_and_command_id=None)
Parameters
| Name | Type | Description |
|---|---|---|
payload | bytes | Binary payload data |
checksum | optional common.UInt8 | LRC8: Automatically calculated if None |
logical_and_command_id | optional tuple(common.UInt8, common.UInt8) | Logical device ID and command ID |
If the third argument is specified, the corresponding header in the payload is omitted.
i16_at()
i16_at(index)
Gets a signed 16-bit integer from the specified position.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | Position in payload |
Returns
| Type | Value | Description |
|---|---|---|
common.Int16 | - | Numeric data |
i32_at()
i32_at(index)
Gets a signed 32-bit integer from the specified position.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | Position in payload |
Returns
| Type | Value | Description |
|---|---|---|
common.Int32 | - | Numeric data |
i8_at()
i8_at(index)
Gets a signed 8-bit integer from the specified position.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | Position in payload |
Returns
| Type | Value | Description |
|---|---|---|
common.Int8 | - | Numeric data |
u16_at()
u16_at(index)
Gets an unsigned 16-bit integer from the specified position.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | Position in payload |
Returns
| Type | Value | Description |
|---|---|---|
common.UInt16 | - | Numeric data |
u32_at()
u32_at(index)
Gets an unsigned 32-bit integer from the specified position.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | Position in payload |
Returns
| Type | Value | Description |
|---|---|---|
common.UInt32 | - | Numeric data |
u8_at()
u8_at(index)
Gets an unsigned 8-bit integer from the specified position.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | Position in payload |
Returns
| Type | Value | Description |
|---|---|---|
common.UInt8 | - | Numeric data |
u8_from()
u8_from(index)
Gets a byte sequence starting from the specified index.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | Starting index in payload |
Returns
| Type | Value | Description |
|---|---|---|
optional bytes | bytes | Partial byte sequence |
None | Invalid index |
CommandBase
Abstract base class for commands
Inherits from:
ABC,pydantic.BaseModel
CommandBase()
CommandBase(*, destination_logical_id=120)
Parameters
| Name | Type | Description |
|---|---|---|
destination_logical_id | common.UInt8 | Logical device ID of destination |
You may pass a dictionary using
**unpacking.
is_valid()
is_valid()
Checks if the command data is valid.
Parameters
None
Returns
| Type | Value | Description |
|---|---|---|
bool | True | Valid |
False | Invalid |
CommandSerializerBase
Static abstract base class for command serializers
Inherits from:
ABC
serialize()
serialize(command)
Expands the given command into a raw byte sequence.
Parameters
| Name | Type | Description |
|---|---|---|
command | common.SomeCommand | A command data object |
Returns
| Type | Value | Description |
|---|---|---|
optional common.BarePacket | common.BarePacket | Expanded packet data |
None | Invalid command |
CrossSectional[T]
Tuple-like class for storing cross-sectional data at a specific time point
Inherits from:
common.FixedTuple[T]
CrossSectional[T]()
CrossSectional[T](length, elements)
Parameters
| Name | Type | Description |
|---|---|---|
T | common.T | Element type |
length | int | Number of elements |
elements | Iterable[T] | Element values |
Exceptions
ValueErrorif the number of elements is invalid
DtypedDecimal
Abstract base class for numeric types that retain pandas dtype attribute
get_dtype()
get_dtype()
Retrieves the corresponding pandas dtype identifier.
Parameters
None
Returns
| Type | Value | Description |
|---|---|---|
str | - | dtype identifier |
FixedList[T]
A class representing a fixed-length list
Inherits from:
MutableSequence[T]
FixedList[T]()
FixedList[T](length, initial_elements)
Parameters
| Name | Type | Description |
|---|---|---|
T | common.T | Type of elements |
length | int | Number of elements |
initial_elements | Iterable[T] | Initial elements |
Exceptions
ValueErrorif the number of elements is invalid
insert()
insert(index, value)
Inserts an element at the specified index.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | Index to insert |
value | common.T | Element to insert |
Returns
None
Exceptions
IndexErrorif the index is invalid
FixedTuple[T]
Class representing a fixed-length tuple
Inherits from:
Sequence[T]
FixedTuple[T]()
FixedTuple[T](length, elements)
Parameters
| Name | Type | Description |
|---|---|---|
T | common.T | Type of elements |
length | int | Number of elements |
elements | Iterable[T] | Elements |
Exceptions
ValueErrorif the number of elements is invalid
Float32
Class to store a 32-bit floating point value
Inherits from:
float,common.DtypedDecimal
Float32()
Float32(value=None)
Parameters
| Name | Type | Description |
|---|---|---|
value | optional float | Initial value |
Exceptions
ValueErrorif the value is out of range
Float64
Class to store a 64-bit floating point value
Inherits from:
float,common.DtypedDecimal
Float64()
Float64(value=None)
Parameters
| Name | Type | Description |
|---|---|---|
value | optional float | Initial value |
Exceptions
ValueErrorif the value is out of range
Int16
Class to store a 16-bit integer
Inherits from:
int,common.DtypedDecimal
Int16()
Int16(value=None)
Parameters
| Name | Type | Description |
|---|---|---|
value | optional int | Initial value |
Exceptions
ValueErrorif the value is out of range
hex()
hex()
Returns a hexadecimal string representation.
Python’s built-in hex() function does not accept int subclasses. This method provides a similar interface as float.hex().
Returns
| Type | Value | Description |
|---|---|---|
str | - | Hexadecimal string (lowercase) |
Int32
Class to store a 32-bit integer
Inherits from:
int,common.DtypedDecimal
Int32()
Int32(value=None)
Parameters
| Name | Type | Description |
|---|---|---|
value | optional int | Initial value |
Exceptions
ValueErrorif the value is out of range
hex()
Same as in Int16
Int8
Class to store an 8-bit integer
Inherits from:
int,common.DtypedDecimal
Int8()
Int8(value=None)
Parameters
| Name | Type | Description |
|---|---|---|
value | optional int | Initial value |
Exceptions
ValueErrorif the value is out of range
hex()
Same as in Int16
MagnetState
Identifiers for magnet events
Inherits from:
enum.IntEnum
NOT_DETECTEDNo magnetN_POLE_IS_CLOSEN pole is closeS_POLE_IS_CLOSES pole is close
PacketParserBase
Static abstract base class for packet parsers
Inherits from:
ABC
is_valid()
is_valid(bare_packet)
Checks if the given bare packet is valid.
parse()
parse(bare_packet)
Parses the given bare packet.
PacketType
Identifiers for packet types
Inherits from:
enum.StrEnum
(Keep enum entries as-is, only translated names if needed)
SomeCallable, SomeCommand, SomeParsedPacket, T, Timezone
Keep these type variable and constant definitions unchanged.
TimeSeries[T]
Tuple-like class for storing time-series data
Inherits from:
common.FixedTuple[T]
TimeSeries[T]()
TimeSeries[T](length, elements)
Parameters
| Name | Type | Description |
|---|---|---|
T | common.T | Element type |
length | int | Number of elements |
elements | Iterable[T] | Element values |
Exceptions
ValueErrorif the number of elements is invalid
UInt16, UInt32, UInt8
Same structure as Int16, Int32, Int8 respectively with class names and descriptions updated accordingly:
- Class to store a 16/32/8-bit unsigned integer
hex()method same as above