mwingslite package

mwingslite module

final class mwingslite.Twelite(port=None, rx_buffer_size=1024, timeout=100, tz=None, debugging=False)[source]

Bases: Thread

MWings main class

Constructor

Parameters:
  • port (str | None) – Name for the serial port to use / set None to disable serial

  • rx_buffer_size (int) – Receive buffer size

  • timeout (int) – Timeout for each packet in milliseconds

  • tz (tzinfo) – Timezone for datetime data. Default is UTC (Aware). Use ZoneInfo() for others.

  • debugging (bool) – Print debug info if true

add_listener(event: PacketType, handler: Callable[[BarePacket], None]) None[source]
add_listener(event: PacketType, handler: Callable[[SomeParsedPacket], None]) None

Register a handler for receiving packets

Parameters:
clear_input()[source]

Clear input buffer of serial and packets

Return type:

None

close()[source]

Close the serial port if opened

Return type:

None

on(event)[source]

Generate a decorator to register a handler for receiving packets

Parameters:

event (common.PacketType) – Identifier for packets to receive

Returns:

Decorator to register a handler for receiving packets

Return type:

Callable[[common.SomeCallable], common.SomeCallable]

parse(character: str, use_lf: bool = False) PacketType | None[source]
parse(character: bytes, use_lf: bool = False) PacketType | None
parse(character: int, use_lf: bool = False) PacketType | None

Parse a single character

Parameters:
  • character (Any) – character to parse

  • use_lf (bool) – If use LF instead of CRLF, set True

Returns:

If completed, returns packet type identifier

Return type:

common.PacketType | None

Raises:
  • RuntimeError – Serial IS initialized

  • ValueError – Unsupported character

parse_line(line, use_lf=True)[source]

Parse a single string

Useful when use local log file instead of serial port rx

Parameters:
  • line (str) – String line

  • use_lf (bool) – Use LF instead of CRLF (For f.readline, set True as default)

Returns:

Latest packet type identifier if available else None

Return type:

common.PacketType | None

Raises:

RuntimeError – Serial IS initialized

receive()[source]

Wait for parsing of a single packet

Returns:

Identifier for packet received

Return type:

common.PacketType

Notes

This function blocks current thread

remove_all_listeners(event)[source]

Remove all handlers for receicing packets

Parameters:

event (common.PacketType) – Identifier for packets to receive

Return type:

None

run()[source]

Run the thread to receive continuously

Call this function via Twelite.start()

Notes

Overrides threading.Thread.run()

Return type:

None

send(data: BarePacket) bool[source]
send(data: SomeCommand) bool

Send data to the device with ModBus format

Parameters:

data (Any) – Data to send

Returns:

True if succeeded

Return type:

bool

static set_timezone(tz)[source]

Set timezone for received data

Parameters:

tz (tzinfo) – tzinfo object. Typically Zoneinfo(“IANA/City”). None for UTC.

Return type:

None

start()[source]

Start the thread to receive continuously

Notes

Overrides threading.Thread.start()

Return type:

None

stop()[source]

Stop the thread to receive continuously

Return type:

None

property timezone: tzinfo

Get timezone set

Returns:

Timezone set for mwings

Return type:

tzinfo

update()[source]

Update parsing state with serial data

Returns:

Returns packet type identifier if available else None

Return type:

common.PacketType | None

Internal submodules

mwingslite.utils module

mwingslite.utils.ask_user(prompt, regex, on_error, ex_verifier=None, max_attempts=None)[source]

Ask user for something in text

Parameters:
  • prompt (str) – Prompt message

  • regex (str) – Regular expression for validate user input

  • on_error (str) – Message for invalid input

  • ex_verifier (Callable[[str], bool] | None) – Extra verifier in addition to regex

  • max_attempts (int | None) – Max count for attempts. None to infinite

Returns:

Valid user input

Return type:

str

mwingslite.utils.ask_user_for_port()[source]

Ask the user for the port to use

If there’s only one port, auto selects without asking.

Returns:

Port name (COM or fd)

Return type:

str

Notes

If the console is not available, raise EnvironmentError. If there’s no ports, raise IOError.

mwingslite.utils.byte_count_from(character_count)[source]

Convert to byte count from character count

Parameters:

character_count (int) – bytes count in ascii format

Returns:

bytes count in binary format

Return type:

int

mwingslite.utils.character_from(hexvalue)[source]

Convert to character from hex

Parameters:

hexvalue (int) – Binary integer value (0x0-0xF)

Returns:

Integer value of an ASCII character (‘0’-‘F’)

Return type:

int

mwingslite.utils.find_ascii(port, data, timeout, debugging=False)[source]

Find ASCII-formatted bytes in serial rx data

Parameters:
  • port (serial.Serial) – pyserial instance

  • data (str) – ASCII-formatted bytes to find

  • timeout (int) – Timeout in seconds

  • debugging (bool) – Print debug info if true

