/      日本語

mwings.common Module

Stores data and procedures used throughout the library.

Contains data and procedures used throughout the library.

src/mwings/common.py

AccelEvent

Identifiers for accelerometer events

Inherits from: enum.IntEnum

  • DICE_1 Dice: 1
  • DICE_2 Dice: 2
  • DICE_3 Dice: 3
  • DICE_4 Dice: 4
  • DICE_5 Dice: 5
  • DICE_6 Dice: 6
  • SHAKE Shake
  • MOVE Move
  • NONE No event

AppPalNoticeBlinkSpeed

Identifiers for AppPal notification blink speed

Inherits from: enum.IntEnum

  • ALWAYS_ON Always on
  • SLOW Slow blinking
  • MEDIUM Moderate blinking
  • FAST Fast blinking

AppPalNoticeColor

Identifiers for AppPal notification colors

Inherits from: enum.IntEnum

  • RED Red
  • GREEN Green
  • BLUE Blue
  • YELLOW Yellow
  • PURPLE Purple
  • LIGHT_BLUE Light blue
  • WHITE White
  • WARM_WHITE Warm white

AppPalNoticeRGBWColor

Notification color expressed in RGBW format

Inherits from: pydantic.BaseModel

AppPalNoticeRGBWColor()

AppPalNoticeRGBWColor(*, red=0, green=0, blue=0, white=15)

Parameters

NameTypeDescription
redcommon.UInt8Red: 00xF
greencommon.UInt8Green: 00xF
bluecommon.UInt8Blue: 00xF
whitecommon.UInt8White: 00xF

You may pass a dictionary using ** unpacking.

u16()

u16()

Returns a 16-bit RGBW representation.

Parameters

None

Returns

TypeValueDescription
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

NameTypeDescription
payloadbytesBinary payload data
checksumoptional common.UInt8LRC8: Automatically calculated if None
logical_and_command_idoptional 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

NameTypeDescription
indexintPosition in payload

Returns

TypeValueDescription
common.Int16-Numeric data

i32_at()

i32_at(index)

Gets a signed 32-bit integer from the specified position.

Parameters

NameTypeDescription
indexintPosition in payload

Returns

TypeValueDescription
common.Int32-Numeric data

i8_at()

i8_at(index)

Gets a signed 8-bit integer from the specified position.

Parameters

NameTypeDescription
indexintPosition in payload

Returns

TypeValueDescription
common.Int8-Numeric data

u16_at()

u16_at(index)

Gets an unsigned 16-bit integer from the specified position.

Parameters

NameTypeDescription
indexintPosition in payload

Returns

TypeValueDescription
common.UInt16-Numeric data

u32_at()

u32_at(index)

Gets an unsigned 32-bit integer from the specified position.

Parameters

NameTypeDescription
indexintPosition in payload

Returns

TypeValueDescription
common.UInt32-Numeric data

u8_at()

u8_at(index)

Gets an unsigned 8-bit integer from the specified position.

Parameters

NameTypeDescription
indexintPosition in payload

Returns

TypeValueDescription
common.UInt8-Numeric data

u8_from()

u8_from(index)

Gets a byte sequence starting from the specified index.

Parameters

NameTypeDescription
indexintStarting index in payload

Returns

TypeValueDescription
optional bytesbytesPartial byte sequence
NoneInvalid index

CommandBase

Abstract base class for commands

Inherits from: ABC, pydantic.BaseModel

CommandBase()

CommandBase(*, destination_logical_id=120)

Parameters

NameTypeDescription
destination_logical_idcommon.UInt8Logical 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

TypeValueDescription
boolTrueValid
FalseInvalid

CommandSerializerBase

Static abstract base class for command serializers

Inherits from: ABC

serialize()

serialize(command)

Expands the given command into a raw byte sequence.

Parameters

NameTypeDescription
commandcommon.SomeCommandA command data object

Returns

TypeValueDescription
optional common.BarePacketcommon.BarePacketExpanded packet data
NoneInvalid 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

NameTypeDescription
Tcommon.TElement type
lengthintNumber of elements
elementsIterable[T]Element values

Exceptions

  • ValueError if 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

TypeValueDescription
str-dtype identifier

FixedList[T]

A class representing a fixed-length list

Inherits from: MutableSequence[T]

FixedList[T]()

FixedList[T](length, initial_elements)

Parameters

NameTypeDescription
Tcommon.TType of elements
lengthintNumber of elements
initial_elementsIterable[T]Initial elements

Exceptions

  • ValueError if the number of elements is invalid

insert()

insert(index, value)

Inserts an element at the specified index.

Parameters

NameTypeDescription
indexintIndex to insert
valuecommon.TElement to insert

Returns

None

Exceptions

  • IndexError if the index is invalid

FixedTuple[T]

Class representing a fixed-length tuple

Inherits from: Sequence[T]

FixedTuple[T]()

FixedTuple[T](length, elements)

Parameters

NameTypeDescription
Tcommon.TType of elements
lengthintNumber of elements
elementsIterable[T]Elements

Exceptions

  • ValueError if 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

NameTypeDescription
valueoptional floatInitial value

Exceptions

  • ValueError if 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

NameTypeDescription
valueoptional floatInitial value

Exceptions

  • ValueError if the value is out of range

Int16

Class to store a 16-bit integer

Inherits from: int, common.DtypedDecimal

Int16()

Int16(value=None)

Parameters

NameTypeDescription
valueoptional intInitial value

Exceptions

  • ValueError if 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

TypeValueDescription
str-Hexadecimal string (lowercase)

Int32

Class to store a 32-bit integer

Inherits from: int, common.DtypedDecimal

Int32()

Int32(value=None)

Parameters

NameTypeDescription
valueoptional intInitial value

Exceptions

  • ValueError if 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

NameTypeDescription
valueoptional intInitial value

Exceptions

  • ValueError if the value is out of range

hex()

Same as in Int16

MagnetState

Identifiers for magnet events

Inherits from: enum.IntEnum

  • NOT_DETECTED No magnet
  • N_POLE_IS_CLOSE N pole is close
  • S_POLE_IS_CLOSE S 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

NameTypeDescription
Tcommon.TElement type
lengthintNumber of elements
elementsIterable[T]Element values

Exceptions

  • ValueError if 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