Skip to content

Add event listener to smartcam #1388

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Add event listener to smartcam #1388

wants to merge 8 commits into from

Conversation

sdb9696
Copy link
Collaborator

@sdb9696 sdb9696 commented Dec 18, 2024

No description provided.

@sdb9696 sdb9696 changed the title Add motion module and event listener to smarcam Add event listener to smartcam Dec 19, 2024
@@ -0,0 +1,12 @@
"""Module for listen event types."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to keep this inside smartcam for now, as the types are very onvif-specific(?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to have this at the top level so we can add other listen modules like for trigger logs and motion detection sensors.

@@ -71,6 +71,7 @@ def _legacy_type_to_class(_type: str) -> Any:
"device": None,
"feature": None,
"light": None,
"listen": None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a new sub group "camera", which would contain this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above I think we should keep this generic so we can add other listen modules like for trigger logs and motion detection sensors and have them all exposed with the one cli command. Users can provide the EventType options if they want to limit the events.

instance_id: str

async def _invoke_callback(self, event: EventType) -> None:
self.callback(event)
Copy link
Member

@rytilahti rytilahti Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug log the event here? I had to go and use wireshark to extract the full SOAP payload to see what's happening :-)

Here's one for the reference:

<?xml version="1.0"?>
<SOAP-ENV:Body>
  <wsnt:Notify>
    <wsnt:NotificationMessage>
      <wsnt:SubscriptionReference>
        <wsa5:Address>http://192.168.123.123:2020/event-1_2020</wsa5:Address>
      </wsnt:SubscriptionReference>
      <wsnt:Topic Dialect="http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet">tns1:VideoSource/MotionAlarm</wsnt:Topic>
      <wsnt:ProducerReference>
        <wsa5:Address>http://192.168.123.123:5656/event</wsa5:Address>
      </wsnt:ProducerReference>
      <wsnt:Message>
        <tt:Message PropertyOperation="Changed" UtcTime="2024-12-19T12:53:07Z">
          <tt:Source>
            <tt:SimpleItem Value="raw_vs1" Name="Source"/>
          </tt:Source>
          <tt:Data>
            <tt:SimpleItem Value="false" Name="State"/>
          </tt:Data>
        </tt:Message>
      </wsnt:Message>
    </wsnt:NotificationMessage>
  </wsnt:Notify>
</SOAP-ENV:Body>

See state = false, i.e., detection probably stopped?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now logging all messages although I'm worried this might be a bit too verbose. Maybe this should be a separate verbose flag to function?

@rytilahti rytilahti added the enhancement New feature or request label Dec 19, 2024
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 49.35897% with 79 lines in your changes missing coverage. Please review.

Project coverage is 91.60%. Comparing base (63f4f82) to head (ed98d58).
Report is 82 commits behind head on master.

Files with missing lines Patch % Lines
kasa/smartcam/modules/onviflisten.py 38.77% 60 Missing ⚠️
kasa/cli/listen.py 45.71% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1388      +/-   ##
==========================================
- Coverage   92.42%   91.60%   -0.83%     
==========================================
  Files         132      135       +3     
  Lines        8203     8354     +151     
  Branches      839      847       +8     
==========================================
+ Hits         7582     7653      +71     
- Misses        459      539      +80     
  Partials      162      162              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sdb9696 sdb9696 added this to the 0.9.1 milestone Dec 19, 2024
@sdb9696 sdb9696 modified the milestones: 0.9.1, 0.9.2 Dec 23, 2024
@DawidPietrykowski
Copy link
Contributor

TOPIC_EVENT_TYPE = {
    "tns1:RuleEngine/CellMotionDetector/Motion": EventType.MOTION_DETECTED,
    "tns1:RuleEngine/CellMotionDetector/People": EventType.PERSON_DETECTED,
    "tns1:RuleEngine/TamperDetector/Tamper": EventType.TAMPER_DETECTED,
}

How did you find those topics? There is also

  • Pet detection
  • Meow detection
  • Bark detection
  • Glass break detection
  • Vehicle detection

I just added pet detection configuration in #1465 and I'll try to add the rest soon. Would be great if these events were also included in this PR. I'm open to helping as I have one C220 available for testing.

Are you reverse engineering through packet sniffing or are those topics listed somewhere in the spec?

I hope this gets merged, tested locally and motion detection works well. Thanks for the effort.

@sdb9696 sdb9696 removed this from the 0.10.0 milestone Jan 23, 2025
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added stale and removed stale labels Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants