rcastberg / sure_petcare

Python library for accessing sure connect petflap
GNU General Public License v3.0
55 stars 15 forks source link

Install questions #4

Open chriszuckerberg opened 5 years ago

chriszuckerberg commented 5 years ago

Please, can you tell me how to install this great code?

dib0 commented 5 years ago

Hi!

To do this in Linux: first clone the repo: git clone https://github.com/rcastberg/sure_petcare.git

The run: python3 setup.py install or sudo python3 setup.py install

Then the module should be installed.

chriszuckerberg commented 5 years ago

Cool, Thank you, I'll try it. Chris

ok. And then? I call: sudo sp_cli.py -e cxxxxxxx@gmx.de -p Pxxxxxxxx --update

Result:

Traceback (most recent call last): File "/usr/local/bin/sp_cli.py", line 4, in import('pkg_resources').run_script('sure-petcare==0.1', 'sp_cli.py') File "/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py", line 750, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py", line 1527, in run_script exec(code, namespace, namespace) File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/EGG-INFO/scripts/sp_cli.py", line 156, in main( sys.argv ) File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/EGG-INFO/scripts/sp_cli.py", line 76, in main sp.update() File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/sure_petcare/init.py", line 337, in update self.update_device_ids() File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/sure_petcare/init.py", line 419, in update_device_ids household['default_flap'] = list(flaps.keys())[0] IndexError: list index out of range

What must i do? Or how do I properly call the application? Sorry for many questions...

strix-technica commented 5 years ago

@chriszuckerberg

What must i do? Or how do I properly call the application?

The error you're getting suggests that the API can't see any door devices attached to the account credentials you supplied.

If you want to try to resolve the problem yourself, use sp_cli.py and also the update() method in the main API class as a guide to instantiating the API in an interactive Python interpreter, then examine the data retrieved by each step of the initial update mechanism. You can find the results in the .cache instance attribute.

Beyond that, I'm afraid I can't supply much more support than that in the circumstances. I wanted to develop this API into a more end-user friendly package, but SurePet isn't keen on that last I knew.

rsewell97 commented 5 years ago

Hey, is there any support for windows?

I'm obviously getting the error [WinError 3] The system cannot find the path specified: '/sys/class/net/' . Tried replacing the returned MAC manually, but when I do that it can't find any flaps on my account? Any other pointers?

Cheers and good work!

rcastberg commented 5 years ago

If you replaced the function to return your mac, then you should be fine at that stage. Almost any value should work there from my experience. I would have thought that the python code would have abstracted the difference between windows and Linux. I Will have to look into this.

As to why you aren't getting any flaps i am not sure. I take it you aren't getting any error messages?

On Mon, 17 Dec 2018 at 20:40, rsewell97 notifications@github.com wrote:

Hey, is there any support for windows?

I'm obviously getting the error [WinError 3] The system cannot find the path specified: '/sys/class/net/' . Tried replacing the returned MAC manually, but when I do that it can't find any flaps on my account? Any other pointers?

Cheers and good work!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rcastberg/sure_petcare/issues/4#issuecomment-447972312, or mute the thread https://github.com/notifications/unsubscribe-auth/ACF8T2pCnnmMKsCSrXSUWsRtZtmBAHVEks5u5_M1gaJpZM4XbFTU .

dzjr commented 5 years ago

@chriszuckerberg

What must i do? Or how do I properly call the application?

The error you're getting suggests that the API can't see any door devices attached to the account credentials you supplied.

If you want to try to resolve the problem yourself, use sp_cli.py and also the update() method in the main API class as a guide to instantiating the API in an interactive Python interpreter, then examine the data retrieved by each step of the initial update mechanism. You can find the results in the .cache instance attribute.

Beyond that, I'm afraid I can't supply much more support than that in the circumstances. I wanted to develop this API into a more end-user friendly package, but SurePet isn't keen on that last I knew.

i have the same problem....

i am sure that the email address & PW are right....

can i adjust it manual somewhere?

i tried: ./sp_cli.py --update -e bladiebla@provider.com -p password also tried it wiht sudo and without ./ and all other combinations

all times the output is:

is the location of the program maybe the problem? i have it in ~/domoticz/scripts/Sureflap/sure_petcare because i want to try to connect i in my domoticz system.

` Traceback (most recent call last): File "./sp_cli.py", line 157, in main( sys.argv ) File "./sp_cli.py", line 77, in main sp.update() File "/home/pi/domoticz/scripts/Sureflap/sure_petcare/sure_petcare/init.py", line 337, in update self.update_device_ids() File "/home/pi/domoticz/scripts/Sureflap/sure_petcare/sure_petcare/init.py", line 419, in update_device_ids household['default_flap'] = list(flaps.keys())[0] IndexError: list index out of range

`

