pyg90alarm.cloud
Cloud communication implementation for G90 alarm systems.
This module provides the necessary components to interact with G90 alarm systems through their cloud protocol (referred to as version 1.1).
- class pyg90alarm.cloud.G90CloudNotifications(protocol_factory, local_ip, local_port, cloud_ip, cloud_port, upstream_host=None, upstream_port=None, keep_single_connection=True)
Bases:
G90NotificationsBase,ProtocolCloud notifications service for G90 alarm systems.
Implements a server that listens for connections from G90 alarm devices and processes cloud protocol messages, with optional forwarding to an upstream server.
- Parameters:
protocol_factory (
Callable[[],G90NotificationProtocol]) – Factory function to create notification protocol handlerscloud_ip (
str) – Cloud IP address to announce to the panelcloud_port (
int) – Cloud port to announce to the panellocal_ip (
str) – Local IP to bind the server tolocal_port (
int) – Local port to bind the server toupstream_host (
str|None) – Optional upstream host to forward messages toupstream_port (
int|None) – Optional upstream port to forward messages tokeep_single_connection (
bool) – Whether to keep only a single device connection
- async close()
Close the server and any active connections.
Waits for any pending operations to complete, then closes the upstream connection and the local server.
- Return type:
- connection_lost(exc)
Handle connection loss from a device.
- connection_made(transport)
Handle a new connection from a device.
- Parameters:
transport (
BaseTransport) – The transport for the new connection- Return type:
- data_received(data)
Process data received from a device.
Parses messages from the device, handles them, and sends appropriate responses back to the device simulating the cloud server, unless upstream forwarding is configured - the data is passed thru to the upstream server unmodified.
- property device_id: str | None
The ID (GUID) of the panel being communicated with thru commands.
Available when any panel command receives it from the device (GETHOSTINFO local command or Hello / HelloDiscovery cloud ones).
- eof_received()
Called when the other end calls write_eof() or equivalent.
If this returns a false value (including None), the transport will close itself. If it returns a true value, closing the transport is up to the protocol.
- get_upstream_protocol()
Create and return a protocol for the upstream connection.
- Return type:
BaseProtocol- Returns:
Protocol for handling the upstream connection
- handle_alert(alert, verify_device_id=True)
Handles alert received from the device.
- Parameters:
alert (
G90DeviceAlert) – The alert to handle.verify_device_id (
bool) – Whether to verify the device ID (GUID) in the alert. If set to False, the device ID will not be verified.
- Return type:
- handle_notification(notification)
Handles notification received from the device.
- Parameters:
notification (
G90Notification) – The notification to handle.- Return type:
- property last_device_packet_time: datetime | None
Returns the timestamp of the last packet received from the device.
This property can be used to monitor the communication health with the device.
- property last_upstream_packet_time: datetime | None
Returns the timestamp of the last packet sent to the upstream server.
This property can be used to monitor the communication health with the cloud/upstream server.
- async listen()
Start listening for connections from devices.
Creates a server bound to the configured local host and port.
- Return type:
- property listener_started: bool
Indicates if the listener of the device notifications has been started.
- pause_writing()
Called when the transport’s buffer goes over the high-water mark.
Pause and resume calls are paired – pause_writing() is called once when the buffer goes strictly over the high-water mark (even if subsequent writes increases the buffer size even more), and eventually resume_writing() is called once when the buffer size reaches the low-water mark.
Note that if the buffer size equals the high-water mark, pause_writing() is not called – it must go strictly over. Conversely, resume_writing() is called when the buffer size is equal or lower than the low-water mark. These end conditions are important to ensure that things go as expected when either mark is zero.
NOTE: This is the only Protocol callback that is not called through EventLoop.call_soon() – if it were, it would have no effect when it’s most needed (when the app keeps writing without yielding until pause_writing() is called).
- resume_writing()
Called when the transport’s buffer drains below the low-water mark.
See pause_writing() for details.
- async send_upstream(data)
Send data to the upstream server.
Creates a connection to the upstream server if one doesn’t exist, then sends the provided data.
- set_last_device_packet_time()
Updates the timestamp of the last packet received from the device.
This method is called internally when a packet is received from the device.
- Return type:
- set_last_upstream_packet_time()
Updates the timestamp of the last packet sent to the upstream server.
This method is called internally when a packet is sent to the upstream server.
- Return type:
- upstream_connection_lost(exc)
Handle connection loss to the upstream server.
- upstream_connection_made(transport)
Handle successful connection to the upstream server.
- Parameters:
transport (
BaseTransport) – The transport for the upstream connection- Return type:
Modules
Constants used in the G90 cloud protocol implementation. |
|
Cloud message implementations for G90 alarm systems. |
|
Implementation of G90 cloud protocol notifications service. |
|
Protocol implementation for G90 cloud communication. |