Skip to main content

Provides ability to connect and control a PetSafe Smart Feed device using the PetSafe-SmartFeed API.

Project description

PetSafe Smart Feed - Python API

Connect and control a PetSafe Smart Feed device using the PetSafe-SmartFeed API.

BREAKING CHANGE: Version 2.0 uses the new PetSafe API. You will need to request new tokens.

PetSafe will lock your account if you request data more often than once per 5 minutes.

Installation

pip install petsafe-smartfeed

If installing from source code, python setup.py install

Login tokens

You must use tokens to interact with the PetSafe Smart-Feed API.
There are two methods to retrieve tokens:

Get tokens using command line

  1. Execute python -m petsafe_smartfeed [email_address] to request an email code.
  2. Check your email for an email code from PetSafe.
  3. Enter your code to generate tokens.

Get tokens using Python

import petsafe_smartfeed as sf


# replace with your email address
client = sf.PetSafeClient(email="email@example.com")
client.request_code()

# check your email for a code
code = input("Enter email code: ")
token = client.request_tokens_from_code(code)

print("email:", client.email)
print("id_token:", client.id_token)
print("refresh_token:", client.refresh_token)
print("access_token:", client.access_token)

Example usage

List devices

import petsafe_smartfeed as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_feeders(client)

# print all feeders
for device in devices:
    print(device)

Feed 1/8 cup at normal speed

import petsafe_smartfeed as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_feeders(client)

# get the first feeder
feeder = devices[0]
feeder.feed(amount=1, slow_feed=False)

Get current battery level (0 - 100)

import petsafe_smartfeed as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_feeders(client)

# get the first feeder
feeder = devices[0]
print(feeder.battery_level)

Get current food level

import petsafe_smartfeed as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_feeders(client)

# get the first feeder
feeder = devices[0]
status = feeder.food_low_status

if status == 0:
    print("Feeder has food.")
elif status == 1:
    print("Feeder is low on food.")
elif status == 2:
    print("Feeder is out of food.")

Contributing

All contributions are welcome. Please, feel free to create a pull request!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

petsafe_smartfeed-2.2.tar.gz (6.7 kB view details)

Uploaded Source

File details

Details for the file petsafe_smartfeed-2.2.tar.gz.

File metadata

  • Download URL: petsafe_smartfeed-2.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for petsafe_smartfeed-2.2.tar.gz
Algorithm Hash digest
SHA256 6c335c9e4b0f65e74ddd6bbbbba49b6f09c9b81a84e78462b08fad47a060c3e3
MD5 338209448c711ef259ee1308f61245d8
BLAKE2b-256 c073f36dff669cd5d0867c29f5da90829ed8a82489bbccb695ab38b6d78e5619

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page