therefromhere commented 5 years ago

@chriszuckerberg , @dzjr which model of catflap do you have?

If it's the new "Cat Door Connect" (https://www.surepetcare.com/en-nz/pet-doors/microchip-cat-flap-connect), as opposed to the original, larger "Pet Door Connect" (https://www.surepetcare.com/en-nz/pet-doors/microchip-pet-door-connect), the current code (at ed59e448bd41444845ae198c7662d068cdda2a1d) doesn't have its device id.

My pull request #7 should fix that.

chriszuckerberg commented 5 years ago

Hi!

To do this in Linux: first clone the repo: git clone https://github.com/rcastberg/sure_petcare.git

The run: python3 setup.py install or sudo python3 setup.py install

Then the module should be installed.

Ok, thank you, great application! Now it works for incomprehensible reasons. The only change was on my network to release IPv6 on the Fritzbox? Now I have only the question: Do I always have to do a "sudo sp_cli.py --update" before querying "sudo sp_cli.py ls_pets"?

chriszuckerberg commented 5 years ago

Ok. a day after, the next Problem:

alec@Server:~$ sudo sp_cli.py --update

Traceback (most recent call last): File "/usr/local/bin/sp_cli.py", line 4, in import('pkg_resources').run_script('sure-petcare==0.1', 'sp_cli.py') File "/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py", line 750, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py", line 1527, in run_script exec(code, namespace, namespace) File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/EGG-INFO/scripts/sp_cli.py", line 156, in main( sys.argv ) File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/EGG-INFO/scripts/sp_cli.py", line 75, in main with sp: File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/sure_petcare/init.py", line 646, in enter raise SPAPICacheLocked() sure_petcare.SPAPICacheLocked

Solution: sudo rm .surepet.cache sudo rm .surepet.cache.lock sudo sp_cli.py -e adress@gmx.de -p password --update

staebchen0 commented 5 years ago

Hi, I have two questions about the project:

  1. Can I also use the code without Home Assistant or is it only in connection with the Home Assistant?
  2. Does the project run under Windows 8?

I successfully installed the setup under windows. Can I connect to the flap now?

chriszuckerberg commented 5 years ago

Hi, I have two questions about the project:

  1. Can I also use the code without Home Assistant or is it only in connection with the Home Assistant?
  2. Does the project run under Windows 8? I successfully installed the setup under windows. Can I connect to the flap now?

I run the code directly on Ubuntu 18.04.2 LTS and ask the status via my daschboard via socket connection. It would be desirable that the query is a little faster to view the status faster, but the delay of about 30 seconds is probably due to the server at Sure-Petcare. Sunny greetings from the Allgäu

staebchen0 commented 5 years ago

I did not install Ubuntu. At the moment everything should run under Windows and later on the rasberry Pi

I have only recently started working with python. The installation of the packages was successful. I do not know exactly how to create a test script, for example, to get the battery status. Everything is listed in init.py, but I'm not sure how to build the script.

Do you have an example? I put the test script into the directory ure_petcare-master \ sure_petcare

chriszuckerberg commented 5 years ago

I did not install Ubuntu. At the moment everything should run under Windows and later on the rasberry Pi I have only recently started working with python. The installation of the packages was successful. I do not know exactly how to create a test script, for example, to get the battery status. Everything is listed in init.py, but I'm not sure how to build the script. Do you have an example? I put the test script into the directory ure_petcare-master \ sure_petcare

Rasperry also works under Linux, just like Ubuntu. possible arguments are: one of ls_flaps, ls_house, ls_pets, pet_tl, set_hid Entry in the directory sure_petcare: ./sp_cli.py ls_flaps comes the message: Cat Flap (123456) at 1.332V is Unlocked The battery status is not directly visible. Here you would have to extract the value 1.332V by script and define yourself as good or bad.

For example, I check via a regular thread only if the cat is in the house or out of the house and send with c.write_message ("cat_out") the state to my dashboard. The battery status tells me the normal app, so for me uninteresting.

# Sure-flap def SureFlap (): while true: os.system ("sp_cli.py --update") time.sleep (10) proc = poles ('sp_cli.py ls_pets', shell = true, stdout = PIPE,) output = proc.communicate () [0] if (output.find ("Outside")> 0):

print "Sheila outside."

                     for c in ws_clients:
                             c.write_message ("cat_out")
             else:
                     #print "Sheila inside"
                     for c in ws_clients:
                             c.write_message ("cat_in")
             time.sleep (10)

