pyg90alarm.alarm
Provides interface to G90 alarm panel.
Note
Both local protocol (referred to as 1.2) and cloud one
(mentioned as 1.1) are supported.
The next example queries the device with IP address 10.10.10.250 for the information - the product name, protocol version, HW versions and such.
>>> import asyncio
>>> from pyg90alarm import G90Alarm
>>> async def main():
g90 = G90Alarm(host='10.10.10.250')
s = await g90.host_info
print(s)
>>> asyncio.run(main())
G90HostInfo(host_guid='<...>',
product_name='TSV018-C3SIA',
wifi_protocol_version='1.2',
cloud_protocol_version='1.1',
mcu_hw_version='206',
wifi_hw_version='206',
gsm_status=3,
wifi_status=3,
reserved1=0,
reserved2=0,
band_frequency='4264',
gsm_signal_level=50,
wifi_signal_level=100)
Classes
|
Allows to interact with G90 alarm panel. |
- class pyg90alarm.alarm.G90Alarm(host, port=12368, reset_occupancy_interval=3.0)
Bases:
G90NotificationProtocolAllows to interact with G90 alarm panel.
- Parameters:
host (
str) – Hostname or IP address of the alarm panel. Since the protocol is UDP-based it is ok to use broadcast or directed broadcast addresses, such as 255.255.255.255 or 10.10.10.255 (the latter assumes the device is on 10.10.10.0/24 network)port (
int) – The UDP port of the device where it listens for the protocol commands on WiFi interface, currently the devices don’t allow it to be customizedreset_occupancy_interval (
float) – The interval upon that the sensors are simulated to go into inactive state.
- property host: str
Returns the hostname or IP address of the alarm panel.
This is the address used for communication with the device.
- property port: int
Returns the UDP port number used to communicate with the alarm panel.
By default, this is set to the standard G90 protocol port.
- async command(code, data=None)
Invokes a command against the alarm panel.
- paginated_result(code, start=1, end=None)
Returns asynchronous generator for a paginated command, that is - command operating on a range of records.
- Parameters:
code (
G90Commands) – Command codestart (
int) – Starting record position (one-based)
- Return type:
- Returns:
Asynchronous generator over the result of command invocation.
- async mcu_reboot()
Reboots the MCU of the alarm panel.
Note that underlying command doesn’t return any result, so there is no feedback from the panel upon execution.
- Return type:
- async gsm_reboot()
Reboots the GSM module of the alarm panel.
Note that underlying command doesn’t return any result, so there is no feedback from the panel upon execution.
- Return type:
- async wifi_reboot()
Reboots the WiFi module of the alarm panel.
Note that underlying command doesn’t return any result, so there is no feedback from the panel upon execution.
- Return type:
- async reboot()
Reboots the entire alarm panel.
The system commands performing reboot of a panel’s module don’t return anything so there is no feedback from the panel upon execution, hence the commands are spaced with delays to allow the panel to process them.
Please be aware that the delays are determined experimentally and might be too long or too short.
- Return type:
- async set_cloud_server_address(cloud_ip, cloud_port)
Sets the cloud server address the alarm panel connects to.
- Parameters:
cloud_ip (
str) – IP address of the server to receive cloud protocol notifications, should be reachable from the panel. Typically it is the IP address of the host running the packagecloud_port (
int) – Port number of the server to receive cloud protocol notifications, should be reachable from the panel
- Return type:
- async classmethod discover()
Initiates discovering devices available in the same network segment, by using global broadcast address as the destination.
- Return type:
- Returns:
List of discovered devices
- async classmethod targeted_discover(device_id)
Initiates discovering devices available in the same network segment using targeted protocol, that is - specifying target device GUID in the request, so only the specific device should respond to the query.
- Parameters:
device_id (
str) – GUID of the target device to discover- Return type:
- Returns:
List of discovered devices
- property sensors: List[G90Sensor]
Returns the list of sensors configured in the device. Please note it doesn’t update those from the panel except initially when the list if empty.
- Returns:
List of sensors
- async get_sensors()
Provides list of sensors configured in the device, updating them from panel on each call.
- async find_sensor(idx, name, exclude_unavailable=True)
Finds sensor by index and name.
- async register_sensor(definition_name, name=None, timeout=30)
Registers the sensor with the panel.
- Parameters:
- Return type:
- Returns:
Sensor instance
- property devices: List[G90Device]
Returns the list of devices (switches) configured in the device. Please note it doesn’t update those from the panel except initially when the list if empty.
- Returns:
List of devices
- async get_devices()
Provides list of devices (switches) configured in the device, updating them from panel on each call. Multi-node devices, those having multiple ports, are expanded into corresponding number of resulting entries.
- async find_device(idx, name, exclude_unavailable=True)
Finds device by index and name.
- async register_device(definition_name, name=None, timeout=30)
Registers device (relay, switch) with the panel.
- Parameters:
- Return type:
- Returns:
Device instance
- property host_info: G90HostInfo
Property over new
get_host_info()method, retained for compatibility.
- async get_host_info()
Provides the device information (for example hardware versions, signal levels etc.).
- Return type:
- Returns:
Device information
- property host_status: G90HostStatus
Property over new
get_host_status()method, retained for compatibility.
- async get_host_status()
Provides the device status (for example, armed or disarmed, configured phone number, product name etc.).
- Return type:
- Returns:
Device information
- property alert_config: G90AlertConfig
Provides alert configuration object.
- Returns:
Alert configuration object
- async get_alert_config()
Provides alert configuration flags, retained for compatibility - using
alert_configandG90AlertConfigis preferred.- Return type:
- Returns:
The alerts configured
- async set_alert_config(flags)
Sets the alert configuration flags, retained for compatibility - using
alert_configandG90AlertConfigis preferred.- Return type:
- async alarm_phones(force=False)
Provides access to alarm panel phone numbers.
- Parameters:
force (
bool) – If True, bypass cached value and force device read.- Return type:
- Returns:
Alarm panel phone numbers
- async host_config(force=False)
Provides access to alarm panel configuration.
- Parameters:
force (
bool) – If True, bypass cached value and force device read.- Return type:
- Returns:
Alarm panel configuration
- async net_config(force=False)
Provides access to alarm panel network configuration.
- Parameters:
force (
bool) – If True, bypass cached value and force device read.- Return type:
- Returns:
Alarm panel network configuration
- async sia_config(force=False)
Provides access to SIA Internet reporting configuration.
- Parameters:
force (
bool) – If True, bypass cached value and force device read.- Return type:
- Returns:
SIA Internet reporting configuration
- async cid_config(force=False)
Provides access to CID (Contact ID) phone reporting configuration.
- Parameters:
force (
bool) – If True, bypass cached value and force device read.- Return type:
- Returns:
CID phone reporting configuration
- property user_data_crc: G90UserDataCRC
Property over new
get_user_data_crc()method, retained for compatibility.
- async get_user_data_crc()
Retieves checksums (CRC) for different on-device databases (history, sensors etc.). Might be used to detect if there is a change in a particular database.
Note
Note that due to a bug in the firmware CRC for sensors and device databases change on each call even if there were no changes
- Return type:
- Returns:
Checksums for different databases
- async history(start=1, count=1)
Retrieves event history from the device.
- Parameters:
- Return type:
- Returns:
List of history entries
- async on_sensor_activity(idx, name, occupancy=True)
Invoked both for sensor notifications and door open/close alerts, since the logic for both is same and could be reused. Fires corresponding callback if set by the user with
sensor_callback.Please note the method is for internal use by the class.
- Parameters:
idx (
int) – The index of the sensor the callback is invoked for. Please note the index is a property of sensor, not the direct index ofsensorsarrayname (
str) – The name of the sensor, along with the idx parameter it is used to look the sensor up from thesensorslistoccupancy (
bool) – The flag indicating the target sensor state (=occupancy), will always be True for callbacks invoked from alarm panel notifications, and reflects actual sensor state for device alerts (only for door type sensors, if door open/close alerts are enabled)
- Return type:
- property sensor_callback: G90CallbackList[Callable[[int, str, bool], None] | Callable[[int, str, bool], Coroutine[None, None, None]]]
Sensor activity callback, which is invoked when sensor activates.
Setting the property will add the callback to the list of (retained for compatilibity with earlier package versions), or
G90CallbackListinstance could be accessed over the property - G90Alarm(…).sensor_callback.add(callback) or G90Alarm(…).sensor_callback.remove(callback) methods could be used to add or remove the callback, respectively.
- async on_door_open_close(event_id, zone_name, is_open)
Invoked when door open/close alert comes from the alarm panel. Fires corresponding callback if set by the user with
door_open_close_callback.Please note the method is for internal use by the class.
See also
on_sensor_activity()method for arguments- Return type:
- property door_open_close_callback: G90CallbackList[Callable[[int, str, bool], None] | Callable[[int, str, bool], Coroutine[None, None, None]]]
The door open/close callback, which is invoked when door is opened or closed (if corresponding alert is configured on the device).
See also
sensor_callbackfor compatibility notes
- async on_armdisarm(state)
Invoked when the device is armed or disarmed. Fires corresponding callback if set by the user with
armdisarm_callback.Please note the method is for internal use by the class.
- Parameters:
state (
G90ArmDisarmTypes) – Device state (armed, disarmed, armed home)- Return type:
- property armdisarm_callback: G90CallbackList[Callable[[G90ArmDisarmTypes], None] | Callable[[G90ArmDisarmTypes], Coroutine[None, None, None]]]
The device arm/disarm callback, which is invoked when device state changes.
See also
sensor_callbackfor compatibility notes
- async on_alarm(event_id, zone_name, is_tampered)
Invoked when alarm is triggered. Fires corresponding callback if set by the user with
alarm_callback.Please note the method is for internal use by the class.
- property alarm_callback: G90CallbackList[Callable[[int, str, Any], None] | Callable[[int, str, Any], Coroutine[None, None, None]]]
The device alarm callback, which is invoked when device alarm triggers.
See also
sensor_callbackfor compatibility notes
- async on_low_battery(event_id, zone_name)
Invoked when the sensor reports on low battery. Fires corresponding callback if set by the user with
on_low_battery_callback.Please note the method is for internal use by the class.
- property low_battery_callback: G90CallbackList[Callable[[int, str], None] | Callable[[int, str], Coroutine[None, None, None]]]
Low battery callback, which is invoked when sensor reports the condition.
See also
sensor_callbackfor compatibility notes
- async on_sos(event_id, zone_name, is_host_sos)
Invoked when SOS alert is triggered. Fires corresponding callback if set by the user with
sos_callback.Please note the method is for internal use by the class.
- property sos_callback: G90CallbackList[Callable[[int, str, bool], None] | Callable[[int, str, bool], Coroutine[None, None, None]]]
SOS callback, which is invoked when SOS alert is triggered.
See also
sensor_callbackfor compatibility notes
- async on_remote_button_press(event_id, zone_name, button)
Invoked when remote button is pressed. Fires corresponding callback if set by the user with
remote_button_press_callback.Please note the method is for internal use by the class.
- Parameters:
event_id (
int) – Index of the sensor triggered alarmzone_name (
str) – Sensor namebutton (
G90RemoteButtonStates) – The button pressed
- Return type:
- property remote_button_press_callback: G90CallbackList[Callable[[int, str, G90RemoteButtonStates], None] | Callable[[int, str, G90RemoteButtonStates], Coroutine[None, None, None]]]
Remote button press callback, which is invoked when remote button is pressed.
See also
sensor_callbackfor compatibility notes
- async on_rfid_keypad(event_id, zone_name, state)
Invoked when RFID keypad event occurs. Fires corresponding callback if set by the user with
rfid_keypad_callback.Please note the method is for internal use by the class.
- Parameters:
event_id (
int) – Index of the RFID keypad (sensor associated with the RFID keypad)zone_name (
str) – Sensor namestate (
G90RFIDKeypadStates) – The RFID keypad state
- Return type:
- property rfid_keypad_callback: G90CallbackList[Callable[[int, str, G90RFIDKeypadStates], None] | Callable[[int, str, G90RFIDKeypadStates], Coroutine[None, None, None]]]
RFID keypad callback, which is invoked when RFID keypad event occurs.
See also
sensor_callbackfor compatibility notes
- async on_door_open_when_arming(event_id, zone_name)
Invoked when door is open when arming the device. Fires corresponding callback if set by the user with
door_open_when_arming_callback.Please note the method is for internal use by the class.
- property door_open_when_arming_callback: G90CallbackList[Callable[[int, str], None] | Callable[[int, str], Coroutine[None, None, None]]]
Door open when arming callback, which is invoked when sensor reports the condition.
See also
sensor_callbackfor compatibility notes
- property tamper_callback: G90CallbackList[Callable[[int, str], None] | Callable[[int, str], Coroutine[None, None, None]]]
Tamper callback, which is invoked when sensor reports the condition.
- async on_sensor_change(sensor_idx, sensor_name, added)
Invoked when sensor is added or removed from the device.
There is no user-visible callback assoiciated with this method, those will be handled by on_sensor_list_change() method.
Please note the method is for internal use by the class.
- property sensor_list_change_callback: G90CallbackList[Callable[[G90Sensor, bool], None] | Callable[[G90Sensor, bool], Coroutine[None, None, None]]]
Sensor list change callback, which is invoked when sensor list changes.
See also
sensor_callbackfor compatibility notes
- async on_sensor_list_change(sensor, added)
Invoked when sensor list is changed.
Fires corresponding callback if set by the user with
sensor_list_change_callback. Please note the method is for internal use by the class.
- property device_list_change_callback: G90CallbackList[Callable[[G90Device, bool], None] | Callable[[G90Device, bool], Coroutine[None, None, None]]]
Device list change callback, which is invoked when device list changes.
See also
sensor_callbackfor compatibility notes
- async on_device_list_change(device, added)
Invoked when device list is changed.
Fires corresponding callback if set by the user with
device_list_change_callback.Please note the method is for internal use by the class.
- async listen_notifications()
Starts internal listener for device notifications/alerts.
- Return type:
- property sms_alert_when_armed: bool
When enabled, allows to save costs on SMS by having corresponding alert enabled only when device is armed.
- async start_simulating_alerts_from_history(interval=5, history_depth=5)
Starts the separate task to simulate device alerts from history entries.
The listener for device notifications will be stopped, so device notifications will not be processed thus resulting in possible duplicated if those could be received from the network.
- async stop_simulating_alerts_from_history()
Stops the task simulating device alerts from history entries.
The listener for device notifications will be started back, if it was running when simulation has been started.
- Return type:
- async use_local_notifications(notifications_local_ip='0.0.0.0', notifications_local_port=12901)
Switches to use local notifications for device alerts.
- Return type:
- async use_cloud_notifications(cloud_ip, cloud_port, cloud_local_ip='0.0.0.0', cloud_local_port=5678, upstream_host=None, upstream_port=5678, keep_single_connection=True)
Switches to use cloud notifications for device alerts.
Please note the method does not configure the panel for the host to receive the notifications - please invoke
G90Alarm.set_cloud_server_address()method to do that. The reason of that is configuring cloud server address on the panel is one-time operation, while the method will be called multiple times.- Parameters:
cloud_ip (
str) – The IP address of cloud server to connect to, should be reachable from the panelcloud_port (
int) – The cloud server port to connect to, should be reachable from the panelcloud_local_ip (
str) – Local IP address to bind cloud notifications listener tocloud_local_port (
int) – Local port to bind cloud notifications listener to, should match cloud_port above unless network setup dictates otherwiseupstream_host (
str|None) – Optional upstream host to connect to cloud server throughupstream_port (
int|None) – Optional upstream port to connect to cloud server throughkeep_single_connection (
bool) – If enabled, keeps a single connection to the upstream cloud server for both sending and receiving data
- Return type: