mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Add transmission info about torrents that is accessible with templating (#27111)
* Add information about current downloads. * Cleanup: add "Torrent Info" state attribute * Add username to codeowners * Rename state_attributes - device_state_attributes. * Fix snakecase keys, use f-strings, remove redundant method. * Access started_torrent_dict directly * Add return None condition * Remove redundancy. * Add missing comma in codeowners list. * Add missing @ to username. * Update CODEOWNERS with script.hassfest. * Remove transmission_downloading, give started_torrents the info. * Confirm changes. * Actually approve changes. * Resolve conflicts. * Remove leftovers from old torrent_info sensor. * Remove get_started_torrent_info method. Old method to display boolean for the removed torrent_info sensor.
This commit is contained in:
parent
edcf476408
commit
54342d2a4e
@ -306,7 +306,7 @@ homeassistant/components/tplink/* @rytilahti
|
||||
homeassistant/components/traccar/* @ludeeus
|
||||
homeassistant/components/tradfri/* @ggravlingen
|
||||
homeassistant/components/trafikverket_train/* @endor-force
|
||||
homeassistant/components/transmission/* @engrbm87
|
||||
homeassistant/components/transmission/* @engrbm87 @JPHutchins
|
||||
homeassistant/components/tts/* @robbiet480
|
||||
homeassistant/components/twentemilieu/* @frenck
|
||||
homeassistant/components/twilio_call/* @robbiet480
|
||||
|
@ -232,6 +232,7 @@ class TransmissionData:
|
||||
self._api = api
|
||||
self.completed_torrents = []
|
||||
self.started_torrents = []
|
||||
self.started_torrent_dict = {}
|
||||
|
||||
@property
|
||||
def host(self):
|
||||
@ -250,6 +251,7 @@ class TransmissionData:
|
||||
self.torrents = self._api.get_torrents()
|
||||
self.session = self._api.get_session()
|
||||
|
||||
self.check_started_torrent_info()
|
||||
self.check_completed_torrent()
|
||||
self.check_started_torrent()
|
||||
_LOGGER.debug("Torrent Data for %s Updated", self.host)
|
||||
@ -301,6 +303,31 @@ class TransmissionData:
|
||||
self.hass.bus.fire("transmission_started_torrent", {"name": var})
|
||||
self.started_torrents = actual_started_torrents
|
||||
|
||||
def check_started_torrent_info(self):
|
||||
"""Get started torrent info functionality."""
|
||||
all_torrents = self._api.get_torrents()
|
||||
current_down = {}
|
||||
|
||||
for torrent in all_torrents:
|
||||
if torrent.status == "downloading":
|
||||
info = self.started_torrent_dict[torrent.name] = {
|
||||
"added_date": torrent.addedDate,
|
||||
"percent_done": f"{torrent.percentDone * 100:.2f}",
|
||||
}
|
||||
try:
|
||||
info["eta"] = str(torrent.eta)
|
||||
except ValueError:
|
||||
info["eta"] = "unknown"
|
||||
|
||||
current_down[torrent.name] = True
|
||||
|
||||
elif torrent.name in self.started_torrent_dict:
|
||||
self.started_torrent_dict.pop(torrent.name)
|
||||
|
||||
for torrent in list(self.started_torrent_dict):
|
||||
if torrent not in current_down:
|
||||
self.started_torrent_dict.pop(torrent)
|
||||
|
||||
def get_started_torrent_count(self):
|
||||
"""Get the number of started torrents."""
|
||||
return len(self.started_torrents)
|
||||
|
@ -17,6 +17,7 @@ DEFAULT_NAME = "Transmission"
|
||||
DEFAULT_PORT = 9091
|
||||
DEFAULT_SCAN_INTERVAL = 120
|
||||
|
||||
STATE_ATTR_TORRENT_INFO = "torrent_info"
|
||||
ATTR_TORRENT = "torrent"
|
||||
SERVICE_ADD_TORRENT = "add_torrent"
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": [
|
||||
"@engrbm87"
|
||||
"@engrbm87",
|
||||
"@JPHutchins"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import DOMAIN, SENSOR_TYPES
|
||||
from .const import DOMAIN, SENSOR_TYPES, STATE_ATTR_TORRENT_INFO
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -82,6 +83,13 @@ class TransmissionSensor(Entity):
|
||||
"""Could the device be accessed during the last update call."""
|
||||
return self._tm_client.api.available
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes, if any."""
|
||||
if self._tm_client.api.started_torrent_dict and self.type == "started_torrents":
|
||||
return {STATE_ATTR_TORRENT_INFO: self._tm_client.api.started_torrent_dict}
|
||||
return None
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Handle entity which will be added."""
|
||||
async_dispatcher_connect(
|
||||
|
Loading…
x
Reference in New Issue
Block a user