Skip to content

Commit

Permalink
Supporting instant arming away
Browse files Browse the repository at this point in the history
  • Loading branch information
roopesh committed Apr 18, 2021
1 parent 616768e commit 6e14d06
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ You can send commands to the Qolsys panel on the `request_topic` in the config (
# Arm away
{"event":"ARM", "arm_type":"away", "partition_id": 0, "token":"blah"}
# (Variant) Arm away - Instant
{"event":"ARM", "arm_type":"away", "partition_id": 0, "token":"blah", "instant": true}
# Disarm
{"event":"DISARM", "usercode":0000, "token":"blah"}
```
Expand Down
8 changes: 7 additions & 1 deletion apps/ad-qolsys/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, p_id: int, name: str, status: str, code: int, confirm_code_ar
self.__c_disarmed__ = "disarmed"
self.__c_armed_home__ = "armed_home"
self.__c_armed_away__ = "armed_away"
self.__c_arming__ = "arming"
self.__c_command_topic__ = "command_topic"
self.__c_will_topic__ = "will_topic"
self.__c_will_payload__ = "will_payload"
Expand Down Expand Up @@ -107,13 +108,18 @@ def status(self, status:str):
__c_ARM_STAY__ = "ARM_STAY"
__c_ARM_DELAY__ = "EXIT_DELAY"
__c_DISARM__ = "DISARM"
valid_values = {__c_ARM_STAY__, __c_ARM_DELAY__, __c_DISARM__}
__c_ENTRY_DELAY__ = "ENTRY_DELAY"
__c_ARM_AWAY__ = "ARM_AWAY"
valid_values = {__c_ARM_STAY__, __c_ARM_AWAY__, __c_ARM_DELAY__, __c_DISARM__, __c_ENTRY_DELAY__}
if not status in valid_values:
self.__status = "unavailable"
raise ValueError("Not a valid status: '" + status + "' not in " + str(valid_values))
elif status in {__c_ARM_STAY__}:
# self.__status = self.payload_on
self.__status = self.__c_armed_home__
elif status in {__c_ARM_DELAY__}:
self.__status = self.__c_arming__
elif status in {__c_ENTRY_DELAY__, __c_ARM_AWAY__}:
self.__status = self.__c_armed_away__
elif status in {__c_DISARM__}:
# self.__status = self.payload_off
Expand Down
3 changes: 3 additions & 0 deletions apps/ad-qolsys/qolsys_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def qolsys_data_received(self, data:dict):
topic = "" #self.event_parent_topic
jdata = json.loads(data)
event_type = jdata["event"]

if event_type == "ERROR":
self.log("ERROR event: %s", data, level="ERROR")
if event_type == "INFO":
topic = self.qolsys_info_topic

Expand Down
17 changes: 11 additions & 6 deletions apps/ad-qolsys/qolsys_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def mqtt_info_event_received(self, event_name, data, kwargs):
partition_id = part["partition_id"]
partition_name = part["name"]
partition_status = part["status"]
self.app.log(self.app.mqtt_plugin_config)
# self.app.log(self.app.mqtt_plugin_config)
will_topic = self.app.mqtt_plugin_config["will_topic"]
will_payload = self.app.mqtt_plugin_config["will_payload"]
birth_topic = self.app.mqtt_plugin_config["birth_topic"]
Expand Down Expand Up @@ -180,6 +180,7 @@ def mqtt_request_received(self, event_name, data, kwargs):
usercode Required if disarming
partition_id Required if arming or disarming. 0 is a good value if you don't know what to use
arm_type Required if arming. Options are "away" or "stay"
instant Optional during away arming. Sets delay to 0.
'''

self.app.log("event_name: %s", event_name, level="DEBUG")
Expand All @@ -198,28 +199,29 @@ def mqtt_request_received(self, event_name, data, kwargs):
usercode = payload_json["usercode"] if "usercode" in payload_json else None
partition_id = payload_json["partition_id"] if "partition_id" in payload_json else None
arm_type = payload_json["arm_type"] if "arm_type" in payload_json else None
self.app.log("event: %s, usercode: %s, partition_id: %s, arm_type: %s", event_type, usercode, partition_id, arm_type, level="INFO")
instant = payload_json["instant"] if "instant" in payload_json else False
self.app.log("event: %s, usercode: %s, partition_id: %s, arm_type: %s, instant: %s", event_type, usercode, partition_id, arm_type, instant, level="INFO")
if token == None:
#raise("Token required for anything you want to do")
self.app.log("No token provided. Token is required for anything you want to do with the Qolsys panel", level="ERROR")
else:
if event_type == "INFO":
self.__qolsys_status__(self.qolsys, token)
self.__qolsys_status__(qolsys=self.qolsys, token=token)

if event_type == "ARM":
if partition_id is None or arm_type is None:
self.app.log("arm_type and partition_id are required", level="ERROR")
else:
self.__qolsys_arm__(self.qolsys, token, arm_type, partition_id)
self.__qolsys_arm__(qolsys=self.qolsys, token=token, arming_type=arm_type, partition_id=partition_id, instant=instant, usercode=usercode)

if event_type == "DISARM":
arm_type = "disarm"
if partition_id is None or arm_type is None or usercode is None:
self.app.log("arm_type, partition_id, and usercode are required", level="ERROR")
else:
self.__qolsys_arm__(self.qolsys, token, "disarm", partition_id, usercode)
self.__qolsys_arm__(qolsys=self.qolsys, token=token, arming_type="disarm", partition_id=partition_id, usercode=usercode)

def __qolsys_arm__(self, qolsys, token:str, arming_type:str, partition_id:int, usercode=""):
def __qolsys_arm__(self, qolsys, token:str, arming_type:str, partition_id:int, instant=False, usercode=""):
if not arming_type in self._arming_types:
raise("Invalid arm command")

Expand Down Expand Up @@ -250,6 +252,9 @@ def __qolsys_arm__(self, qolsys, token:str, arming_type:str, partition_id:int, u
if arming_type.lower() == "disarm":
armString.update({"usercode":usercode})

if arming_type.lower() == "away" and instant:
armString.update({"delay":0})

try:
self.app.log("armString: %s", armString, level="INFO")
qolsys.send_to_socket(armString)
Expand Down

0 comments on commit 6e14d06

Please sign in to comment.