Growcube protocol
GrowcubeProtocol is custom asyncio Protocol for communication with a Growcube device.
- class growcube_client.growcubeprotocol.GrowcubeProtocol(on_connected: Callable[[], None], on_message: Callable[[GrowcubeMessage], None], on_connection_lost: Callable[[], None])
Bases:
ProtocolImplements a custom asyncio Protocol for communication with a Growcube device.
This protocol is designed to handle the communication between a client and a Growcube device. It includes methods for handling connection events, receiving and processing data, and sending messages to the device.
- Parameters:
on_connected (Callable[[str], None]) – A callback function to be executed when the connection is established.
on_message (Callable[[str], None]) – A callback function to be executed when a message is received.
on_connection_lost (Callable[[], None]) – A callback function to be executed when the connection is lost.
- Variables:
transport – The transport instance associated with the protocol.
_data – A buffer to accumulate received data.
_on_connected – Callback function for connection established event.
_on_message – Callback function for message received event.
_on_connection_lost – Callback function for connection lost event.
- connection_lost(exc: Exception) None
Called when the connection is lost.
- Parameters:
exc (Exception) – An exception indicating the reason for the connection loss.
- connection_made(transport) None
Called when a connection is made.
- Parameters:
transport (asyncio.Transport) – The transport instance associated with the connection.
- data_received(data) None
Called when data is received.
- Parameters:
data (bytes) – The received data.
- send_message(message: bytes) None
Sends a message to the connected device.
- Parameters:
message (bytes) – The message to send.