Skip to content

Conversation

JPHutchins
Copy link
Contributor

@JPHutchins JPHutchins commented Dec 13, 2020

Proposed change

Make torrent "id" attribute available in fired events as requested here: https://community.home-assistant.io/t/transmission-add-torrent-id-to-event-data/254822

Eliminate unnecessary cast to lists, iterate sets directly.

Update objects before firing event that says they were updated!

Clarify existing code with better variable names and make consistent across the three methods that check for changes and fire events.

TODO:

  • update docs - @AlecRust can you look at this? I don't use events so I am not sure how to explain it!
  • next PR use device triggers?

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @engrbm87, mind taking a look at this pull request as its been labeled with an integration (transmission) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@AlecRust
Copy link

@JPHutchins nice! Sure here's the docs PR: home-assistant/home-assistant.io#15905

The docs assume this will work:

service: transmission.remove_torrent
data:
  name: "Transmission"
  id: "{{trigger.event.data.id}}"

Instead of something like this:

service: transmission.remove_torrent
data:
  name: "Transmission"
  id: "{{trigger.event.data.id | int}}"

@JPHutchins
Copy link
Contributor Author

@AlecRust Awesome, thanks! As far as I can tell the data should an int at each step of the way so the docs you provided are correct.

I think what's going on is that the raw torrent object has ints and strings whereas when you use the workaround accessing attributes of the HA sensor everything is strings necessitating the | int - I could be wrong and then we bugfix it!

I will ask on the community threads about other potentially useful attributes as outlined in the spec: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.txt

Technically we could provide an event that is simply {torrent} and you would have access to the actual torrent object for every event... my opinion is this is too much data in the event.

{
          "activityDate": 1607716468,
          "addedDate": 1607713708,
          "announceResponse": 0,
          "announceURL": 0,
          "bandwidthPriority": 0,
          "comment": "Garuda",
          "corruptEver": 0,
          "creator": "mktorrent 1.1",
          "dateCreated": 1607201653,
          "desiredAvailable": 5183946752,
          "doneDate": 0,
          "downloadDir": "/downloads/complete",
          "downloadLimit": 100,
          "downloadLimited": false,
          "downloadedEver": 27879026,
          "downloaders": 0,
          "editDate": 0,
          "error": 0,
          "errorString": "",
          "eta": 316403,
          "etaIdle": -1,
          "fileStats": [
            {
              "bytesCompleted": 24107008,
              "priority": 0,
              "wanted": true
            }
          ],
          "files": [
            {
              "bytesCompleted": 24107008,
              "length": 5208053760,
              "name": "garuda-kde-ultimate-linux-tkg-bmq-201205.iso"
            }
          ],
          "hashString": "1d981fa2cb881c3ff3f5f3d98c3ccc5253b4b943",
          "haveUnchecked": 6504448,
          "haveValid": 17602560,
          "honorSessionLimits": 0,
          "id": 1,
          "isFinished": false,
          "isPrivate": true,
          "isStalled": false,
          "labels": [],
          "lastAnnounceTime": 0,
          "lastScrapeTime": 0,
          "leechers": 0,
          "leftUntilDone": 5183946752,
          "magnetLink": "magnet:?xt=urn:btih:1d981fa2cb881c3ff3f5f3d98c3ccc5253b4b943&dn=garuda-kde-ultimate-linux-tkg-bmq-201205.iso&tr=udp%3A%2F%2Flonewolf-builder.duckdns.org%3A23069&tr=http%3A%2F%2Ftorrent.resonatingmedia.com%3A6969%2Fannounce&ws=https%3A%2F%2Fbuilds.garudalinux.org%2Fiso%2Fgaruda%2Fkde%2F201205%2Fgaruda-kde-ultimate-linux-tkg-bmq-201205.iso&ws=https%3A%2F%2Fosdn.net%2Fprojects%2Fgaruda-linux%2Fstorage%2Fkde%2F201205%2Fgaruda-kde-ultimate-linux-tkg-bmq-201205.iso&ws=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fgaruda-linux%2Ffiles%2Fkde%2F201205%2Fgaruda-kde-ultimate-linux-tkg-bmq-201205.iso",
          "manualAnnounceTime": -1,
          "maxConnectedPeers": 50,
          "metadataPercentComplete": 1,
          "name": "garuda-kde-ultimate-linux-tkg-bmq-201205.iso",
          "nextAnnounceTime": 0,
          "nextScrapeTime": 0,
          "peer-limits": 0,
          "peersConnected": 1,
          "peersFrom": {
            "fromCache": 1,
            "fromDht": 0,
            "fromIncoming": 0,
            "fromLpd": 0,
            "fromLtep": 0,
            "fromPex": 0,
            "fromTracker": 0
          },
          "peersGettingFromUs": 0,
          "peersKnown": 0,
          "peersSendingToUs": 1,
          "percentDone": 0.0046,
          "pieceCount": 2484,
          "pieceSize": 2097152,
          "pieces": "gAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAQAAAAAAAIAAAAAAAAAgAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABA=",
          "priorities": [
            0
          ],
          "queuePosition": 0,
          "rateDownload": 16000,
          "rateUpload": 0,
          "recheckProgress": 0,
          "scrapeResponse": 0,
          "scrapeURL": 0,
          "secondsDownloading": 2144,
          "secondsSeeding": 0,
          "seedIdleLimit": 30,
          "seedIdleMode": 0,
          "seedRatioLimit": 2,
          "seedRatioMode": 0,
          "seeders": 0,
          "sizeWhenDone": 5208053760,
          "startDate": 1607714631,
          "status": 4,
          "status": 4,
          "swarmSpeed": 0,
          "timesCompleted": 0,
          "torrentFile": "/config/torrents/1d981fa2cb881c3ff3f5f3d98c3ccc5253b4b943.torrent",
          "totalSize": 5208053760,
          "trackerStats": [
            {
              "announce": "udp://lonewolf-builder.duckdns.org:23069",
              "announceState": 1,
              "downloadCount": -1,
              "hasAnnounced": true,
              "hasScraped": true,
              "host": "udp://lonewolf-builder.duckdns.org:23069",
              "id": 0,
              "isBackup": false,
              "lastAnnouncePeerCount": 0,
              "lastAnnounceResult": "Connection failed",
              "lastAnnounceStartTime": 0,
              "lastAnnounceSucceeded": false,
              "lastAnnounceTime": 1607714781,
              "lastAnnounceTimedOut": false,
              "lastScrapeResult": "Connection failed",
              "lastScrapeStartTime": 0,
              "lastScrapeSucceeded": false,
              "lastScrapeTime": 1607715691,
              "lastScrapeTimedOut": false,
              "leecherCount": -1,
              "nextAnnounceTime": 1607716590,
              "nextScrapeTime": 1607719320,
              "scrape": "udp://lonewolf-builder.duckdns.org:23069",
              "scrapeState": 1,
              "seederCount": -1,
              "tier": 0
            },
            {
              "announce": "http://torrent.resonatingmedia.com:6969/announce",
              "announceState": 1,
              "downloadCount": 4,
              "hasAnnounced": true,
              "hasScraped": true,
              "host": "http://torrent.resonatingmedia.com:6969",
              "id": 1,
              "isBackup": false,
              "lastAnnouncePeerCount": 6,
              "lastAnnounceResult": "Success",
              "lastAnnounceStartTime": 1607716300,
              "lastAnnounceSucceeded": true,
              "lastAnnounceTime": 1607716300,
              "lastAnnounceTimedOut": false,
              "lastScrapeResult": "",
              "lastScrapeStartTime": 0,
              "lastScrapeSucceeded": true,
              "lastScrapeTime": 1607716300,
              "lastScrapeTimedOut": false,
              "leecherCount": 2,
              "nextAnnounceTime": 1607717941,
              "nextScrapeTime": 1607718100,
              "scrape": "http://torrent.resonatingmedia.com:6969/scrape",
              "scrapeState": 1,
              "seederCount": 4,
              "tier": 1
            }
          ],
          "trackers": [
            {
              "announce": "udp://lonewolf-builder.duckdns.org:23069",
              "id": 0,
              "scrape": "udp://lonewolf-builder.duckdns.org:23069",
              "tier": 0
            },
            {
              "announce": "http://torrent.resonatingmedia.com:6969/announce",
              "id": 1,
              "scrape": "http://torrent.resonatingmedia.com:6969/scrape",
              "tier": 1
            }
          ],
          "uploadLimit": 100,
          "uploadLimitMode": 0,
          "uploadLimited": false,
          "uploadRatio": 0.04,
          "wanted": [
            1
          ],
          "webseeds": [
            "https://builds.garudalinux.org/iso/garuda/kde/201205/garuda-kde-ultimate-linux-tkg-bmq-201205.iso",
            "https://osdn.net/projects/garuda-linux/storage/kde/201205/garuda-kde-ultimate-linux-tkg-bmq-201205.iso",
            "https://sourceforge.net/projects/garuda-linux/files/kde/201205/garuda-kde-ultimate-linux-tkg-bmq-201205.iso"
          ],
          "webseedsSendingToUs": 3
        },