Returns:

Found if true

Return type:

bool

mwingslite.utils.find_binary(port, data, timeout, with_terminal=False, terminal=0, debugging=False)[source]

Find binary bytes in serial rx data

Parameters:
  • port (serial.Serial) – pyserial instance

  • data (bytes) – Binary data bytes to find

  • timeout (int) – Timeout in seconds

  • with_terminal (bool) – Use terminal byte for data input or not

  • terminal (int) – Terminal byte for data input

  • debugging (bool) – Print debug info if true

Returns:

Found if true

Return type:

bool

mwingslite.utils.flush_rx_buffer(port)[source]

Flush serial rx buffer

Parameters:

port (serial.Serial) – pyserial instance

Return type:

None

mwingslite.utils.flush_tx_buffer(port)[source]

Flush serial tx buffer

Parameters:

port (serial.Serial) – pyserial instance

Return type:

None

mwingslite.utils.get_ports()[source]

Get port informations

Returns:

List of port names

Return type:

list[str]

mwingslite.utils.hex_from(character)[source]

Convert to hex from character

Parameters:

character (int) – Integer value of an ASCII character (‘0’-‘F’)

Returns:

Binary integer value (0x0-0xF)

Return type:

int

mwingslite.utils.is_initialized(port)[source]

Check if the serial port is initialized

Parameters:

port (serial.Serial) – pyserial instance

Returns:

initialized if true

Return type:

bool

mwingslite.utils.is_readable(port)[source]

Check if the serial port is readable

Parameters:

port (serial.Serial) – pyserial instance

Returns:

readable if true

Return type:

bool

mwingslite.utils.is_there_some_ports()[source]

Check if there is some ports exists

Returns:

True if exists

Return type:

bool

mwingslite.utils.is_writable(port)[source]

Check if the serial port is writable

Parameters:

port (serial.Serial) – pyserial instance

Returns:

writable if true

Return type:

bool

mwingslite.utils.lrc8(data)[source]

Calculate 8-bit LRC for given data

Parameters:

data (bytes) – Bytes to calculate

Returns:

LRC checksum

Return type:

int

mwingslite.utils.millis()[source]

Get current time in milliseconds

Returns:

Current epoch in milliseconds

Return type:

int

mwingslite.utils.open_on_system(path)[source]

Open the file in the given path on system using default application

Parameters:

path (Path) – pathlib.Path for file

Return type:

None

mwingslite.utils.write_binary(port, data)[source]

Write binary integer value to the serial port

Parameters:
  • port (serial.Serial) – pyserial instance

  • data (int | bytes) – Binary integer value or bytes

Return type:

None

mwingslite.utils.write_in_ascii(port, data)[source]

Write binary in ASCII format to the serial port

Parameters:
  • port (serial.Serial) – pyserial instance

  • data (int) – Binary integer value or bytes

Return type:

None

mwingslite.common module

