pyg90alarm.local.notifications

Implements support for notifications/alerts sent by G90 alarm panel.

Classes

G90LocalNotifications(protocol_factory, ...)

Implements support for notifications/alerts sent by alarm panel.

class pyg90alarm.local.notifications.G90LocalNotifications(protocol_factory, port, host, local_port, local_ip)

Bases: G90NotificationsBase, DatagramProtocol

Implements support for notifications/alerts sent by alarm panel.

There is a basic check to ensure only notifications/alerts from the correct device are processed - the check uses the host and port of the device, and the device ID (GUID) that is set by the ancestor class that implements the commands (e.g. G90Alarm). The latter to work correctly needs a command to be performed first, one that fetches device GUID and then stores it using device_id (e.g. G90Alarm.get_host_info()).

Parameters:
  • protocol_factory (Callable[[], G90NotificationProtocol]) – A callable that returns a new instance of the G90NotificationProtocol class.

  • port (int) – The port on which the device is listening for notifications.

  • host (str) – The host on which the device is listening for notifications.

  • local_port (int) – The port on which the local host is listening for notifications.

  • local_ip (str) – The IP address on which the local host is listening for notifications.

connection_made(transport)

Invoked when connection from the device is made.

Return type:

None

connection_lost(exc)

Same but when the connection is lost.

Return type:

None

datagram_received(data, addr)

Invoked when datagram is received from the device.

Return type:

None

async listen()

Listens for notifications/alerts from the device.

Return type:

None

clear_device_id()

Clears the device ID.

Return type:

None

async close()

Closes the listener.

Return type:

None

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).

error_received(exc)

Called when a send or receive operation raises an OSError.

(Other than BlockingIOError or InterruptedError.)

handle(data)

Invoked when message is received from the device.

Return type:

None

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:

None

handle_notification(notification)

Handles notification received from the device.

Parameters:

notification (G90Notification) – The notification to handle.

Return type:

None

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.

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.

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:

None

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:

None