Growcube client

GrowcubeClient is the main client for communicating with a Growcube device.

class growcube_client.growcubeclient.GrowcubeClient(host: str, on_message_callback: Callable[[GrowcubeReport], Awaitable[None]], on_connected_callback: Callable[[str], Awaitable[None]] = None, on_disconnected_callback: Callable[[str], Awaitable[None]] = None, log_level: int = 20)

Bases: object

Growcube client class

Variables:
  • host – The name or IP address of the Growcube device.

  • port – The port number for the connection. (Default: 8800)

  • _on_message_callback – Callback function to receive data from the Growcube.

  • _on_connected_callback – Callback function for when the connection is established.

  • _on_disconnected_callback – Callback function for when the connection is lost.

  • log_level – Logging level. (Default: logging.INFO)

  • _exit – Internal flag indicating if the client is exiting.

  • _data – Buffer to accumulate received data.

  • transport – The transport instance associated with the protocol.

  • protocol – The protocol instance associated with the connection.

  • connected – Indicates whether the client is connected to the Growcube.

  • connection_timeout – Timeout for connection attempts. (Default: 5 seconds)

async connect() Tuple[bool, str]

Connect to the Growcube and start listening for data.

Returns:

A tuple. True and an empty string if the connection was successful, otherwise False and the error message.

Return type:

Tuple[bool, str]

disconnect() None

Disconnect from the Growcube

Returns:

None

host: str
on_connected() None

Callback function for when the connection is established

on_connection_lost() None

Callback function for when the connection is lost

Returns:

None

Return type:

None

on_message(message: GrowcubeMessage) None

Callback function for when a message is received from the Growcube

Parameters:

message (GrowcubeMessage) – The received GrowcubeMessage.

send_command(command: GrowcubeCommand) bool

Send a command to the Growcube.

Parameters:

command (GrowcubeCommand) – A GrowcubeCommand object.

Returns:

True if the command was sent successfully, otherwise False.

Return type:

bool

async send_keep_alive(interval: int) None

Send a keep alive, we are using the SetWorkModeCommand for this

Parameters:

interval (int) – How often to send keep alive message

Returns:

None

async water_plant(channel: Channel, duration: int) bool

Water a plant for a given duration. This function will block until the watering is complete.

Parameters:
  • channel (Channel) – Channel number 0-3.

  • duration (int) – Duration in seconds.

Returns:

True if the watering was successful, otherwise False.

Return type:

bool