Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions homeassistant/components/rtorrent/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@
SENSOR_TYPE_CURRENT_STATUS = "current_status"
SENSOR_TYPE_DOWNLOAD_SPEED = "download_speed"
SENSOR_TYPE_UPLOAD_SPEED = "upload_speed"
SENSOR_TYPE_ALL_TORRENTS = "all_torrents"
SENSOR_TYPE_STOPPED_TORRENTS = "stopped_torrents"
SENSOR_TYPE_COMPLETE_TORRENTS = "complete_torrents"
SENSOR_TYPE_UPLOADING_TORRENTS = "uploading_torrents"
SENSOR_TYPE_DOWNLOADING_TORRENTS = "downloading_torrents"
SENSOR_TYPE_ACTIVE_TORRENTS = "active_torrents"

DEFAULT_NAME = "rtorrent"
SENSOR_TYPES = {
SENSOR_TYPE_CURRENT_STATUS: ["Status", None],
SENSOR_TYPE_DOWNLOAD_SPEED: ["Down Speed", DATA_RATE_KILOBYTES_PER_SECOND],
SENSOR_TYPE_UPLOAD_SPEED: ["Up Speed", DATA_RATE_KILOBYTES_PER_SECOND],
SENSOR_TYPE_ALL_TORRENTS: ["All Torrents", None],
SENSOR_TYPE_STOPPED_TORRENTS: ["Stopped Torrents", None],
SENSOR_TYPE_COMPLETE_TORRENTS: ["Complete Torrents", None],
SENSOR_TYPE_UPLOADING_TORRENTS: ["Uploading Torrents", None],
SENSOR_TYPE_DOWNLOADING_TORRENTS: ["Downloading Torrents", None],
SENSOR_TYPE_ACTIVE_TORRENTS: ["Active Torrents", None],
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
Expand Down Expand Up @@ -102,6 +114,11 @@ def update(self):
multicall = xmlrpc.client.MultiCall(self.client)
multicall.throttle.global_up.rate()
multicall.throttle.global_down.rate()
multicall.d.multicall2("", "main")
Comment thread
springstan marked this conversation as resolved.
multicall.d.multicall2("", "stopped")
multicall.d.multicall2("", "complete")
multicall.d.multicall2("", "seeding", "d.up.rate=")
multicall.d.multicall2("", "leeching", "d.down.rate=")

try:
self.data = multicall()
Expand All @@ -113,6 +130,21 @@ def update(self):

upload = self.data[0]
download = self.data[1]
alltorrents = self.data[2]
Comment thread
springstan marked this conversation as resolved.
Outdated
stoppedtorrents = self.data[3]
Comment thread
springstan marked this conversation as resolved.
Outdated
completetorrents = self.data[4]
Comment thread
springstan marked this conversation as resolved.
Outdated

uploading_torrents = 0
for uptorrent in self.data[5]:
Comment thread
springstan marked this conversation as resolved.
Outdated
if uptorrent[0] > 0:
Comment thread
springstan marked this conversation as resolved.
Outdated
uploading_torrents += 1

downloading_torrents = 0
for downtorrent in self.data[6]:
Comment thread
springstan marked this conversation as resolved.
Outdated
if downtorrent[0] > 0:
Comment thread
springstan marked this conversation as resolved.
Outdated
downloading_torrents += 1

active_torrents = uploading_torrents + downloading_torrents

if self.type == SENSOR_TYPE_CURRENT_STATUS:
if self.data:
Expand All @@ -132,3 +164,15 @@ def update(self):
self._state = format_speed(download)
elif self.type == SENSOR_TYPE_UPLOAD_SPEED:
self._state = format_speed(upload)
elif self.type == SENSOR_TYPE_ALL_TORRENTS:
self._state = len(alltorrents)
elif self.type == SENSOR_TYPE_STOPPED_TORRENTS:
self._state = len(stoppedtorrents)
elif self.type == SENSOR_TYPE_COMPLETE_TORRENTS:
self._state = len(completetorrents)
elif self.type == SENSOR_TYPE_UPLOADING_TORRENTS:
self._state = uploading_torrents
elif self.type == SENSOR_TYPE_DOWNLOADING_TORRENTS:
self._state = downloading_torrents
elif self.type == SENSOR_TYPE_ACTIVE_TORRENTS:
self._state = active_torrents