Code Monkey home page Code Monkey logo

visonicalarm's People

Contributors

bitcanon avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

visonicalarm's Issues

Update the Examples

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

Add string methods for classes for easier printing

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

Update the README file

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

Implement the wakeup_sms() core API method

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.

Add support for API version 10.0

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.

Implement the get_panels() core API method

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.

Allow to override default usernames in get_users()

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

Check that traits are set prior to assignment

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)

Integration with DSC alarms

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

Refactor GET and POST methods

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

The __repr__() method should return object

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)

Create more Exceptions covering login errors

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"}]}'

Error decoding response from API server

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

Pluggin not working since 08 august 2020

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.

Don't store credentials in memory

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

KeyError exception when connecting to API v8.0

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.

Support for bypass

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.