@AlecRust
Copy link

@JPHutchins agree that whole object is probably not necessary. I think just the items that make combining the different events and services possible are important. Saying that attributes such as bytesCompleted look potentially useful for including filesize of download in notification etc.

Copy link

@TFyre TFyre left a comment

Choose a reason for hiding this comment

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

LGTM

@allenporter allenporter changed the title Transmission event torrent Add torrent id to Transmission events Jan 8, 2021
@allenporter allenporter merged commit 793adb7 into home-assistant:dev Jan 8, 2021
@frenck
Copy link
Member

frenck commented Jan 8, 2021

We should have used actual type hinting. There is no need to use comments for type hints.

Please address that in a new PR @JPHutchins

@JPHutchins
Copy link
Contributor Author

JPHutchins commented Jan 8, 2021 via email

KJonline pushed a commit to Pyhass/core that referenced this pull request Jan 9, 2021
* 'dev' of https://github.com/home-assistant/core: (98 commits)
  Bump pymyq to 2.0.13 (home-assistant#44961)
  Add zwave to ozw migration (home-assistant#39081)
  Add pressure forecast to HA weather entity model (home-assistant#44965)
  Deduplicate MQTT entity discovery code (home-assistant#44970)
  Fix parameters when toggling light (home-assistant#44950)
  Move MQTT entity helpers to separate file (home-assistant#44838)
  Helpers type hint improvements (home-assistant#44964)
  Remove script/test (home-assistant#44967)
  Add MQTT Number (non optimistic) (home-assistant#44883)
  Fix Netatmo climate boost for valves (home-assistant#44957)
  Disambiguate Supervisor HTTPUnauthorized on user/password validation (home-assistant#44940)
  Add torrent id to Transmission events (home-assistant#44187)
  Prefix versions in system health (home-assistant#44921)
  Fix media renderers without volume control (home-assistant#44874)
  Fix wait_template incorrectly matching falsey values (home-assistant#44938)
  Upgrade youtube_dl to 2021.01.03 (home-assistant#44942)
  Upgrade discord.py to 1.6.0 (home-assistant#44941)
  Fix KNX cover state return open when unknown (home-assistant#44926)
  Use parent_id to find cause of logbook events with new contexts (home-assistant#44416)
  Implement support for additional ecobee hold modes (home-assistant#40520)
  ...
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants