bitcanon / visonicalarm Goto Github PK
View Code? Open in Web Editor NEWA simple library for the Visonic Alarm API written in Python 3.
License: MIT License
A simple library for the Visonic Alarm API written in Python 3.
License: MIT License
Dear bitcanon,
Would it be possible to include a method "STAY" to comply with the option on DSC alarms?
Something like this would suffice! Thanks!
def arm_stay(self, partition): """ Arm in Home mode. """ arm_info = {'partition': partition, 'state': 'STAY'} arm_json = json.dumps(arm_info, separators=(',', ':')) return self.__send_request(self.__url_set_state, data_json=arm_json, request_type='POST')
Add the str() and repr() methods to the Device classes to make it easier to print and show these objects.
Example:
def __str__(self):
object_type = str(type(self))
return object_type + ": This is a Contact Device str."
def __repr__(self):
object_type = str(type(self))
return object_type + ": This is a Contact Device repr."
My alarm integration stopped working because the provider changed the API version to v10.0: https://connect.tycomonitor.com/rest_api/version
I have tested in Postman logging in and getting devices by just replacing the version number in request URLs and requests worked and return meaningful data. I'm not sure if the structure on reduced devices has changed though.
Nice, I have been testing in my system today and it is working. Only issue I had it was with the GSM device, which is not reporting the signal so the get_devices was failing on line 181 alarm.py so I added a check as a workaround:
elif device['device_type'] == 'GSM':
if 'signal_level' in device['traits'].keys():
signal_level=device['traits']['signal_level']['level']
else:
signal_level=0
contact_device = GSMDevice(
device_number=device['device_number'],
device_type=device['device_type'],
enrollment_id=device['enrollment_id'],
id=device['id'],
name=device['name'],
partitions=device['partitions'],
preenroll=device['preenroll'],
removable=device['removable'],
renamable=device['renamable'],
subtype=device['subtype'],
warnings=device['warnings'],
zone_type=device['zone_type'],
signal_level=signal_level
)
If you have time maybe you can check the inputs before assign them, traits seems to be quite tricky.
Originally posted by @amaduain in #16 (comment)
The two methods __send_get_request() and __send_post_request() are almost exact copies except for some small bits of code. Refactor this into a __send_request().
It's bad security practice to store email, password and user code in memory inside the library.
Remove the local variables from core.py
and make it up to the user to decide where to store the credentials:
self.__user_code = user_code
self.__app_id = user_id
self.__panel_id = panel_id
self.__user_email = user_email
self.__user_password = user_password
Implement the core.py
API method:
def wakeup_sms(self):
""" Send a wakeup SMS to the alarm panel. """
# send_get('https://api.server.com/rest_api/9.0/wakeup_sms')
raise NotImplementedError()
Also extract the method for use in alarm.py
.
Implement the core.py
method:
def get_panels(self):
""" Get a list of panels. """
# send_get('https://api.server.com/rest_api/9.0/panels')
raise NotImplementedError()
Also extract the method for use in alarm.py
.
Exception handling has to be rebuilt as well. If calling login() with faulty credentials, panel_ids and so on, we get a BadRequestError that can be parsed into multiple sub exception:
For example (calling login()
using an email that doesn't exist):
visonic.exceptions.BadRequestError: b'{"error":10004,"error_message":"Wrong combination","error_reason_code":"WrongCombination","extras":[{"key":"email","value":"wrong_combination"},{"key":"password","value":"wrong_combination"}]}'
Or a panel_id
that doesn't exist:
b'{"error":10001,"error_message":"Bad Request Params","error_reason_code":"BadRequestParams","extras":[{"key":"panel_serial","value":"incorrect"}]}'
The example scripts in the /examples/
directory needs to be updated to work with the latest version of the library.
Save the old example scripts in a directory called version 2 or something (that support API version 4.0).
Hi,
It seem that the rest API is not available anymore. New visonic Go android APK is now asking a registration (mail / password) et there is a crypted communication between server and app.
I tried to trace TCP flow using wireshard and android emulator and API command are now crypted and it's way too complicated for me.
If you still use Visonic and can look at this new API, I would be happy to help.
Regards,
Fred.
When calling the repr() method of the Device class it should return a text that can be used to create a new object of that class.
Example:
Device(id='123-4567', zone='5', location='Livingroom', alerts=None, ...and so on)
You should then be able to copy that text and create a new object:
test = Device(id='123-4567', zone='5', location='Livingroom', alerts=None, ...and so on)
print(text.id)
The method get_users() generates names "User 1", "User 2", ... "User N" (where N is total user count).
It would be great if we could pass a list of usernames that should override the generated user names.
name_list = [
[1, 'Egon'],
[8, 'Sture']
]
alarm.get_users(name_list)
def get_users(self, names_to_override=None):
....
Update it with the new accessor class:
A quick draft. Add all other functionality as well and example code:
from visonic import alarm
hostname = 'visonic.tycomonitor.com'
user_code = '1234'
user_id = '2d978962-daa6-4e18-a5e5-b4a99100bd3b'
panel_id = '123456'
alarm = alarm.Setup(hostname, user_code, user_id, panel_id)
alarm.connect()
# Print system information
print(f'Panel ID: {alarm.serial_number}')
print(f'Name: {alarm.name}')
print(f'Model: {alarm.model}')
print(f'Ready: {alarm.ready}')
print(f'State: {alarm.state}')
print(f'Active: {alarm.active}')
print(f'Token: {alarm.session_token}')
print(f'Connected: {alarm.connected}')
alarm.update_devices()
print(alarm.devices[0].id)
alarm.sync_time()
Hi all,
thanks for the great work, I was guessing if you already thought on supporting bypassing, I've been trying to find the api for bypassing, but so far no luck.
Do you have any details on the api?
Thanks!
First of all thank you and congratulate you for your work with this library to connect to visonic, my name is Dario, nice to meet you.
I'm trying to connect to my alarm, I have visonic-go and all the parameters are well configured but I don't know why it fails and I don't know how to debug the library.
My provider's API version is 8.0, my company's panel_id is a 6-digit decimal value and not a hexadecimal value, and the endpoint I'm trying to connect to is (www.visonic.xxx.com) and the error that I get using your example script (with all the parameters correctly set) is this:
Connecting to 'www.visonic.biservicus.com'...
Supported REST API version(s): 8.0
Enter your master code:
Authenticating using '[email protected]'...
Successfully authenticated.
Traceback (most recent call last): File
"/home/user123/Delete/visonicAlarm/alarm.py", line 213, in <module> main() File
"/home/user123/Delete/visonicAlarm/alarm.py", line 168, in main if notconnect(): File
"/home/user123/Delete/visonicAlarm/alarm.py", line 124, in connect if not alarm.connected(): File
"/home/user123/.local/lib/python3.10/site-packages/visonic/alarm.py", line 56, in connected return self.get_status().connected
File "/home/user123/.local/lib/python3.10/site-packages/visonic/alarm.py", line 344, in get_status
bba_connected=status['connected_status']['bba']['is_connected'], KeyError: 'bba'
Thank you very much, I hope your answer.
When trying the first example code in the README.md file this error occurs:
from visonic import alarm
hostname = 'your.alarmcompany.com'
user_code = '1234'
user_id = '2d978962-daa6-4e18-a5e5-b4a99100bd3b'
panel_id = '123ABC'
alarm = alarm.Setup(hostname, user_code, user_id, panel_id)
print('Supported REST API version(s): ' + ', '.join(alarm.rest_api_version()))
Result:
Traceback (most recent call last):
File "/Users/mikael/code/python/visonictest/test.py", line 10, in <module>
print('Supported REST API version(s): ' + ', '.join(alarm.rest_api_version()))
File "/Users/mikael/code/python/visonictest/venv/lib/python3.9/site-packages/visonic/alarm.py", line 59, in rest_api_version
return self.__api.get_version_info()['rest_versions']
File "/Users/mikael/code/python/visonictest/venv/lib/python3.9/site-packages/visonic/core.py", line 183, in get_version_info
return self.__send_request(self.__url_version,
File "/Users/mikael/code/python/visonictest/venv/lib/python3.9/site-packages/visonic/core.py", line 143, in __send_request
return json.loads(response.content.decode('utf-8'))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 1: invalid start byte
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.