Coder Social home page Coder Social logo

sure_petcare's People

Contributors

rcastberg avatar rcastbergw avatar strix-technica avatar therefromhere avatar

Stargazers

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

Watchers

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

sure_petcare's Issues

Read and write?

Hi, this looks awesome! Does this allow you to set the state (eg locked / unlocked) or just read the state? Thanks :)

Compatibility with API changes for app version 2.0.5.54

Heads up, it looks like Sureflap changed their API sometime within the last week, to add support for multiple curfews in the current version of the app (2.0.5.54-9771d74), so there's now a list of curfews instead of a single lock/unlock time.

This has broken my integration ( https://github.com/therefromhere/sureflap_gcloud ), I think it's caused some issues with this library as well.

Incidentally, I was thinking about how we could detect or document these sorts of changes - one option would be adding asserts of the API return data structure, eg by using pydantic (though that would require Python >=3.6).

Home Assistant

Nice work on the surepet support!

I'm trying to get the home assistant sensor working, but I keep getting the following error:

Error while setting up platform sure_petflap Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform SLOW_SETUP_MAX_WAIT, loop=hass.loop) File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/home/hass/.homeassistant/custom_components/sensor/sure_petflap.py", line 59, in setup_platform username = config.get(CONF_USERNAME) NameError: name 'CONF_USERNAME' is not defined

I'm not sure what goes wrong. The code looks alright. I'm running hass 0.80.2. any Ideas?

Catflap without homepod

Hello,

I'm interested in sureflap catflap. Do you think a new sureflap catflap can be controlled/parametrized with code based on yours, without ever being connected to their homepod ? (that i would'nt buy)

Thanks in advance

update_pet_status fails if pet is in unknown position

First off, great work on this project! A minor bug I've found -

I'm seeing a 204 response from https://app.api.surehub.io/api/pet/<pet_id>/position for a cat that's been added to the catflap but has never gone through it, so they're not showing as either inside or outside in the app.

_get_data doesn't handle 204, so it blows up trying to JSON decode an empty response (with json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)).

The no-code workaround is to explicitly set any newly added pets to a location (eg inside) using the app.

Can't seem to install add on

Hi there, I'm probably being a donut but I can't seem to add this guthub repository via either HACS or config of the Hassio GUI.

Here is the error log when I try to add it:
20-11-09 15:08:00 ERROR (MainThread) [supervisor.utils.json] Can't read json from /data/addons/git/dc3846f2/repository.json: [Errno 2] No such file or directory: '/data/addons/git/dc3846f2/repository.json'
20-11-09 15:08:00 ERROR (MainThread) [supervisor.store] https://github.com/rcastberg/sure_petcare is not a valid add-on repository.

Please can you help?

Many thanks,
Ed

Hass.IO Install guide

I´m using HASS.IO

Does anyone have it working on hass.io?

manifest.json is missing

Suggestion: lock in cat ("indoor cat")/ free cat ("outdoor cat")

great project - is it still maintained (2 years old)?

My suggestion is to add code that allows to modify a cat to an "indoor cat", which locks them in, and back to an "outdoor cat", e.g. to keep one cat inside while others can leave (because of being sick, pending vet visit, etc). The app and web frontend allows to do this, but unfortunately without a timer; it is not possible in the app to say "modify cat x to indoor cat at 3am", so the cat can still enter and leave freely until then, but after this, needs to stay inside (because, e.g., a vet visit in the morning), while other cats - I have 3 - can enter and leave freely. Moreover, the feature is hidden deep inside the app and I originally had trouble finding it.

Actually I've already written code that works; feel free to add it in a way that you seem fit, if you like. I did not (yet) figure out how to read the status, because my priority was setting it. Of course you might decide against it, because this involves writing data to the server instead of only readin data.

The main modification is to add a method in class SurePetFlapMixin (line 684 of __init__.py) like this:

    def set_pet_profile( self, pet_id = None, name = None, profile = None, household_id = None ):
        """
        Set lock mode of a pet (3 is locked, 2 is free)
        """
        household_id = household_id or self.default_household
        if profile is None or type(profile) != int:
            raise ValueError('Please define a profile int value')
        if pet_id is None and name is None:
            raise ValueError('Please define pet_id or name')
        if pet_id is None:
            pet_id = self.get_pet_id_by_name(name)
        pet_id = int(pet_id)
        try:
            tag_id = self.household['pets'][pet_id]['tag_id']
            pet_name = self.household['pets'][pet_id]['name']
        except KeyError as e:
            raise SPAPIUnknownPet(str(e))
        device_id = self.household['default_flap']

        headers = self._create_header()
        data = {"profile": profile}
        url = '%s/%s/tag/%s' % (_URL_DEV, device_id, tag_id)
        response = self.s.put(url, headers=headers, json=data)
        if response.status_code == 401:
            self.update_authtoken(force=True)
            if 'headers' in kwargs and 'Authorization' in kwargs['headers']:
                kwargs['headers']['Authorization'] = 'Bearer ' + self.cache['AuthToken']
                response = self.s.post(_URL_AUTH, headers=headers, json=data)
            else:
                raise SPAPIException('Auth required but not present in header')

        response_data = response.json()
        return 'data' in response_data and 'profile' in response_data['data'] and \
               response_data['data']['profile'] == profile

And adding to sp_cli.py

@cmd
def cmd_pet_lock( sp: sure_petcare.SurePetFlapMixin, args ):
    """
    For each pet in household, lock it inside
    """
    try:
        name = args.cmd[1]
    except IndexError:
        exit('need pet name (enclose in quotes if necessary)')

    if sp.set_pet_profile( name = name, profile=3 ):
        print("ok")
    else:
        print("fail")

@cmd
def cmd_pet_free( sp: sure_petcare.SurePetFlapMixin, args ):
    """
    For each pet in household, lock it inside
    """
    try:
        name = args.cmd[1]
    except IndexError:
        exit('need pet name (enclose in quotes if necessary)')

    if sp.set_pet_profile( name = name, profile=2 ):
        print("ok")
    else:
        print("fail")

You might want to rename things and/or change code style. It basically PUTs to an URL .../device/<flap-id>/tag/<pet-tag-id> with a json {"profile": 3} to lock in, and {"profile": 2} to free (I don't know if other profile values might have different effects).

PS: It is possible to read the status via URL _URL_DEV and parameters to

        params = (
            ('with[]', 'tags'),
        )

The last record in datalist then has a tagslist (of all pets), each with id== pet tag-id and profile set to 2 or 3 (plus update timestamp in updated_at)

Animo?

Just curious if there has been any work done towards bringing the Animo data in also.

Derivation of DeviceID

After a bit of digging, the device_id sent as part of the initial login to generate the subsequently token is done using the following JS library

https://github.com/Valve/fingerprintjs

Here's the bit of code that does the login

$scope.login = function() { var fingerprint = String(new Fingerprint().get()); $http.post($rootScope.config.api+'/api/auth/login', { email_address: $scope.login.email, password: $scope.login.password, device_id: fingerprint }).success(function(data, status, headers, config){ //setting the user info details

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.