Excuse me, I do not know why the code can not be structured here :-(

staebchen0 commented 5 years ago

Thank you for your help :-)

I have the command: ./sp_cli.py ls_flaps tried it out

The following message appears:

Sure Petcare Connect CLI

--- WARNING ---

etc....

Although I created a user with a readonly role in the household and executed the following commands sp_cli.py --update -e xxxxtest@t-online.de -p xxxxxxx and then sp_cli.py --update

Did I forget something else?

chriszuckerberg commented 5 years ago

Thank you for your help :-)

I have the command: ./sp_cli.py ls_flaps tried it out

The following message appears:

Sure Petcare Connect CLI

--- WARNING ---

etc....

Although I created a user with a readonly role in the household and executed the following commands sp_cli.py --update -e pyhton.test@t-online.de -p xxxxxxx and then sp_cli.py --update

Did I forget something else?

Please try first with complete rights or with sudo. I have the experience that you have to do "sp_cli.py --update -e pyhton.test@t-online.de -p xxxxxxx" only once, after that "sp_cli.py --update" always goes. --update seems to read the data from the server and put it in the file ~/.surepet.cache or ~/.surepet.cache.lock which you can read out with sp_cli.py, see my entries above.

The rights are here: ls -alh in home directory shows -rw-r--r-- 1 root root 35K Mar 17 11:50 .surepet.cache -rw-r--r-- 1 alec www-data 4 Mar 17 11:54 .surepet.cache.lock drwxr-xr-x 8 alec www-data 4,0K Mär 10 10:55 sure_petcare

PS: the e-mail address and the password must be the same as the access data of Surepet. For me the script worked only after activation of IPv6 on the Fritzbox. Maybe also a source of error? Test it with: ping6 ipv6.google.com

chriszuckerberg commented 5 years ago

@staebchen0: new insights?

staebchen0 commented 5 years ago

Thanks for the hints :-) I had created the user in the household.

I have packed your sample program into a file and that seems to work. In the DOS window, however, only the DOS Promt comes back. But at least there is no warning - Sure Petcare Connect CLI

Why the program no message print outside or inside is still a mystery to me. I would at least expect an error message if it is not working properly

staebchen0 commented 5 years ago

Ping habe ich ausgeführt und das klappt :-)

staebchen0 commented 5 years ago

The rights are here: ls -alh in home directory shows -rw-r--r-- 1 root root 35K Mar 17 11:50 .surepet.cache -rw-r--r-- 1 alec www-data 4 Mar 17 11:54 .surepet.cache.lock drwxr-xr-x 8 alec www-data 4,0K Mär 10 10:55 sure_petcare``

da ich kein Linux nutze kann ich den Befehl ja nicht ausführen. Die Dateien habe ich unter Windows nicht gefunden. (können wir bei Deutsch bleiben?) - ist einfacher ;-)

staebchen0 commented 5 years ago

Hier das Script:

import time
import os

