Skip to content

Commit

Permalink
add webhook cleanup by host
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Feb 25, 2024
1 parent f26b3dc commit 5b97d33
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 6 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
"""Test run."""

import asyncio
import json

from pathlib import Path

from pytedee_async import TedeeClient
from pytedee_async.lock import TedeeLock


async def main():
with open("config.json", encoding="utf-8") as f:
with open(f"{Path(__file__).parent}/config.json", encoding="utf-8") as f:
data = json.load(f)
personal_token = data["personalToken"]
ip = data["ip"]
local_token = data["localToken"]

# client = await TedeeClient.create(personal_token, local_token, ip)
client = TedeeClient(local_ip=ip, local_token=local_token)
bridge = await client.get_local_bridge()
await client.cleanup_webhooks_by_host("test")
# bridge = await client.get_local_bridge()
# await client.delete_webhook(5)
# await client.register_webhook("http://192.168.1.151/events")
await client.get_locks()
Expand Down
17 changes: 17 additions & 0 deletions pytedee_async/tedee_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The TedeeClient class."""

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -512,3 +513,19 @@ async def delete_webhook(self, webhook_id: int) -> None:
except TedeeDataUpdateException as ex:
_LOGGER.debug("Unable to delete webhook: %s", str(ex))
_LOGGER.debug("Webhook deleted successfully.")

async def cleanup_webhooks_by_host(self, host: str) -> None:
"""Delete all webhooks for a specific host"""
_LOGGER.debug("Deleting webhooks for host %s", host)
try:
success, result = await self._local_api_call("/callback", HTTPMethod.GET)
except TedeeDataUpdateException as ex:
_LOGGER.debug("Unable to get webhooks: %s", str(ex))
return
if not success or result is None:
_LOGGER.debug("Unable to get webhooks")
return
for webhook in result:
if host in webhook["url"]:
await self.delete_webhook(webhook["id"])
_LOGGER.debug("Webhooks deleted successfully.")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pytedee_async",
version="0.2.13",
version="0.2.14",
author="Josef Zweck",
author_email="[email protected]",
description="A Tedee Lock Client package",
Expand Down

0 comments on commit 5b97d33

Please sign in to comment.