kdschlosser / MiCasaVerde_Vera

Python library for controlling the MiCasaVerde Vera Z-Wave controller.
MIT License
6 stars 1 forks source link

Keeps giving an error while trying to import the library #8

Open newwarez opened 5 years ago

newwarez commented 5 years ago

When I am using the following command line: import micasaverde_vera Pycharm gives me the following error

Traceback (most recent call last): File "C:/Users/Userx/PycharmProjects/untitled3/yarab.py", line 1, in import micasaverde_vera File "C:\Users\Userx\AppData\Roaming\Python\Python37\site-packages\micasaverde_vera__init__.py", line 183, in import vera_build # NOQA ModuleNotFoundError: No module named 'vera_build'

Even though I have added the micasaverde_vera library in the site packages of python. And I also do not understand why this package does not have a setup.py file.

kdschlosser commented 5 years ago

It does not have a setup.py file because when I made this it was before I had done anything with distutils or setuptools. Now that I am more familiar with it I can make one. also when I wrote this I was using python 2.7. i do not know about 3.3+ compatibility. I imagine the import error is because you are running python 3.3+

I can make any changes needed to make it python 3.3+ compatible, you will need to give me a little bit to complete the changes

kdschlosser commented 5 years ago

ok there is now a setup.py file and it should work on python3. I no longer have a MiCasaVerde Vera so I am not able to test. I do not know if this thing even works anymore.

newwarez commented 5 years ago

Thank you for your reply and contribution, I think the setup.py shall be placed inside the micasaverde_vera folder or there is a referencing problem in the file. However, when I placed it inside the folder I was able to install it (manually through build and install).

But when I try to run the code in the "readme", it still gives me errors. I am not sure if I have done something wrong. I also noticed that in the same code, the "print" command has no parenthesis which I modified.

kdschlosser commented 5 years ago

ok I updated the module again. I added a very in depth data path debugging routine. I also added logging instead of the print() statements.

Do me a favor tho. please post the traceback in their entirety you are getting this way I have something to help locate the problems.

also read this issue. i cannot remember if i updated the README or not to reflect the changes made.. https://github.com/kdschlosser/MiCasaVerde_Vera/issues/6

let me know if it works.

kdschlosser commented 5 years ago

Oh one other thing. depending on what OS you are using you will need to delete ~/.micasaverde_vera if running a NIX OS (Linux, Unix, OSX) or %appdata%\micasaverde_vera if running Windows

kdschlosser commented 5 years ago

after you do the import of micasaverde_vera please add this line right after the import.

micasaverde_vera.logger.setLevel(micasaverde_vera.logger.DEBUG)
kdschlosser commented 5 years ago

I just added a method to dump the logging output to a file also. I did this because the debugging output is going to be MASSIVE. so you will most likely not have enough of a character buffer set in your console window. and it is easier for me to add this then it is to explain how to change the buffer.

after you set the logging level to output to a file add this line.

micasaverde_vera.logger.set_output_file(r'SOME_PATH/SOME.FILE', micasaverde_vera.logger.DEBUG)

replace SOME_PATH/SOME.FILE with the path and filename to output to.

newwarez commented 5 years ago

Well, the import finally worked fine ! Library was imported with no errors in python 3.7.2 However, trying to connect to the vera is now giving an error, trying to log the error the way you told me about is giving me a non-meaningful log (included below), so when I run the micasaverde_vera.build_files('192.168.8.25', log=True) or vera = micasaverde_vera.connect(IP_ADDRESS) after the import of the library the following error shows in the console:

