Growcube message

The GrowcubeMessage class is used as an abstraction of the protocol used to communicate with Growcube devices.

Growcube client library https://github.com/jonnybergdahl/Python-growcube-client

Author: Jonny Bergdahl Date: 2023-09-05

class growcube_client.growcubemessage.GrowcubeMessage(command: int, payload: str, data: bytes)

Bases: object

Growcube protocol message base class

Variables:
  • HEADER (str) – The header for a Growcube protocol message.

  • DELIMITER (str) – The delimiter used in the message.

  • END_DELIMITER (str) – The end delimiter used in the message.

  • EMPTY_MESSAGE (str) – An empty message used as a template.

  • _command – The command value.

  • _payload – The message payload.

  • _data – The complete message as bytes.

DELIMITER = '#'
EMPTY_MESSAGE = 'elea00###'
END_DELIMITER = '#'
HEADER = 'elea'
property command: int

Command value

Returns:

Command value.

Return type:

int

property data: bytes

The complete message as bytes

Returns:

The complete message as bytes.

Return type:

bytes

static from_bytes(data: bytearray) Tuple[int, GrowcubeMessage] | Tuple[int, None]

Tries to construct a complete GrowcubeMessage from the data and returns the index of the next non-consumed data in the buffer, together with the message. Converts a byte array to a GrowcubeMessage instance.

Parameters:

data (bytearray) – The current data buffer.

Returns:

The index of the next non-consumed data in the buffer, together with the message, or the next found start index and None if the message is incomplete.

Return type:

Tuple[int, GrowcubeMessage] or Tuple[int, None]

property payload: str

Message payload

Returns:

Message payload.

Return type:

str

static to_bytes(command: int, data: str) bytes

Creates a bytearray representation of a message as used in the protocol.

Parameters:
  • command (int) – Command value.

  • data (str) – Data to send.

Returns:

A bytearray representation of a message as used in the protocol.

Return type:

bytes