# Sure-flap
def SureFlap ():
    while true:
        os.system ("sp_cli.py --update")
        time.sleep (10)
        proc = poles ('sp_cli.py ls_pets', shell = true, stdout = PIPE,)
        output = proc.communicate () [0]
    if (output.find ("Outside")> 0):
        print ("Mila outside.")

        for c in ws_clients:
            c.write_message ("cat_out")
    else:
        print ("Mila inside")
        for c in ws_clients:
            c.write_message ("cat_in")
            time.sleep (10)`
staebchen0 commented 5 years ago

;-) hast du denn noch eine Idee, woran es liegen könnte?

chriszuckerberg commented 5 years ago

;-) hast du denn noch eine Idee, woran es liegen könnte?

Nun ja, das script ist so nicht allein lauffähig, da es eine Funktion def SureFlap (): ist. Du musst es zum testen so schreiben: https://github.com/chriszuckerberg/mila/blob/master/abfrage.py Aber sp_cli.py --update bzw. sudo sp_cli.py --update und dann sudo sp-cli.py ls_flaps muss ja erstmal so laufen.

chriszuckerberg commented 5 years ago

-rw-r--r-- 1 root root 35K Mar 17 11:50 .surepet.cache

-rw-r--r-- 1 alec www-data 4 Mar 17 11:54 .surepet.cache.lock drwxr-xr-x 8 alec www-data 4,0K Mär 10 10:55 sure_petcare`` Die Dateien habe ich unter Windows nicht gefunden.

Nochmal: sp_cli.py --update holt scheinbar die erforderlichen Daten vom SurePet-Server und schreibt sie in die Datei ~/.surepet.cache Hieraus werden dann wohl die Werte mit zB. sp_cli.py ls_flaps herausgelesen. D.h. wenn du die Datei ~/.surepet.cache nicht hast, kann sp_cli.py mit entsprechendem Kommando nichts finden. M.E. mußt du sicherstellen, das sp_cli.py -e[email] -p[passwort] --update schon mal die ~/.surepet.cache erstellen kann. Die ~/.surepet.cache hat das Attribute "versteckt". Zudem musst du als Email und Passwort dieselben eingeben, wie du zur Anmeldung deiner SurePet-Katzenklappe verwendet hast. Das von mir verwendete Script https://github.com/chriszuckerberg/mila/blob/master/abfrage.py dient mir nur zur Abfrage, ob die Katze draussen oder drinnen ist. Für dich ist es quasi erstmal unrelevant. Du könntest es weiter modifizieren, um später mal die erforderlichen Daten irgendwo anzeigen zu lassen (zB. Batteriespannung, etc.).

staebchen0 commented 5 years ago

Okay, Danke für deine Mühe :-) Gibt es auch die Möglichkeit die Klappe zu sperren?

Gruß Anja

chriszuckerberg commented 5 years ago

Okay, Danke für deine Mühe :-) Gibt es auch die Möglichkeit die Klappe zu sperren? Gruß Anja

Mit diesem GIT denke ich nicht, bin mir aber nicht sicher was über Home-Assistant läuft. Schau doch mal hier vorbei: https://community.home-assistant.io/t/sureflap-connect-pet-door/41488/39 Grüße Chris

staebchen0 commented 5 years ago

Dank Dir!

i00 commented 4 years ago

Mine fails when calling:

python3 sp_cli.py -e ****@****.*** -p **** --update
Traceback (most recent call last):
  File "sp_cli.py", line 156, in <module>
    main( sys.argv )
  File "sp_cli.py", line 76, in main
    sp.update()
  File "/config/sp/sure_petcare/sure_petcare/__init__.py", line 342, in update
    self.update_pet_status()
  File "/config/sp/sure_petcare/sure_petcare/__init__.py", line 528, in update_pet_status
    response = self._get_data(url)
  File "/config/sp/sure_petcare/sure_petcare/__init__.py", line 560, in _get_data
    'LastData': response.json(),
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
chriszuckerberg commented 4 years ago

Please try it as root and without a python3 command because it can run itself.

i00 commented 4 years ago

Ok will and let you know, when I get back to Australia.. overseas till Sunday

i00 commented 4 years ago

@chriszuckerberg Ok without the python3 it worked ... but now how do I read the cache file ... the file is not intelligible! ... and it's certainly not json as mentioned here: https://www.home-assistant.io/integrations/surepetcare/

chriszuckerberg commented 4 years ago

You get the data as follows: Initialize with: sp_cli.py -e your@email.org -p YourSurepetPassword --update

Data retrieval with: sp_cli.py ls_house => returns household_id sp_cli.py ls_flaps => returns flaps-id sp_cli.py ls_pets => returns pets-id


General instructions:

* First use: sp_cli.py --update -e <email_address> -p <password>

* Subsequently: sp_cli.py --update

After update, you can use any of the following switches to query the status of your pets, flap or household. Note that --update is mutually exclusive with any other option (other than --email or --pass).

positional arguments: cmd One of ls_flaps, ls_house, ls_pets, pet_tl, set_hid

optional arguments: -h, --help show this help message and exit -e EMAIL, --email EMAIL account email address -p PW, --pass PW account password --update update cache from Sure servers. Mutually exclusive with commands/queries. -c CACHE_FILE, --cache-file CACHE_FILE Cache file to use if not default

jimiwester commented 4 years ago

Can anyone tell me how to install this on Rasberry image of Home Assistant? I understand that there is a linux under it all, but its the "docker" version. Is this compatible with this HA version?

rathgar commented 4 years ago

@jimiwester It's baked in so you just add the integration as you would any other. Here are the docs for surepetcare integration.

jimiwester commented 4 years ago

Nice, great I was a bit afraid to just enter the config in case the code would crash my setup because it had to have more installed.

It works like a charm when I added the config.

Thanks!!

24 juni 2020 kl. 18:05 skrev Rue notifications@github.com<mailto:notifications@github.com>:

@jimiwesterhttps://github.com/jimiwester It's baked in so you just add the integration as you would any other. Here are the docs for surepetcarehttps://www.home-assistant.io/integrations/surepetcare/ integration.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/rcastberg/sure_petcare/issues/4#issuecomment-648913687, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQB2VOYGN6H7CN2DCD4NKBDRYIP57ANCNFSM4F3MKTKA.