2019-09-11 12:02:59,460 - startin vera 2019-09-11 12:02:59,460 - MicasaVerde Vera: Building files please wait.... 2019-09-11 12:02:59,460 - 192.168.8.25 2019-09-11 12:02:59,460 - /cgi-bin/cmh/sysinfo.sh 2019-09-11 12:02:59,460 - 192.168.8.25 Traceback (most recent call last): File "C:\Users\U337493\PycharmProjects\untitled4\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera__init.py", line 338, in connect core = start_vera() File "C:\Users\U337493\PycharmProjects\untitled4\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera__init__.py", line 329, in start_vera return init_core() File "C:\Users\U337493\AppData\Local\Programs\Python\Python37\lib\imp.py", line 171, in load_source module = _load(spec) File "", line 696, in _load File "", line 677, in _load_unlocked File "", line 724, in exec_module File "", line 859, in get_code File "C:\Users\U337493\AppData\Local\Programs\Python\Python37\lib\imp.py", line 157, in get_data return super().get_data(path) File "", line 916, in get_data FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\U337493\AppData\Roaming\MiCasaVerde_Vera\core\init__.py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/U337493/PycharmProjects/untitled4/NewFile.py", line 5, in vera = micasaverde_vera.connect(IP_ADDRESS) File "C:\Users\U337493\PycharmProjects\untitled4\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera__init.py", line 355, in connect build() File "C:\Users\U337493\PycharmProjects\untitled4\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera\init__.py", line 333, in build build_files(ip_address, log=False) File "C:\Users\U337493\PycharmProjects\untitled4\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera\vera_build.py", line 872, in build_files logger.debug(CONTROLLER_INFO_TEMPLATE.format(*get_vera_info(ip_address))) File "C:\Users\U337493\PycharmProjects\untitled4\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera\vera_build.py", line 700, in get_verainfo response, = get_data(SYS_INFO, ip_address) File "C:\Users\U337493\PycharmProjects\untitled4\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera\vera_build.py", line 127, in get_data response = ip_address.build_relay.send(extra_url=url, **params) AttributeError: 'str' object has no attribute 'build_relay'

The content of the error log file is the following:

2019-09-11 12:02:59,460 - startin vera 2019-09-11 12:02:59,460 - MicasaVerde Vera: Building files please wait.... 2019-09-11 12:02:59,460 - 192.168.8.25 2019-09-11 12:02:59,460 - /cgi-bin/cmh/sysinfo.sh 2019-09-11 12:02:59,460 - 192.168.8.25

The exact context of the code that I have written is the following:

import micasaverde_vera micasaverde_vera.logger.setLevel(micasaverde_vera.logger.DEBUG) micasaverde_vera.logger.set_output_file(r'Log/Log.txt', micasaverde_vera.logger.DEBUG) IP_ADDRESS = '192.168.8.25' vera = micasaverde_vera.connect(IP_ADDRESS)

I also already came across issue #6 and it turned out that there is already a line of the vera = micasaverde_vera.connect(IP_ADDRESS) function inside the readme code (but not at the beginning), I just modified the print statements of the readme and tried to run it, I noticed that the error is coming from the vera = micasaverde_vera.connect(IP_ADDRESS) function.

for the ( %appdata%\micasaverde_vera ) thing, I searched in the app data for this file, I did not find it, maybe you can elaborate more on the %appdata% location (to which folder are you trying to refer exactly).

kdschlosser commented 5 years ago

ok give it a go now. and the file that is output is a debugging log it is not an error log it lets me know what is going on and when is all. makes it easier to find where the problem is and what data might be causing the problem.

kdschlosser commented 5 years ago

how this library works is it leverages some "holes" or open ports/locations on the vera to download things like device xml files. I use these files along with a bunch of other available information to generate python versions of the files. so in essence I am building a python version of the MIOS backend. so it does not matter if you call the builder directly using micasaverde_vera.build_files or if you call micasaverde_vera.connect it is still going to build the files. you can use the first command to forcefully rebuild the files if you want. The files are also hash key check to ensure they are not altered or corrupted. so you cannot modify the generated files at all otherwise it will remove the file and recreate it. It is going to build alot of files you are welcome to go and look at them when the build process is done.

I am assuming you are running Windows. When the builder completes (which it has not done yet) if you open Windows Explorer (File Explorer) and in the addressbar type in %appdata%\micasaverde_vera and press the enter/return key it will bring you to the location the generated files are stored.

kdschlosser commented 5 years ago

%appdata% is a windows environment variable that is always set. it points to the roaming folder in appdata... so if you were logged in as Administrator the path would be C:\Users\Administrator\appdata\roaming so %appdata%\micasaverde_vera would be C:\Users\Administrator\appdata\roaming\micasaverde_vera

newwarez commented 5 years ago

Again, there is an error while trying to build, the python code is the following:

import micasaverde_vera
micasaverde_vera.logger.setLevel(micasaverde_vera.logger.DEBUG)
micasaverde_vera.logger.set_output_file(r'Log/Log.txt', micasaverde_vera.logger.DEBUG)

IP_ADDRESS = '192.168.8.25'
DEVICE_NUMBER = None
SHOW_ALL_EVENTS = True

