Skip to content

Commit

Permalink
Fixed static token
Browse files Browse the repository at this point in the history
  • Loading branch information
roopesh committed Apr 8, 2021
1 parent 4bbc5cc commit 15bb742
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apps/ad-qolsys/partition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re

class partition:
def __init__(self, p_id: int, name: str, status: str, code: int, confirm_code_arm: bool, confirm_code_disarm: bool):
def __init__(self, p_id: int, name: str, status: str, code: int, confirm_code_arm: bool, confirm_code_disarm: bool, token: str):
""" Arguments:
id: int
name: str
Expand All @@ -26,6 +26,7 @@ def __init__(self, p_id: int, name: str, status: str, code: int, confirm_code_ar
self.code = code
self.confirm_code_arm = confirm_code_arm
self.confirm_code_disarm = confirm_code_disarm
self.token = token

def alarm_config_payload(self):
payload = {
Expand All @@ -34,7 +35,7 @@ def alarm_config_payload(self):
"code_disarm_required": self.confirm_code_disarm,
"code_arm_required": self.confirm_code_arm,
"command_topic":"qolsys/requests",
"command_template":'{"event":"{% if action == \"ARM_HOME\" or action == \"ARM_AWAY\" %}ARM","arm_type":"{% if action == \"ARM_HOME\" %}stay{% else %}away{% endif %}"{% else %}{{action}}", "usercode":"' + str(self.code) + '"{% endif %}, "token":"shw9s8", "partition_id":"' + str(self.p_id) + '"}'
"command_template":'{"event":"{% if action == \"ARM_HOME\" or action == \"ARM_AWAY\" %}ARM","arm_type":"{% if action == \"ARM_HOME\" %}stay{% else %}away{% endif %}"{% else %}{{action}}", "usercode":"' + str(self.code) + '"{% endif %}, "token":"' + self.token + '", "partition_id":"' + str(self.p_id) + '"}'
}
if self.confirm_code_disarm or self.confirm_code_arm:
payload.update({"code":self.code})
Expand Down
4 changes: 3 additions & 1 deletion apps/ad-qolsys/qolsys_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,21 @@ def initialize(self):
def terminate(self):
try:
self.qolsys.close_socket()
self.log("Socket closed")
except:
self.log("Error closing socket: %s", sys.exc_info(), level="ERROR")

try:
for zone in self.zones:
self.call_service("mqtt/publish", topic=self.zones[zone].config_topic, namespace=self.mqtt_namespace)
self.log("Zones removed")
except:
self.log("Error publishing empty zone: %s, %s", zone, sys.exc_info(), level="ERROR")

try:
for part in self.partitions:
self.call_service("mqtt/publish", topic=self.partitions[part].config_topic, namespace=self.mqtt_namespace)
self.call_service("mqtt/publish", topic=self.partitions[part].alarm_config_topic, namespace=self.mqtt_namespace)
self.log("Partitions removed")
except:
self.log("Error publishing empty partition: %s, %s", part, sys.exc_info(), level="ERROR")

Expand Down
2 changes: 1 addition & 1 deletion 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"]
this_partition = partition.partition(p_id=partition_id, name=partition_name, status=partition_status, code=self.app.qolsys_disarm_code, confirm_code_arm=self.app.qolsys_confirm_arm_code, confirm_code_disarm=self.app.qolsys_confirm_disarm_code)
this_partition = partition.partition(p_id=partition_id, name=partition_name, status=partition_status, code=self.app.qolsys_disarm_code, confirm_code_arm=self.app.qolsys_confirm_arm_code, confirm_code_disarm=self.app.qolsys_confirm_disarm_code, token=self.app.qolsys_token)
self.app.update_partition(partition_id, this_partition)
# self.app.call_service("mqtt/publish", namespace=self.app.mqtt_namespace, topic=this_partition.config_topic, payload=json.dumps(this_partition.config_payload()))
# self.app.call_service("mqtt/publish", namespace=self.app.mqtt_namespace, topic=this_partition.state_topic, payload=this_partition.status)
Expand Down

0 comments on commit 15bb742

Please sign in to comment.