-
Notifications
You must be signed in to change notification settings - Fork 16
Add shortened common onvif namespace prefixes #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4a11e13
Add shortened common onvif namespace prefixes.
jterrace 85bdf5d
Merge branch 'async' into tapo-500
bdraco bd4cad0
chore(pre-commit.ci): auto fixes
pre-commit-ci[bot] 6c3f1df
Merge branch 'async' into tapo-500
bdraco 4ea62e8
Update requirements.txt
bdraco 65630b0
Merge branch 'async' into tapo-500
bdraco 5d3cbef
Merge branch 'async' into tapo-500
bdraco f4658ed
Merge branch 'async' into tapo-500
bdraco 927df8d
fix examples
bdraco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,107 @@ | ||
"""Example to fetch pullpoint events.""" | ||
|
||
from aiohttp import web | ||
import argparse | ||
import asyncio | ||
import datetime as dt | ||
import logging | ||
import onvif | ||
import os.path | ||
import pprint | ||
import sys | ||
|
||
SUBSCRIPTION_TIME = dt.timedelta(minutes=1) | ||
WAIT_TIME = dt.timedelta(seconds=30) | ||
|
||
from onvif import ONVIFCamera | ||
|
||
logging.getLogger("zeep").setLevel(logging.DEBUG) | ||
def subscription_lost(): | ||
print("subscription lost") | ||
|
||
|
||
async def run(): | ||
mycam = ONVIFCamera( | ||
"192.168.3.10", | ||
80, | ||
"hass", | ||
"peek4boo", | ||
wsdl_dir="/home/jason/python-onvif-zeep-async/onvif/wsdl", | ||
async def post_handler(request): | ||
print(request) | ||
print(request.url) | ||
for k, v in request.headers.items(): | ||
print(f"{k}: {v}") | ||
body = await request.content.read() | ||
print(body) | ||
return web.Response() | ||
|
||
|
||
async def run(args): | ||
mycam = onvif.ONVIFCamera( | ||
args.host, | ||
args.port, | ||
args.username, | ||
args.password, | ||
wsdl_dir=f"{os.path.dirname(onvif.__file__)}/wsdl/", | ||
) | ||
await mycam.update_xaddrs() | ||
|
||
if not await mycam.create_pullpoint_subscription(): | ||
print("PullPoint not supported") | ||
return | ||
|
||
event_service = mycam.create_events_service() | ||
properties = await event_service.GetEventProperties() | ||
print(properties) | ||
capabilities = await event_service.GetServiceCapabilities() | ||
print(capabilities) | ||
|
||
pullpoint = mycam.create_pullpoint_service() | ||
await pullpoint.SetSynchronizationPoint() | ||
req = pullpoint.create_type("PullMessages") | ||
req.MessageLimit = 100 | ||
req.Timeout = dt.timedelta(seconds=30) | ||
messages = await pullpoint.PullMessages(req) | ||
print(messages) | ||
|
||
subscription = mycam.create_subscription_service("PullPointSubscription") | ||
termination_time = ( | ||
(dt.datetime.utcnow() + dt.timedelta(days=1)) | ||
.isoformat(timespec="seconds") | ||
.replace("+00:00", "Z") | ||
) | ||
await subscription.Renew(termination_time) | ||
await subscription.Unsubscribe() | ||
capabilities = await mycam.get_capabilities() | ||
pprint.pprint(capabilities) | ||
|
||
if args.notification: | ||
app = web.Application() | ||
app.add_routes([web.post("/", post_handler)]) | ||
runner = web.AppRunner(app) | ||
await runner.setup() | ||
site = web.TCPSite(runner, args.notification_address, args.notification_port) | ||
await site.start() | ||
|
||
receive_url = f"http://{args.notification_address}:{args.notification_port}/" | ||
manager = await mycam.create_notification_manager( | ||
receive_url, | ||
SUBSCRIPTION_TIME, | ||
subscription_lost, | ||
) | ||
await manager.set_synchronization_point() | ||
|
||
print(f"waiting for messages at {receive_url}...") | ||
await asyncio.sleep(WAIT_TIME.total_seconds()) | ||
|
||
await manager.shutdown() | ||
await runner.cleanup() | ||
else: | ||
manager = await mycam.create_pullpoint_manager( | ||
SUBSCRIPTION_TIME, subscription_lost | ||
) | ||
await manager.set_synchronization_point() | ||
|
||
pullpoint = manager.get_service() | ||
print("waiting for messages...") | ||
messages = await pullpoint.PullMessages( | ||
{ | ||
"MessageLimit": 100, | ||
"Timeout": WAIT_TIME, | ||
} | ||
) | ||
print(messages) | ||
|
||
await manager.shutdown() | ||
|
||
await mycam.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
def main(): | ||
logging.getLogger("zeep").setLevel(logging.DEBUG) | ||
|
||
parser = argparse.ArgumentParser(prog="EventTester") | ||
parser.add_argument("--host", default="192.168.3.10") | ||
parser.add_argument("--port", type=int, default=80) | ||
parser.add_argument("--username", default="hass") | ||
parser.add_argument("--password", default="peek4boo") | ||
parser.add_argument("--notification", action=argparse.BooleanOptionalAction) | ||
parser.add_argument("--notification_address") | ||
parser.add_argument("--notification_port", type=int, default=8976) | ||
|
||
args = parser.parse_args(sys.argv[1:]) | ||
if args.notification and args.notification_address is None: | ||
parser.error("--notification requires --notification_address") | ||
|
||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(run()) | ||
loop.run_until_complete(run(args)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Package | ||
ciso8601>=2.1.3 | ||
httpx==0.28.0 | ||
zeep[async]==4.3.1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.