final class mwingslite.common.AccelEvent(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Event ID for state of the magnet sensor

DICE_1

Dice roll: 1

Type:

int

DICE_2

Dice roll: 2

Type:

int

DICE_3

Dice roll: 3

Type:

int

DICE_4

Dice roll: 4

Type:

int

DICE_5

Dice roll: 5

Type:

int

DICE_6

Dice roll: 6

Type:

int

SHAKE

Shake

Type:

int

MOVE

Move

Type:

int

NONE

No events

Type:

int

final class mwingslite.common.AppPalNoticeBlinkSpeed(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Blinking speed ID for App_PAL (NOTICE)

ALWAYS_ON

Always on

Type:

int

SLOW

Slow blinking

Type:

int

MEDIUM

Medium blinking

Type:

int

FAST

Fast blinking

Type:

int

final class mwingslite.common.AppPalNoticeColor(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Color ID for App_PAL (NOTICE)

RED

RED color

Type:

int

GREEN

GREEN color

Type:

int

BLUE

BLUE color

Type:

int

YELLOW

YELLOW color

Type:

int

PURPLE

PURPLE color

Type:

int

LIGHT_BLUE

LIGHT_BLUE color

Type:

int

WHITE

WHITE color

Type:

int

WARM_WHITE

WARM_WHITE color

Type:

int

final class mwingslite.common.AppPalNoticeRGBWColor(*, red=0, green=0, blue=0, white=15)[source]

Bases: BaseModel

Color in RGBW for App_PAL (NOTICE)

Parameters:
  • red (int)

  • green (int)

  • blue (int)

  • white (int)

red

Red value 0-0xF

Type:

UInt8

green

Green value 0-0xF

Type:

UInt8

blue

Blue value 0-0xF

Type:

UInt8

white

White value 0-0xF

Type:

UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

u16()[source]

Returns UInt16 representation

Returns:

RGBW as UInt16

Return type:

UInt16

final class mwingslite.common.BarePacket(payload, checksum=None, logical_and_command_id=None)[source]

Bases: BaseModel

Bare packet dataclass

payload

Data payload

Type:

bytes

checksum

LRC checksum for data payload

Type:

UInt8

Overridden constructor

Parameters:
  • payload (bytes) – Payload data

  • checksum (UInt8, optional) – LRC8 checksum

  • logical_and_command_id (tuple[UInt8, UInt8], optional) – Logical ID and Command ID (if set, payload should be shorter

i16_at(index)[source]

Get 2 bytes as an signed integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

Int16

i32_at(index)[source]

Get 4 bytes as an signed integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

Int32

i8_at(index)[source]

Get 1 byte as a signed integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

Int8

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

u16_at(index)[source]

Get 2 bytes as an unsigned integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

UInt16

u32_at(index)[source]

Get 4 bytes as an unsigned integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

UInt32

u8_at(index)[source]

Get 1 byte as an unsigned integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

UInt8

u8_from(index)[source]

Get bytes from the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else None

Return type:

bytes | None

class mwingslite.common.CommandBase(*, destination_logical_id=120)[source]

Bases: ABC, BaseModel

Base dataclass for commands

Parameters:

destination_logical_id (int)

destination_logical_id

Logical ID for the source device

Type:

UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

abstract is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Pure virtual function

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mwingslite.common.CommandSerializerBase[source]

Bases: ABC

Base class for packet serializers

abstract static serialize(command)[source]

Serialize the given command

Parameters:

command (SomeCommand) – Some command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

BarePacket | None

class mwingslite.common.CrossSectional(length, elements)[source]

Bases: FixedTuple[T]

Tuple for cross-sectional data such as ADC voltages

Constructor for the sequence

Parameters:
  • length (int) – Fixed length

  • elements (Iterable[T]) – Items to contain

Raises:

ValueError – Invalid length

class mwingslite.common.DtypedDecimal[source]

Bases: ABC

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

class mwingslite.common.FixedList(length, initial_elements)[source]

Bases: MutableSequence[T]

List with fixed length

Constructor for the sequence

Parameters:
  • length (int) – Fixed length

  • initial_elements (Iterable[T]) – Initial items in iterable representation

Raises:

ValueError – Invalid length

append(value)[source]

Append an item

Parameters:

value (T) – Value of the item to append

Raises:

IndexError – FixedList does not support append()

Return type:

None

extend(values)[source]

Extend the sequence

Parameters:

values (Iterable[T]) – Sequence to extend

Raises:

IndexError – FixedList does not support extend()

Return type:

None

insert(index, value)[source]

Insert an item for the specific index

Parameters:
  • index (int) – Index to insert

  • value (T) – Value of item to insert

Raises:

IndexError – Out of range

Return type:

None

pop(index=-1)[source]

Pop an item

Parameters:

index (int) – Index to pop

Returns:

An poped item

Return type:

T

Raises:

RuntimeError – FixedList does not support pop()

remove(value)[source]

Remove an item

Parameters:

value (T) – Value of item to remove

Raises:

RuntimeError – FixedList does not support remove()

Return type:

None

class mwingslite.common.FixedTuple(length, elements)[source]

Bases: Sequence[T]

Tuple with fixed length

Constructor for the sequence

Parameters:
  • length (int) – Fixed length

  • elements (Iterable[T]) – Items to contain

Raises:

ValueError – Invalid length

class mwingslite.common.Float32(value=None)[source]

Bases: float, DtypedDecimal

Parameters:

value (float | None)

Return type:

Float32

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

class mwingslite.common.Float64(value=None)[source]

Bases: float, DtypedDecimal

Parameters:

value (float | None)

Return type:

Float64

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

class mwingslite.common.Int16(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

Int16

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

class mwingslite.common.Int32(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

Int32

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

class mwingslite.common.Int8(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

Int8

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

final class mwingslite.common.MagnetState(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Event ID for state of the magnet sensor

For App_ARIA, App_CUE and App_PAL(OPENCLOSE)

NOT_DETECTED

No magnet

Type:

int

N_POLE_IS_CLOSE

N pole is close

Type:

int

S_POLE_IS_CLOSE

S pole is close

Type:

int

class mwingslite.common.PacketParserBase[source]

Bases: ABC

Base class for packet parsers

abstract static is_valid(bare_packet)[source]

Check if the given bare packet is valid or not

Parameters:

bare_packet (BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Pure virtual function

abstract static parse(bare_packet)[source]

Parse the given bare packet

Parameters:

bare_packet (BarePacket) – Bare packet content

Returns:

Parsed packet content if valid otherwise None

Return type:

ParsedPacketBase | None

Notes

Pure virtual function

final class mwingslite.common.PacketType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: StrEnum

Packet type identifier for receiving handlers

BARE

Identifier for bare packets

Type:

str

ACT

Identifier for act packets

Type:

str

APP_TWELITE

Identifier for App_Twelite packets

Type:

str

APP_IO

Identifier for App_IO packets

Type:

str

APP_ARIA

Identifier for App_ARIA packets

Type:

str

APP_CUE

Identifier for App_CUE packets

Type:

str

APP_CUE_PAL_EVENT

Identifier for App_CUE (PAL Move or Dice mode) packets

Type:

str

APP_PAL_OPENCLOSE

Identifier for App_PAL (OPENCLOSE) packets

Type:

str

APP_PAL_AMB

Identifier for App_PAL (AMB) packets

Type:

str

APP_PAL_MOT

Identifier for App_PAL (MOT) packets

Type:

str

APP_UART_ASCII

Identifier for App_Uart (Mode A) packets

Type:

str

APP_UART_ASCII_EXTENDED

Identifier for App_Uart (Mode A, Extended) packets

Type:

str

class mwingslite.common.ParsedPacketBase(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None)[source]

Bases: ABC, BaseModel

Base dataclass for data of parsed packets

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (int | None)

  • source_serial_id (int)

  • source_logical_id (int)

  • lqi (int | None)

  • supply_voltage (int | None)

mwings_implementation

Implementation of mwings; In this case: “python”

Type:

str

mwings_version

Version of mwings in PEP440 format declared in the pyproject.toml

Type:

str

time_parsed

Date and time parsed in ISO 8601 format

Type:

str | None

hostname

Hostname for the running system

Type:

str

system_type

System type for the running system (e.g. “Linux”)

Type:

str

packet_type

Type of the received packet

Type:

PacketType

sequence_number

Sequence number for the packet

Type:

UInt16

source_serial_id

Serial ID for the source device

Type:

UInt32

source_logical_id

Logical ID for the source device

Type:

UInt8

lqi

Link quality indicator for the source device (Max: 255)

Type:

UInt8

supply_voltage

Supply voltage for the source device in mV

Type:

UInt16

Notes

Immutable (frozen) object

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_source_logical_id(lid)[source]

Check source logical id

Must be in range between 0 and 100 or 120 and 127

Parameters:

lid (UInt8) – Input

Returns:

Valid input

Return type:

UInt8

Raises:

ValueError – Out of range

classmethod datetime_must_be_clear(dt)[source]

Check time received

Must be aware timezone as mw.common.Timezone

Parameters:

dt (datetime) – Input

Returns:

Valid input

Return type:

datetime

Raises:

ValueError – Native or not same as mw.common.Timezone

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

serialize_packet_type(packet_type)[source]

Print packet_type in readable names for JSON or something

Parameters:

packet_type (PacketType) – Type of the packet

Returns:

Serialized text for JSON or something

Return type:

str

serialize_source_serial_id(source_serial_id)[source]

Print source_serial_id in HEX for JSON or something

Parameters:

source_serial_id (UInt32) – Source serial ID

Returns:

Serialized text for JSON or something

Return type:

str

serialize_time_parsed(dt)[source]

Print time_parsed in ISO 8601 format

Parameters:

dt (datetime, optional) – Date and time received

Returns:

Serialized text for JSON or something

Return type:

str | None

Notes

Date and time should be UTC, but python uses “+00:00” suffix instead of “Z”. However, it can be parsed in other environments like ECMAScript’s Date().

to_df(include=None, exclude=None, verbose=True)[source]

Export to a pandas DataFrame

Requires optional dependency: pandas

Parameters:
  • include (set[str], optional) – Columns to include in the DataFrame

  • exclude (set[str], optional) – Columns to include in the DataFrame

  • verbose (bool) – Set False to exclude system information. Only valid if include and exclude are None.

Returns:

Output DataFrame

Return type:

pd.DataFrame

Raises:

EnvironmentError – No pandas found

to_dict(include=None, exclude=None, verbose=True, spread=False, sort_keys=False)[source]

Export to a dictionary (or OrderedDict)

Parameters:
  • include (set[str], optional) – Properties to include in the dictionary

  • exclude (set[str], optional) – Properties to exclude in the dictionary

  • verbose (bool) – Set False to exclude system information. Only valid if include and exclude are None.

  • spread (bool) – Spread cross-sectional tuple values into separated properties if True

  • sort_keys (bool) – Returns a sorted OrderedDict if True

Returns:

Output dictionary (or OrderedDict)

Return type:

dict[str, Any]

Notes

Higher-level implementation of pydantic’s model_dump()

to_json(include=None, exclude=None, verbose=True, spread=False, indent=2, sort_keys=False)[source]

Export to a JSON string

Parameters:
  • include (set[str], optional) – Properties to include the JSON

  • exclude (set[str], optional) – Properties to exclude the JSON

  • verbose (bool) – Set False to exclude system information. Only valid if include and exclude are None.

  • spread (bool) – Spread cross-sectional tuple values into separated properties if True

  • indent (int, optional) – Space-indentation width (default: 2, None to single-line)

  • sort_keys (bool) – Sort properties by keys if True

Returns:

Output JSON

Return type:

str

class mwingslite.common.SomeCallable

TypeVar for handlers

alias of TypeVar(‘SomeCallable’, bound=Callable[[…], Any])

class mwingslite.common.SomeCommand

TypeVar for all classes derived from CommandBase

alias of TypeVar(‘SomeCommand’, bound=CommandBase)

class mwingslite.common.SomeParsedPacket

TypeVar for all classes derived from ParsedPacketBase

alias of TypeVar(‘SomeParsedPacket’, bound=ParsedPacketBase)

class mwingslite.common.T

TypeVar for generics

alias of TypeVar(‘T’)

class mwingslite.common.TimeSeries(length, elements)[source]

Bases: FixedTuple[T]

Tuple for time series data such as acceleration samples

Constructor for the sequence

Parameters:
  • length (int) – Fixed length

  • elements (Iterable[T]) – Items to contain

Raises:

ValueError – Invalid length

mwingslite.common.Timezone: tzinfo = datetime.timezone.utc

Global tzinfo

class mwingslite.common.UInt16(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

UInt16

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

class mwingslite.common.UInt32(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

UInt32

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

class mwingslite.common.UInt8(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

UInt8

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

mwingslite.parsers module

mwingslite.parsers.app_twelite module

final class mwingslite.parsers.app_twelite.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_Twelite

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.app_twelite.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, destination_logical_id=120, relay_count=0, periodic=False, di_changed=<mwingslite.common.CrossSectional object>, di_state=<mwingslite.common.CrossSectional object>, ai_voltage=<mwingslite.common.CrossSectional object>)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_Twelite

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • destination_logical_id (int)

  • relay_count (Annotated[int, Ge(ge=0), Le(le=3)])

  • periodic (bool)

  • di_changed (CrossSectional[bool])

  • di_state (CrossSectional[bool])

  • ai_voltage (CrossSectional[UInt16])

destination_logical_id

Logical ID for the destination (parent) device

Type:

common.UInt8

relay_count

Number of relay stations

Type:

common.UInt8

periodic

True if the packet is a periodic transmit packet

Type:

bool

di_changed

State for each digital interfaces; True if changed

Type:

common.CrossSectional[bool]

di_state

Input status for each digital interfaces

Type:

common.CrossSectional[bool]

ai_voltage

Voltage in mV for each analog interfaces

Type:

common.CrossSectional[common.UInt16]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_ai_voltage(aiv)[source]

Check voltage of analog interfaces

Must be in range between 0 and 3700 (VCCmax3600+margin100)

Parameters:

aiv (common.CrossSectional) – Input

Returns:

Valid input

Return type:

common.CrossSectional

Raises:

ValueError – Out of range

classmethod check_destination_logical_id(lid)[source]

Check destination lid

Must be in range between 0 and 100 or 120 and 127 but 122 (Router) is invalid

Parameters:

lid (int) – Input

Returns:

Valid input

Return type:

int

Raises:

ValueError – Out of range

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

mwingslite.parsers.app_io module

final class mwingslite.parsers.app_io.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_IO

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.app_io.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, relay_count=0, di_state=<mwingslite.common.CrossSectional object>, di_valid=<mwingslite.common.CrossSectional object>, di_interrupt=<mwingslite.common.CrossSectional object>)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_IO

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • relay_count (Annotated[int, Ge(ge=0), Le(le=3)])

  • di_state (CrossSectional[bool])

  • di_valid (CrossSectional[bool])

  • di_interrupt (CrossSectional[bool])

relay_count

Number of relay stations

Type:

common.UInt8

di_state

Input state for each DI ports

Type:

common.CrossSectional[bool]

di_valid

Valid state for each DI ports; True if used

Type:

common.CrossSectional[bool]

di_interrupt

Interrupt state for each DI ports; True if detected via ISR

Type:

common.CrossSectional[bool]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

mwingslite.parsers.app_aria module

final class mwingslite.parsers.app_aria.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_ARIA

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.app_aria.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, ai1_voltage=0, temp_100x=0, humid_100x=0, magnet_state=MagnetState.NOT_DETECTED, magnet_state_changed=False)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_ARIA

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • ai1_voltage (Annotated[int, Ge(ge=0), Le(le=3600)])

  • temp_100x (Annotated[int, Ge(ge=-4000), Le(le=12500)])

  • humid_100x (Annotated[int, Ge(ge=0), Le(le=10000)])

  • magnet_state (MagnetState)

  • magnet_state_changed (bool)

ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

temp_100x

100x temperature in °C

Type:

common.Int16

humid_100x

100x humidity in RH%

Type:

common.UInt16

magnet_state

Magnet state

Type:

common.MagnetState

magnet_state_changed

True if the magnet state was changed

Type:

bool

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

serialize_magnet_state(magnet_state)[source]

Print magnet_state in readable names for JSON or something

Parameters:

magnet_state (common.MagnetState) – Magnet state

Returns:

Serialized text for JSON or something

Return type:

str

mwingslite.parsers.app_cue module

final class mwingslite.parsers.app_cue.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_CUE

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.app_cue.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, ai1_voltage=0, sample_count=10, samples_x=<mwingslite.common.TimeSeries object>, samples_y=<mwingslite.common.TimeSeries object>, samples_z=<mwingslite.common.TimeSeries object>, has_accel_event=False, accel_event=AccelEvent.NONE, magnet_state=MagnetState.NOT_DETECTED, magnet_state_changed=False)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_CUE

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • ai1_voltage (Annotated[int, Ge(ge=0), Le(le=3600)])

  • sample_count (Annotated[int, Ge(ge=10), Le(le=10)])

  • samples_x (TimeSeries[Int16])

  • samples_y (TimeSeries[Int16])

  • samples_z (TimeSeries[Int16])

  • has_accel_event (bool)

  • accel_event (AccelEvent)

  • magnet_state (MagnetState)

  • magnet_state_changed (bool)

ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

sample_count

Number of accel samples

Type:

common.UInt8

samples_x

Accel samples for x axis

Type:

common.TimeSeries[common.Int16]

samples_y

Accel samples for y axis

Type:

common.TimeSeries[common.Int16]

samples_z

Accel samples for z axis

Type:

common.TimeSeries[common.Int16]

has_accel_event

True if an accel event is available

Type:

bool

accel_event

Accel event

Type:

common.AccelEvent

magnet_state

Magnet state

Type:

common.MagnetState

magnet_state_changed

True if the magnet state was changed

Type:

bool

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

serialize_accel_event(accel_event)[source]

Print accel_event in readable names for JSON or something

Parameters:

accel_event (common.AccelEvent) – Accel event

Returns:

Serialized text for JSON or something

Return type:

str

serialize_magnet_state(magnet_state)[source]

Print magnet_state in readable names for JSON or something

Parameters:

magnet_state (common.MagnetState) – Magnet state

Returns:

Serialized text for JSON or something

Return type:

str

mwingslite.parsers.app_cue_pal_event module

final class mwingslite.parsers.app_cue_pal_event.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_CUE (PAL Move or Dice mode)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.app_cue_pal_event.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, ai1_voltage=0, accel_event=AccelEvent.NONE)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_CUE (PAL Move or Dice mode)

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • ai1_voltage (Annotated[int, Ge(ge=0), Le(le=3700)])

  • accel_event (AccelEvent)

ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

accel_event

Accel event

Type:

common.AccelEvent

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

serialize_accel_event(accel_event)[source]

Print accel_event in readable names for JSON or something

Parameters:

accel_event (common.AccelEvent) – Accel event

Returns:

Serialized text for JSON or something

Return type:

str

mwingslite.parsers.app_pal_openclose module

final class mwingslite.parsers.app_pal_openclose.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_PAL (OPENCLOSE)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.app_pal_openclose.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, ai1_voltage=0, magnet_state=MagnetState.NOT_DETECTED, magnet_state_changed=False)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_PAL (OPENCLOSE)

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • ai1_voltage (Annotated[int, Ge(ge=0), Le(le=3700)])

  • magnet_state (MagnetState)

  • magnet_state_changed (bool)

ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

magnet_state

Magnet state

Type:

common.MagnetState

magnet_state_changed

True if the magnet state was changed

Type:

bool

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

serialize_magnet_state(magnet_state)[source]

Print magnet_state in readable names for JSON or something

Parameters:

magnet_state (common.MagnetState) – Magnet state

Returns:

Serialized text for JSON or something

Return type:

str

mwingslite.parsers.app_pal_amb module

final class mwingslite.parsers.app_pal_amb.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_PAL (AMB)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.app_pal_amb.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, ai1_voltage=0, temp_100x=0, humid_100x=0, illuminance=0)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_PAL (AMB)

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • ai1_voltage (Annotated[int, Ge(ge=0), Le(le=3700)])

  • temp_100x (Annotated[int, Ge(ge=-4000), Le(le=12500)])

  • humid_100x (Annotated[int, Ge(ge=0), Le(le=10000)])

  • illuminance (Annotated[int, Ge(ge=0), Le(le=157000)])

ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

temp_100x

100x temperature in °C

Type:

common.Int16

humid_100x

100x humidity in RH%

Type:

common.UInt16

illuminance

Illuminance in lux

Type:

common.UInt32

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

mwingslite.parsers.app_pal_mot module

final class mwingslite.parsers.app_pal_mot.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_PAL (MOT)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.app_pal_mot.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, ai1_voltage=0, sample_count=16, samples_x=<mwingslite.common.TimeSeries object>, samples_y=<mwingslite.common.TimeSeries object>, samples_z=<mwingslite.common.TimeSeries object>, sampling_frequency=25)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_PAL (MOT)

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • ai1_voltage (Annotated[int, Ge(ge=0), Le(le=3700)])

  • sample_count (Annotated[int, Ge(ge=16), Le(le=16)])

  • samples_x (TimeSeries[Int16])

  • samples_y (TimeSeries[Int16])

  • samples_z (TimeSeries[Int16])

  • sampling_frequency (int)

ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

sample_count

Number of accel samples

Type:

common.UInt8

samples_x

Accel samples for x axis

Type:

common.TimeSeries[common.Int16]

samples_y

Accel samples for y axis

Type:

common.TimeSeries[common.Int16]

samples_z

Accel samples for z axis

Type:

common.TimeSeries[common.Int16]

sampling_frequency

Sampling frequency in Hz

Type:

UInt16

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_sampling_frequency(freq)[source]

Check for sampling_frequency

Parameters:

freq (int) – Input

Returns:

Valid input

Return type:

int

Raises:

ValueError – Raise if the specified frequency is not supported

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

mwingslite.parsers.app_uart_ascii module

final class mwingslite.parsers.app_uart_ascii.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_Uart (Mode A)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.app_uart_ascii.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, command_id=0, data=b'')[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_Uart (Mode A)

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • command_id (Annotated[int, Ge(ge=0), Lt(lt=128)])

  • data (bytes)

command_id

Command ID

Type:

common.UInt8

data

Data body (Hidden in JSON or something)

Type:

bytes

data_base64

Data body in Base64 for JSON or something

Type:

str

data_hexstr

Data body in ASCII string

Type:

str

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_data(data)[source]

Check for data

Parameters:

data (bytes) – Input

Returns:

Valid input

Return type:

bytes

Raises:

ValueError – Byte length is not in range between 1 and 80

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

mwingslite.parsers.app_uart_ascii_extended module

class mwingslite.parsers.app_uart_ascii_extended.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_Uart (Mode A, Extended)

final static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

final static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

class mwingslite.parsers.app_uart_ascii_extended.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, destination_serial_id=120, command_id=0, data=b'')[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_Uart (Mode A, Extended)

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • destination_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • command_id (Annotated[int, Ge(ge=0), Lt(lt=128)])

  • data (bytes)

destination_serial_id

Serial ID for the destination (parent) device

Type:

common.UInt32

command_id

Command ID

Type:

common.UInt8

data

Data body (Hidden in JSON or something)

Type:

bytes

data_base64

Data body in Base64 for JSON or something

Type:

str

data_hexstr

Data body in ASCII string

Type:

str

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_data(data)[source]

Check for data

Parameters:

data (bytes) – Input

Returns:

Valid input

Return type:

bytes

Raises:

ValueError – Byte length is not in range between 1 and 80

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

mwingslite.parsers.act module

final class mwingslite.parsers.act.PacketParser[source]

Bases: PacketParserBase

Packet parser for act

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwingslite.parsers.act.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, command_id=0, data=b'')[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from act

Parameters:
  • time_parsed (AwareDatetime | None)

  • packet_type (PacketType)

  • sequence_number (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • source_serial_id (Annotated[int, Ge(ge=0), Le(le=4294967295)])

  • source_logical_id (int)

  • lqi (Annotated[int | None, Ge(ge=0), Le(le=255)])

  • supply_voltage (Annotated[int | None, Ge(ge=0), Le(le=65535)])

  • command_id (Annotated[int, Ge(ge=0), Lt(lt=127)])

  • data (bytes)

command_id

Command ID

Type:

common.UInt8

data

Data body (Hidden in JSON or something)

Type:

bytes

data_base64

Data body in Base64 for JSON or something

Type:

str

data_hexstr

Data body in ASCII string

Type:

str

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

mwingslite.serializers module

mwingslite.serializers.app_twelite module

final class mwingslite.serializers.app_twelite.Command(*, destination_logical_id=120, di_to_change=<mwingslite.common.FixedList object>, di_state=<mwingslite.common.FixedList object>, pwm_to_change=<mwingslite.common.FixedList object>, pwm_duty=<mwingslite.common.FixedList object>)[source]

Bases: CommandBase

Dataclass for App_Twelite command

Parameters:
di_to_change

To enable modification on a specific digital interface, set True

Type:

common.FixedList[bool]

di_state

Output status for each digital interfaces

Type:

common.FixedList[bool]

pwm_to_change

To enable modification on a specific PWM interface, set True

Type:

common.FixedList[bool]

pwm_duty

Duty for each PWM interfaces (0 to 1024, can be disabled with 0xFFFF)

Type:

common.FixedList[bool]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

final class mwingslite.serializers.app_twelite.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_Twelite

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_Twelite command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwingslite.serializers.app_io module

final class mwingslite.serializers.app_io.Command(*, destination_logical_id=120, di_to_change=<mwingslite.common.FixedList object>, di_state=<mwingslite.common.FixedList object>)[source]

Bases: CommandBase

Dataclass for App_Io command

Parameters:
di_to_change

To enable modification on a specific digital interface, set True

Type:

common.FixedList[bool]

di_state

Output status for each digital interfaces

Type:

common.FixedList[bool]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

final class mwingslite.serializers.app_io.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_Io

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_Io command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwingslite.serializers.app_pal_notice module

final class mwingslite.serializers.app_pal_notice.Command(*, destination_logical_id=120, color=AppPalNoticeColor.WHITE, blink_speed=AppPalNoticeBlinkSpeed.ALWAYS_ON, brightness=8, duration_in_sec=5)[source]

Bases: CommandBase

Dataclass for App_PAL (NOTICE) command

Parameters:
  • destination_logical_id (int)

  • color (AppPalNoticeColor)

  • blink_speed (AppPalNoticeBlinkSpeed)

  • brightness (Annotated[int, Ge(ge=0), Le(le=15)])

  • duration_in_sec (Annotated[int, Ge(ge=0), Le(le=255)])

color

Color

Type:

common.AppPalNoticeColor

Blinking speed

Type:

common.AppPalNoticeBlinkSpeed

brightness

Brightness from 0 to 0xF

Type:

common.UInt8

duration_in_sec

Duration in seconds

Type:

common.UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Print blink_speed in readable names for JSON or something

Parameters:

blink_speed (common.AppPalNoticeBlinkSpeed) – Blinking speed

Returns:

Serialized text for JSON or something

Return type:

str

serialize_color(color)[source]

Print color in readable names for JSON or something

Parameters:

color (common.AppPalNoticeColor) – Color

Returns:

Serialized text for JSON or something

Return type:

str

final class mwingslite.serializers.app_pal_notice.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_PAL (NOTICE)

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_PAL (NOTICE) command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwingslite.serializers.app_pal_notice_detailed module

final class mwingslite.serializers.app_pal_notice_detailed.Command(*, destination_logical_id=120, color=AppPalNoticeRGBWColor(red=0, green=0, blue=0, white=15), blink_duty_percentage=100, blink_period_in_sec=1.0, duration_in_sec=1)[source]

Bases: CommandBase

Dataclass for App_PAL (NOTICE) detailed command

Parameters:
  • destination_logical_id (int)

  • color (AppPalNoticeRGBWColor)

  • blink_duty_percentage (Annotated[int, Ge(ge=0), Le(le=100)])

  • blink_period_in_sec (Annotated[float, Ge(ge=0.0), Le(le=10.2)])

  • duration_in_sec (Annotated[int, Le(le=255)])

color

Color in RGBW (0-0xF)

Type:

common.AppPalNoticeRGBWColor

Blink duty in %

Type:

common.UInt8

Blink period in sec (0-10.2)

Type:

common.Float64

duration_in_sec

Duration in seconds

Type:

common.UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

final class mwingslite.serializers.app_pal_notice_detailed.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_PAL (NOTICE)

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_PAL (NOTICE) command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwingslite.serializers.app_pal_notice_event module

final class mwingslite.serializers.app_pal_notice_event.Command(*, destination_logical_id=120, event_id=0)[source]

Bases: CommandBase

Dataclass for App_PAL (NOTICE) event command

Parameters:
  • destination_logical_id (int)

  • event_id (Annotated[int, Ge(ge=0), Le(le=16)])

event_id

Event id

Type:

common.UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

final class mwingslite.serializers.app_pal_notice_event.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_PAL (NOTICE)

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_PAL (NOTICE) command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwingslite.serializers.app_uart_ascii module

final class mwingslite.serializers.app_uart_ascii.Command(*, destination_logical_id=120, command_id=0, data)[source]

Bases: CommandBase

Dataclass for App_UART (Mode A) command

Parameters:
  • destination_logical_id (int)

  • command_id (Annotated[int, Ge(ge=0), Lt(lt=128)])

  • data (Annotated[bytes, MinLen(min_length=1), MaxLen(max_length=80)])

command_id

Command id

Type:

common.UInt8

data

Data to send

Type:

bytes

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

final class mwingslite.serializers.app_uart_ascii.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_Uart (Mode A)

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_Uart (Mode A) command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method