mirror of
https://github.com/home-assistant/core.git
synced 2025-04-29 19:57:52 +00:00
Extend rtorrent sensor functionality (#32353)
* Extend rtorrent sensor functionality. * Remove blank line from end of file. * After using black formatter. * Update sensor.py using snake_case for variable names. * Update PR by using true value in condition.
This commit is contained in:
parent
992daa4a44
commit
f3fed5647e
@ -21,12 +21,24 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
SENSOR_TYPE_CURRENT_STATUS = "current_status"
|
SENSOR_TYPE_CURRENT_STATUS = "current_status"
|
||||||
SENSOR_TYPE_DOWNLOAD_SPEED = "download_speed"
|
SENSOR_TYPE_DOWNLOAD_SPEED = "download_speed"
|
||||||
SENSOR_TYPE_UPLOAD_SPEED = "upload_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"
|
DEFAULT_NAME = "rtorrent"
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
SENSOR_TYPE_CURRENT_STATUS: ["Status", None],
|
SENSOR_TYPE_CURRENT_STATUS: ["Status", None],
|
||||||
SENSOR_TYPE_DOWNLOAD_SPEED: ["Down Speed", DATA_RATE_KILOBYTES_PER_SECOND],
|
SENSOR_TYPE_DOWNLOAD_SPEED: ["Down Speed", DATA_RATE_KILOBYTES_PER_SECOND],
|
||||||
SENSOR_TYPE_UPLOAD_SPEED: ["Up 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(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
@ -102,6 +114,11 @@ class RTorrentSensor(Entity):
|
|||||||
multicall = xmlrpc.client.MultiCall(self.client)
|
multicall = xmlrpc.client.MultiCall(self.client)
|
||||||
multicall.throttle.global_up.rate()
|
multicall.throttle.global_up.rate()
|
||||||
multicall.throttle.global_down.rate()
|
multicall.throttle.global_down.rate()
|
||||||
|
multicall.d.multicall2("", "main")
|
||||||
|
multicall.d.multicall2("", "stopped")
|
||||||
|
multicall.d.multicall2("", "complete")
|
||||||
|
multicall.d.multicall2("", "seeding", "d.up.rate=")
|
||||||
|
multicall.d.multicall2("", "leeching", "d.down.rate=")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.data = multicall()
|
self.data = multicall()
|
||||||
@ -113,6 +130,21 @@ class RTorrentSensor(Entity):
|
|||||||
|
|
||||||
upload = self.data[0]
|
upload = self.data[0]
|
||||||
download = self.data[1]
|
download = self.data[1]
|
||||||
|
all_torrents = self.data[2]
|
||||||
|
stopped_torrents = self.data[3]
|
||||||
|
complete_torrents = self.data[4]
|
||||||
|
|
||||||
|
uploading_torrents = 0
|
||||||
|
for up_torrent in self.data[5]:
|
||||||
|
if up_torrent[0]:
|
||||||
|
uploading_torrents += 1
|
||||||
|
|
||||||
|
downloading_torrents = 0
|
||||||
|
for down_torrent in self.data[6]:
|
||||||
|
if down_torrent[0]:
|
||||||
|
downloading_torrents += 1
|
||||||
|
|
||||||
|
active_torrents = uploading_torrents + downloading_torrents
|
||||||
|
|
||||||
if self.type == SENSOR_TYPE_CURRENT_STATUS:
|
if self.type == SENSOR_TYPE_CURRENT_STATUS:
|
||||||
if self.data:
|
if self.data:
|
||||||
@ -132,3 +164,15 @@ class RTorrentSensor(Entity):
|
|||||||
self._state = format_speed(download)
|
self._state = format_speed(download)
|
||||||
elif self.type == SENSOR_TYPE_UPLOAD_SPEED:
|
elif self.type == SENSOR_TYPE_UPLOAD_SPEED:
|
||||||
self._state = format_speed(upload)
|
self._state = format_speed(upload)
|
||||||
|
elif self.type == SENSOR_TYPE_ALL_TORRENTS:
|
||||||
|
self._state = len(all_torrents)
|
||||||
|
elif self.type == SENSOR_TYPE_STOPPED_TORRENTS:
|
||||||
|
self._state = len(stopped_torrents)
|
||||||
|
elif self.type == SENSOR_TYPE_COMPLETE_TORRENTS:
|
||||||
|
self._state = len(complete_torrents)
|
||||||
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user