vera = micasaverde_vera.connect('192.168.8.25')

def test_callback(event):
    if SHOW_ALL_EVENTS:
        print(event.event)

    split_event = event.event.split('.')

    def check_event():
        if split_event[-1] == 'changed':
            print()
            print('--------------------------------------------')
            print(event.event)
            attr_name = split_event[-2:][0]
            try:
                print (event.name)
            except AttributeError:
                print('NO NAME')
            print(attr_name, '=', getattr(event, attr_name))
            print('--------------------------------------------')
            print()

    if split_event[0] == 'devices':
        if split_event[1] == str(DEVICE_NUMBER):
            check_event()

    elif split_event[0] == 'rooms':
        check_event()

vera = micasaverde_vera.connect(IP_ADDRESS)
event_handler = vera.bind('*', test_callback)
vera.start_polling(0.2)

while True:
    command = [
        raw_input('key in commands here. the last line must be RUN\n\n')
    ]
    while command[-1] != 'RUN' and not command[-1].endswith('RUN'):
        command += [raw_input('')]
    command = '\n'.join(command)[:-3]

    try:
        exec(command)
    except:
        import traceback
        traceback.print_exc()

the error code is the following:

C:\Users\U337493\PycharmProjects\go3\venv\Scripts\python.exe C:/Users/U337493/PycharmProjects/go3/go3.py 2019-09-12 14:33:40,790 - startin vera 2019-09-12 14:33:40,791 - MicasaVerde Vera: Building files please wait.... 2019-09-12 14:33:40,791 - 192.168.8.25 Traceback (most recent call last): File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera__init.py", line 338, in connect core = start_vera() File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera__init__.py", line 329, in start_vera return init_core() File "C:\Users\U337493\AppData\Local\Programs\Python\Python37\lib\imp.py", line 171, in load_source module = _load(spec) File "", line 696, in _load File "", line 677, in _load_unlocked File "", line 724, in exec_module File "", line 859, in get_code File "C:\Users\U337493\AppData\Local\Programs\Python\Python37\lib\imp.py", line 157, in get_data return super().get_data(path) File "", line 916, in get_data FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\U337493\AppData\Roaming\MiCasaVerde_Vera\core\init__.py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/U337493/PycharmProjects/go3/go3.py", line 10, in vera = micasaverde_vera.connect('192.168.8.25') File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera__init.py", line 355, in connect build() File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera\init__.py", line 333, in build build_files(ip_address, log=False) File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera\vera_build.py", line 873, in build_files logger.debug(CONTROLLER_INFO_TEMPLATE.format(*get_vera_info(ip_address))) File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera\vera_build.py", line 701, in get_verainfo response, = get_data(SYS_INFO, ip_address) File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\micasaverde_vera-0.5.9-py3.7.egg\micasaverde_vera\vera_build.py", line 126, in get_data response = requests.get(url, params=params, timeout=1) File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\requests-2.22.0-py3.7.egg\requests\api.py", line 75, in get return request('get', url, params=params, kwargs) File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\requests-2.22.0-py3.7.egg\requests\api.py", line 60, in request return session.request(method=method, url=url, kwargs) File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\requests-2.22.0-py3.7.egg\requests\sessions.py", line 519, in request prep = self.prepare_request(req) File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\requests-2.22.0-py3.7.egg\requests\sessions.py", line 462, in prepare_request hooks=merge_hooks(request.hooks, self.hooks), File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\requests-2.22.0-py3.7.egg\requests\models.py", line 313, in prepare self.prepare_url(url, params) File "C:\Users\U337493\PycharmProjects\go3\venv\lib\site-packages\requests-2.22.0-py3.7.egg\requests\models.py", line 387, in prepare_url raise MissingSchema(error) requests.exceptions.MissingSchema: Invalid URL '/cgi-bin/cmh/sysinfo.sh': No schema supplied. Perhaps you meant http:///cgi-bin/cmh/sysinfo.sh?

Process finished with exit code 1

the output of the log file is the following:

2019-09-11 12:02:59,460 - startin vera 2019-09-11 12:02:59,460 - MicasaVerde Vera: Building files please wait.... 2019-09-11 12:02:59,460 - 192.168.8.25 2019-09-11 12:02:59,460 - /cgi-bin/cmh/sysinfo.sh 2019-09-11 12:02:59,460 - 192.168.8.25