# 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`
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 [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
```python
import petsafe 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 feeders
```python
import petsafe 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
```python
import petsafe 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)
```python
import petsafe 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
```python
import petsafe 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.")
```
# get litterboxes
```python
import petsafe 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_litterboxes(client)
# print all litterboxes
for device in devices:
print(device)
```
# get litterbox activity
```python
import petsafe 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_litterboxes(client)
litterbox = devices[0]
print(litterbox.get_schedule())
```
# rake the litterbox
```python
import petsafe 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_litterboxes(client)
litterbox = devices[0]
litterbox.rake()
```
# modify the litterbox rake timer
```python
import petsafe 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_litterboxes(client)
litterbox = devices[0]
litterbox.modify_timer(15)
```
# reset the litterbox rake count
```python
import petsafe 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_litterboxes(client)
litterbox = devices[0]
litterbox.reset()
```
## Contributing
All contributions are welcome.
Please, feel free to create a pull request!
Raw data
{
"_id": null,
"home_page": "https://github.com/dcmeglio/petsafe",
"name": "petsafe",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Jordan Stremming & Dominick Meglio",
"author_email": "dmeglio@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/7e/34/934b495e2ef0fc9761876246fb8f352bbee99509681841f9ea5fa6001132/petsafe-2.0.7.tar.gz",
"platform": null,
"description": "# PetSafe Smart Feed - Python API\r\nConnect and control a PetSafe Smart Feed device using the PetSafe-SmartFeed API.\r\n\r\n> **BREAKING CHANGE:** Version 2.0 uses the new PetSafe API.\r\n> You will need to request new tokens.\r\n\r\n> PetSafe will lock your account if you request data more often than once per 5 minutes.\r\n\r\n## Installation\r\n`pip install petsafe`\r\n\r\nIf installing from source code,\r\n`python setup.py install`\r\n\r\n## Login tokens\r\nYou **must** use tokens to interact with the PetSafe Smart-Feed API. \r\nThere are two methods to retrieve tokens:\r\n\r\n#### Get tokens using command line\r\n1. Execute `python -m petsafe [email_address]` to request an email code.\r\n2. Check your email for an email code from PetSafe.\r\n3. Enter your code to generate tokens.\r\n\r\n#### Get tokens using Python\r\n```python\r\nimport petsafe as sf\r\n\r\n\r\n# replace with your email address\r\nclient = sf.PetSafeClient(email=\"email@example.com\")\r\nclient.request_code()\r\n\r\n# check your email for a code\r\ncode = input(\"Enter email code: \")\r\ntoken = client.request_tokens_from_code(code)\r\n\r\nprint(\"email:\", client.email)\r\nprint(\"id_token:\", client.id_token)\r\nprint(\"refresh_token:\", client.refresh_token)\r\nprint(\"access_token:\", client.access_token)\r\n```\r\n\r\n\r\n## Example usage\r\n#### List feeders\r\n\r\n```python\r\nimport petsafe as sf\r\n\r\nclient = sf.PetSafeClient(email=\"email@example.com\",\r\n id_token=\"YOUR_ID_TOKEN\",\r\n refresh_token=\"YOUR_REFRESH_TOKEN\",\r\n access_token=\"YOUR_ACCESS_TOKEN\")\r\ndevices = sf.devices.get_feeders(client)\r\n\r\n# print all feeders\r\nfor device in devices:\r\n print(device)\r\n\r\n```\r\n#### Feed 1/8 cup at normal speed\r\n```python\r\nimport petsafe as sf\r\n\r\nclient = sf.PetSafeClient(email=\"email@example.com\",\r\n id_token=\"YOUR_ID_TOKEN\",\r\n refresh_token=\"YOUR_REFRESH_TOKEN\",\r\n access_token=\"YOUR_ACCESS_TOKEN\")\r\ndevices = sf.devices.get_feeders(client)\r\n\r\n# get the first feeder\r\nfeeder = devices[0]\r\nfeeder.feed(amount=1, slow_feed=False)\r\n\r\n```\r\n#### Get current battery level (0 - 100)\r\n```python\r\nimport petsafe as sf\r\n\r\nclient = sf.PetSafeClient(email=\"email@example.com\",\r\n id_token=\"YOUR_ID_TOKEN\",\r\n refresh_token=\"YOUR_REFRESH_TOKEN\",\r\n access_token=\"YOUR_ACCESS_TOKEN\")\r\ndevices = sf.devices.get_feeders(client)\r\n\r\n# get the first feeder\r\nfeeder = devices[0]\r\nprint(feeder.battery_level)\r\n\r\n```\r\n#### Get current food level\r\n```python\r\nimport petsafe as sf\r\n\r\nclient = sf.PetSafeClient(email=\"email@example.com\",\r\n id_token=\"YOUR_ID_TOKEN\",\r\n refresh_token=\"YOUR_REFRESH_TOKEN\",\r\n access_token=\"YOUR_ACCESS_TOKEN\")\r\ndevices = sf.devices.get_feeders(client)\r\n\r\n# get the first feeder\r\nfeeder = devices[0]\r\nstatus = feeder.food_low_status\r\n\r\nif status == 0:\r\n print(\"Feeder has food.\")\r\nelif status == 1:\r\n print(\"Feeder is low on food.\")\r\nelif status == 2:\r\n print(\"Feeder is out of food.\")\r\n\r\n```\r\n\r\n# get litterboxes\r\n```python\r\nimport petsafe as sf\r\n\r\nclient = sf.PetSafeClient(email=\"email@example.com\",\r\n id_token=\"YOUR_ID_TOKEN\",\r\n refresh_token=\"YOUR_REFRESH_TOKEN\",\r\n access_token=\"YOUR_ACCESS_TOKEN\")\r\ndevices = sf.devices.get_litterboxes(client)\r\n\r\n# print all litterboxes\r\nfor device in devices:\r\n print(device)\r\n\r\n```\r\n\r\n# get litterbox activity\r\n```python\r\nimport petsafe as sf\r\n\r\nclient = sf.PetSafeClient(email=\"email@example.com\",\r\n id_token=\"YOUR_ID_TOKEN\",\r\n refresh_token=\"YOUR_REFRESH_TOKEN\",\r\n access_token=\"YOUR_ACCESS_TOKEN\")\r\ndevices = sf.devices.get_litterboxes(client)\r\n\r\nlitterbox = devices[0]\r\nprint(litterbox.get_schedule())\r\n\r\n```\r\n\r\n# rake the litterbox\r\n```python\r\nimport petsafe as sf\r\n\r\nclient = sf.PetSafeClient(email=\"email@example.com\",\r\n id_token=\"YOUR_ID_TOKEN\",\r\n refresh_token=\"YOUR_REFRESH_TOKEN\",\r\n access_token=\"YOUR_ACCESS_TOKEN\")\r\ndevices = sf.devices.get_litterboxes(client)\r\n\r\nlitterbox = devices[0]\r\nlitterbox.rake()\r\n\r\n```\r\n\r\n# modify the litterbox rake timer\r\n```python\r\nimport petsafe as sf\r\n\r\nclient = sf.PetSafeClient(email=\"email@example.com\",\r\n id_token=\"YOUR_ID_TOKEN\",\r\n refresh_token=\"YOUR_REFRESH_TOKEN\",\r\n access_token=\"YOUR_ACCESS_TOKEN\")\r\ndevices = sf.devices.get_litterboxes(client)\r\n\r\nlitterbox = devices[0]\r\nlitterbox.modify_timer(15)\r\n\r\n```\r\n\r\n# reset the litterbox rake count\r\n```python\r\nimport petsafe as sf\r\n\r\nclient = sf.PetSafeClient(email=\"email@example.com\",\r\n id_token=\"YOUR_ID_TOKEN\",\r\n refresh_token=\"YOUR_REFRESH_TOKEN\",\r\n access_token=\"YOUR_ACCESS_TOKEN\")\r\ndevices = sf.devices.get_litterboxes(client)\r\n\r\nlitterbox = devices[0]\r\nlitterbox.reset()\r\n\r\n```\r\n\r\n## Contributing\r\nAll contributions are welcome. \r\nPlease, feel free to create a pull request!\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Provides ability to connect and control a PetSafe Smart Feed and Scoopfree device using the PetSafe API.",
"version": "2.0.7",
"project_urls": {
"Homepage": "https://github.com/dcmeglio/petsafe"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3ca54bd86bd4c8b945b8ac6c0f75397d1fe474aafad40d6d78490297ac122d5a",
"md5": "8cac866c7d0b9762e2b5ac56971ffebb",
"sha256": "51e6b6c63fd7b0aa87c18cdff5db646c49828afb369cb76d105392aea555973e"
},
"downloads": -1,
"filename": "petsafe-2.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8cac866c7d0b9762e2b5ac56971ffebb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 9044,
"upload_time": "2024-08-28T01:54:35",
"upload_time_iso_8601": "2024-08-28T01:54:35.089327Z",
"url": "https://files.pythonhosted.org/packages/3c/a5/4bd86bd4c8b945b8ac6c0f75397d1fe474aafad40d6d78490297ac122d5a/petsafe-2.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7e34934b495e2ef0fc9761876246fb8f352bbee99509681841f9ea5fa6001132",
"md5": "ad9e0f09d6e91083da5bc4e7d1e44fb3",
"sha256": "58cbe0f9fdddae36c5b6618bc1718dea2014011617b23a8fa84f96860f12b012"
},
"downloads": -1,
"filename": "petsafe-2.0.7.tar.gz",
"has_sig": false,
"md5_digest": "ad9e0f09d6e91083da5bc4e7d1e44fb3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 9195,
"upload_time": "2024-08-28T01:54:37",
"upload_time_iso_8601": "2024-08-28T01:54:37.810541Z",
"url": "https://files.pythonhosted.org/packages/7e/34/934b495e2ef0fc9761876246fb8f352bbee99509681841f9ea5fa6001132/petsafe-2.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-28 01:54:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dcmeglio",
"github_project": "petsafe",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "petsafe"
}