From 4d89ec31143e1c61af6ffe2d7991b89cd7e69873 Mon Sep 17 00:00:00 2001 From: JPHutchins Date: Mon, 30 Sep 2019 20:22:02 -0700 Subject: [PATCH 01/17] Add information about current downloads. --- .../components/transmission/__init__.py | 41 +++++++++++++++++++ .../components/transmission/const.py | 34 +++++++++++---- .../components/transmission/sensor.py | 33 +++++++++++++++ 3 files changed, 99 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/transmission/__init__.py b/homeassistant/components/transmission/__init__.py index 6cfd6bf640ae37..bd85589cc2d11e 100644 --- a/homeassistant/components/transmission/__init__.py +++ b/homeassistant/components/transmission/__init__.py @@ -28,6 +28,7 @@ DEFAULT_SCAN_INTERVAL, DOMAIN, SERVICE_ADD_TORRENT, + _TRPC, ) from .errors import AuthenticationError, CannotConnect, UnknownError @@ -232,6 +233,9 @@ def __init__(self, hass, config, api): self._api = api self.completed_torrents = [] self.started_torrents = [] + self.started_torrents_objects = [] + self.torrent_down_list = [] + self.started_torrent_dict = {} @property def host(self): @@ -250,6 +254,7 @@ def update(self): 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 +306,31 @@ def check_started_torrent(self): 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 x in all_torrents: + if ( + x.status == _TRPC["downloading"] + or x.status == _TRPC["download pending"] + ): + + self.started_torrent_dict[x.name] = { + "addedDate": x.addedDate, + "percentDone": "%.2f" % (x.percentDone * 100), + "eta": str(x.eta), + } + current_down[x.name] = True + else: + self.started_torrent_dict.pop(x.name) + + # remove torrents that have completed or otherwise been removed + for x in self.started_torrent_dict: + if x.name not in current_down: + self.started_torrent_dict.pop(x.name) + def get_started_torrent_count(self): """Get the number of started torrents.""" return len(self.started_torrents) @@ -309,6 +339,17 @@ def get_completed_torrent_count(self): """Get the number of completed torrents.""" return len(self.completed_torrents) + def get_started_torrent_list(self): + """Get the list of started torrents.""" + if self.started_torrent_dict: + return True + else: + return False + + def get_started_torrent_dict(self): + """Get the dict of started torrents.""" + return self.started_torrent_dict + def start_torrents(self): """Start all torrents.""" self._api.start_all() diff --git a/homeassistant/components/transmission/const.py b/homeassistant/components/transmission/const.py index 472bb32a391cfe..0f356db3959f0f 100644 --- a/homeassistant/components/transmission/const.py +++ b/homeassistant/components/transmission/const.py @@ -2,14 +2,16 @@ DOMAIN = "transmission" SENSOR_TYPES = { - "active_torrents": ["Active Torrents", None], - "current_status": ["Status", None], - "download_speed": ["Down Speed", "MB/s"], - "paused_torrents": ["Paused Torrents", None], - "total_torrents": ["Total Torrents", None], - "upload_speed": ["Up Speed", "MB/s"], - "completed_torrents": ["Completed Torrents", None], - "started_torrents": ["Started Torrents", None], + "active_torrents": ["Active Torrents", None, None], + "current_status": ["Status", None, None], + "download_speed": ["Down Speed", "MB/s", None], + "paused_torrents": ["Paused Torrents", None, None], + "total_torrents": ["Total Torrents", None, None], + "upload_speed": ["Up Speed", "MB/s", None], + "completed_torrents": ["Completed Torrents", None, None], + "started_torrents": ["Started Torrents", None, None], + "torrent_down_list": ["Downloading", None, None], + "started_torrent_dict": ["Torrent Info", None, None], } SWITCH_TYPES = {"on_off": "Switch", "turtle_mode": "Turtle Mode"} @@ -17,7 +19,21 @@ DEFAULT_PORT = 9091 DEFAULT_SCAN_INTERVAL = 120 -ATTR_TORRENT = "torrent" +STATE_ATTR_TORRENT_INFO = "torrent_info" SERVICE_ADD_TORRENT = "add_torrent" DATA_UPDATED = "transmission_data_updated" +<<<<<<< HEAD +======= +DATA_TRANSMISSION = "data_transmission" + +_TRPC = { + "check pending": "check pending", + "checking": "checking", + "downloading": "downloading", + "seeding": "seeding", + "stopped": "stopped", + "download pending": "download pending", + "seed pending": "seed pending", +} +>>>>>>> Add information about current downloads. diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index d9fd2b5114476c..e2f531cdd5f88d 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -6,7 +6,17 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import Entity +<<<<<<< HEAD from .const import DOMAIN, SENSOR_TYPES +======= +from .const import ( + DATA_TRANSMISSION, + DATA_UPDATED, + DOMAIN, + SENSOR_TYPES, + STATE_ATTR_TORRENT_INFO, +) +>>>>>>> Add information about current downloads. _LOGGER = logging.getLogger(__name__) @@ -31,6 +41,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): name, SENSOR_TYPES[sensor_type][0], SENSOR_TYPES[sensor_type][1], + SENSOR_TYPES[sensor_type][2], ) ) @@ -41,7 +52,17 @@ class TransmissionSensor(Entity): """Representation of a Transmission sensor.""" def __init__( +<<<<<<< HEAD self, sensor_type, tm_client, client_name, sensor_name, unit_of_measurement +======= + self, + sensor_type, + transmission_api, + client_name, + sensor_name, + unit_of_measurement, + torrent_info, +>>>>>>> Add information about current downloads. ): """Initialize the sensor.""" self._name = sensor_name @@ -51,6 +72,7 @@ def __init__( self._data = None self.client_name = client_name self.type = sensor_type + self._torrent_info = torrent_info @property def name(self): @@ -82,6 +104,11 @@ def available(self): """Could the device be accessed during the last update call.""" return self._tm_client.api.available + @property + def state_attributes(self): + """Return the state attributes, if any.""" + return {STATE_ATTR_TORRENT_INFO: self._torrent_info} + async def async_added_to_hass(self): """Handle entity which will be added.""" async_dispatcher_connect( @@ -133,3 +160,9 @@ def update(self): self._state = self._data.pausedTorrentCount elif self.type == "total_torrents": self._state = self._data.torrentCount + + if self.type == "torrent_down_list": + self._state = self._transmission_api.get_started_torrent_list() + self._torrent_info = self._transmission_api.get_started_torrent_dict() + if self.type == "started_torrent_dict": + self._state = self._transmission_api.get_started_torrent_dict() From 8dfb47f6d82298e52b1ca0f80fe0979fb3a8e62f Mon Sep 17 00:00:00 2001 From: JPHutchins Date: Tue, 1 Oct 2019 20:38:54 -0700 Subject: [PATCH 02/17] Cleanup: add "Torrent Info" state attribute --- .../components/transmission/__init__.py | 53 ++++++++++--------- .../components/transmission/const.py | 4 +- .../components/transmission/sensor.py | 12 ++--- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/homeassistant/components/transmission/__init__.py b/homeassistant/components/transmission/__init__.py index bd85589cc2d11e..5f6d3b884c3ced 100644 --- a/homeassistant/components/transmission/__init__.py +++ b/homeassistant/components/transmission/__init__.py @@ -233,8 +233,6 @@ def __init__(self, hass, config, api): self._api = api self.completed_torrents = [] self.started_torrents = [] - self.started_torrents_objects = [] - self.torrent_down_list = [] self.started_torrent_dict = {} @property @@ -311,25 +309,31 @@ def check_started_torrent_info(self): all_torrents = self._api.get_torrents() current_down = {} - for x in all_torrents: - if ( - x.status == _TRPC["downloading"] - or x.status == _TRPC["download pending"] - ): + for torrent in all_torrents: + if torrent.status == _TRPC["downloading"]: + info = self.started_torrent_dict[torrent.name] = { + "addedDate": torrent.addedDate, + "percentDone": "%.2f" % (torrent.percentDone * 100), + } + try: + info["eta"] = str(torrent.eta) + except ValueError: + info["eta"] = "unknown" + + current_down[torrent.name] = True - self.started_torrent_dict[x.name] = { - "addedDate": x.addedDate, - "percentDone": "%.2f" % (x.percentDone * 100), - "eta": str(x.eta), + elif torrent.status == _TRPC["download pending"]: + self.started_torrent_dict[torrent.name] = { + "addedDate": torrent.addedDate } - current_down[x.name] = True - else: - self.started_torrent_dict.pop(x.name) + current_down[torrent.name] = True + + elif torrent.name in self.started_torrent_dict: + self.started_torrent_dict.pop(torrent.name) - # remove torrents that have completed or otherwise been removed - for x in self.started_torrent_dict: - if x.name not in current_down: - self.started_torrent_dict.pop(x.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.""" @@ -339,17 +343,14 @@ def get_completed_torrent_count(self): """Get the number of completed torrents.""" return len(self.completed_torrents) - def get_started_torrent_list(self): - """Get the list of started torrents.""" - if self.started_torrent_dict: - return True - else: - return False - def get_started_torrent_dict(self): - """Get the dict of started torrents.""" + """Get the started torrent dict.""" return self.started_torrent_dict + def get_started_torrent_info(self): + """Return True if there is info in state attribute.""" + return bool(self.started_torrent_dict) + def start_torrents(self): """Start all torrents.""" self._api.start_all() diff --git a/homeassistant/components/transmission/const.py b/homeassistant/components/transmission/const.py index 0f356db3959f0f..3d5ed88276b02c 100644 --- a/homeassistant/components/transmission/const.py +++ b/homeassistant/components/transmission/const.py @@ -10,8 +10,7 @@ "upload_speed": ["Up Speed", "MB/s", None], "completed_torrents": ["Completed Torrents", None, None], "started_torrents": ["Started Torrents", None, None], - "torrent_down_list": ["Downloading", None, None], - "started_torrent_dict": ["Torrent Info", None, None], + "started_torrent_info": ["Torrent Info", None, None], } SWITCH_TYPES = {"on_off": "Switch", "turtle_mode": "Turtle Mode"} @@ -20,6 +19,7 @@ DEFAULT_SCAN_INTERVAL = 120 STATE_ATTR_TORRENT_INFO = "torrent_info" +ATTR_TORRENT = "torrent" SERVICE_ADD_TORRENT = "add_torrent" DATA_UPDATED = "transmission_data_updated" diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index e2f531cdd5f88d..e62cf80298d19a 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -107,7 +107,8 @@ def available(self): @property def state_attributes(self): """Return the state attributes, if any.""" - return {STATE_ATTR_TORRENT_INFO: self._torrent_info} + if self._torrent_info: + return {STATE_ATTR_TORRENT_INFO: self._torrent_info} async def async_added_to_hass(self): """Handle entity which will be added.""" @@ -160,9 +161,6 @@ def update(self): self._state = self._data.pausedTorrentCount elif self.type == "total_torrents": self._state = self._data.torrentCount - - if self.type == "torrent_down_list": - self._state = self._transmission_api.get_started_torrent_list() - self._torrent_info = self._transmission_api.get_started_torrent_dict() - if self.type == "started_torrent_dict": - self._state = self._transmission_api.get_started_torrent_dict() + elif self.type == "started_torrent_info": + self._state = self._transmission_api.get_started_torrent_info() + self._torrent_info = self._transmission_api.get_started_torrent_dict() From 853ddca160eb23c8919e8cb5f867a3c2dacb359c Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" <34154542+JPHutchins@users.noreply.github.com> Date: Wed, 2 Oct 2019 09:51:24 -0700 Subject: [PATCH 03/17] Add username to codeowners --- homeassistant/components/transmission/manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/transmission/manifest.json b/homeassistant/components/transmission/manifest.json index c2fa31d7b500c9..a42b801b1e041d 100644 --- a/homeassistant/components/transmission/manifest.json +++ b/homeassistant/components/transmission/manifest.json @@ -9,5 +9,6 @@ "dependencies": [], "codeowners": [ "@engrbm87" + "JPHutchins" ] -} \ No newline at end of file +} From 9e1873a3649875dbf0806f3faff263bc2b5ccbf2 Mon Sep 17 00:00:00 2001 From: JPHutchins Date: Wed, 2 Oct 2019 09:57:11 -0700 Subject: [PATCH 04/17] Rename state_attributes - device_state_attributes. --- homeassistant/components/transmission/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index e62cf80298d19a..e597c4a57a8987 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -105,7 +105,7 @@ def available(self): return self._tm_client.api.available @property - def state_attributes(self): + def device_state_attributes(self): """Return the state attributes, if any.""" if self._torrent_info: return {STATE_ATTR_TORRENT_INFO: self._torrent_info} From d684fb320d3c7a21a57ab1ea7ea5cfbf1df93bb8 Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" <34154542+JPHutchins@users.noreply.github.com> Date: Wed, 2 Oct 2019 11:49:51 -0700 Subject: [PATCH 05/17] Fix snakecase keys, use f-strings, remove redundant method. --- homeassistant/components/transmission/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/transmission/__init__.py b/homeassistant/components/transmission/__init__.py index 5f6d3b884c3ced..f6462aedd5ece0 100644 --- a/homeassistant/components/transmission/__init__.py +++ b/homeassistant/components/transmission/__init__.py @@ -312,8 +312,8 @@ def check_started_torrent_info(self): for torrent in all_torrents: if torrent.status == _TRPC["downloading"]: info = self.started_torrent_dict[torrent.name] = { - "addedDate": torrent.addedDate, - "percentDone": "%.2f" % (torrent.percentDone * 100), + "added_date": torrent.addedDate, + "percent_done": f"{torrent.percentDone * 100:.2f}", } try: info["eta"] = str(torrent.eta) @@ -324,7 +324,7 @@ def check_started_torrent_info(self): elif torrent.status == _TRPC["download pending"]: self.started_torrent_dict[torrent.name] = { - "addedDate": torrent.addedDate + "added_date": torrent.addedDate } current_down[torrent.name] = True @@ -343,10 +343,6 @@ def get_completed_torrent_count(self): """Get the number of completed torrents.""" return len(self.completed_torrents) - def get_started_torrent_dict(self): - """Get the started torrent dict.""" - return self.started_torrent_dict - def get_started_torrent_info(self): """Return True if there is info in state attribute.""" return bool(self.started_torrent_dict) From 22f056fcc58e709599328eae3ab2f1bf3679e47e Mon Sep 17 00:00:00 2001 From: JPHutchins Date: Wed, 2 Oct 2019 11:58:58 -0700 Subject: [PATCH 06/17] Access started_torrent_dict directly --- homeassistant/components/transmission/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index e597c4a57a8987..05c6e6df615199 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -163,4 +163,4 @@ def update(self): self._state = self._data.torrentCount elif self.type == "started_torrent_info": self._state = self._transmission_api.get_started_torrent_info() - self._torrent_info = self._transmission_api.get_started_torrent_dict() + self._torrent_info = self._transmission_api.started_torrent_dict From e0f2f272bb42eefe8181b594e4458fdb5639c359 Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" <34154542+JPHutchins@users.noreply.github.com> Date: Wed, 2 Oct 2019 12:52:26 -0700 Subject: [PATCH 07/17] Add return None condition --- homeassistant/components/transmission/sensor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index 05c6e6df615199..a5172465179223 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -109,6 +109,8 @@ def device_state_attributes(self): """Return the state attributes, if any.""" if self._torrent_info: return {STATE_ATTR_TORRENT_INFO: self._torrent_info} + else: + return None async def async_added_to_hass(self): """Handle entity which will be added.""" From 94056fd2103110ea7a5e1b009a163af0e96952b9 Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" <34154542+JPHutchins@users.noreply.github.com> Date: Wed, 2 Oct 2019 22:26:36 -0700 Subject: [PATCH 08/17] Remove redundancy. --- homeassistant/components/transmission/sensor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index a5172465179223..6604d8500513eb 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -109,8 +109,7 @@ def device_state_attributes(self): """Return the state attributes, if any.""" if self._torrent_info: return {STATE_ATTR_TORRENT_INFO: self._torrent_info} - else: - return None + return None async def async_added_to_hass(self): """Handle entity which will be added.""" From 4425a716ddb02c3a8f0428cf9f6f74a8f4467f9c Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" <34154542+JPHutchins@users.noreply.github.com> Date: Thu, 3 Oct 2019 18:28:52 -0700 Subject: [PATCH 09/17] Add missing comma in codeowners list. --- homeassistant/components/transmission/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/transmission/manifest.json b/homeassistant/components/transmission/manifest.json index a42b801b1e041d..7c68f71bc1766b 100644 --- a/homeassistant/components/transmission/manifest.json +++ b/homeassistant/components/transmission/manifest.json @@ -8,7 +8,7 @@ ], "dependencies": [], "codeowners": [ - "@engrbm87" + "@engrbm87", "JPHutchins" ] } From 5beeeadc4f044e4bd9443beec5771bf74d9ad885 Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" <34154542+JPHutchins@users.noreply.github.com> Date: Thu, 3 Oct 2019 18:29:24 -0700 Subject: [PATCH 10/17] Add missing @ to username. --- homeassistant/components/transmission/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/transmission/manifest.json b/homeassistant/components/transmission/manifest.json index 7c68f71bc1766b..9618a5677adef6 100644 --- a/homeassistant/components/transmission/manifest.json +++ b/homeassistant/components/transmission/manifest.json @@ -9,6 +9,6 @@ "dependencies": [], "codeowners": [ "@engrbm87", - "JPHutchins" + "@JPHutchins" ] } From 7a46e1232a5fc76e5866f10fb4d28b7983879f7e Mon Sep 17 00:00:00 2001 From: JPHutchins Date: Thu, 3 Oct 2019 18:38:11 -0700 Subject: [PATCH 11/17] Update CODEOWNERS with script.hassfest. --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 809101a5271ec0..63cc2d5e8aa5d1 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -305,7 +305,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 From dced6761a2c29fa8ee38f2aa1b45cb0973801b2e Mon Sep 17 00:00:00 2001 From: JPHutchins Date: Mon, 7 Oct 2019 21:04:23 -0700 Subject: [PATCH 12/17] Remove transmission_downloading, give started_torrents the info. --- homeassistant/components/transmission/const.py | 1 - homeassistant/components/transmission/sensor.py | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/transmission/const.py b/homeassistant/components/transmission/const.py index 3d5ed88276b02c..60f51dfc016677 100644 --- a/homeassistant/components/transmission/const.py +++ b/homeassistant/components/transmission/const.py @@ -10,7 +10,6 @@ "upload_speed": ["Up Speed", "MB/s", None], "completed_torrents": ["Completed Torrents", None, None], "started_torrents": ["Started Torrents", None, None], - "started_torrent_info": ["Torrent Info", None, None], } SWITCH_TYPES = {"on_off": "Switch", "turtle_mode": "Turtle Mode"} diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index 6604d8500513eb..9f67979bcf7dba 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -130,7 +130,12 @@ def update(self): if self.type == "completed_torrents": self._state = self._tm_client.api.get_completed_torrent_count() elif self.type == "started_torrents": +<<<<<<< HEAD self._state = self._tm_client.api.get_started_torrent_count() +======= + self._state = self._transmission_api.get_started_torrent_count() + self._torrent_info = self._transmission_api.started_torrent_dict +>>>>>>> Remove transmission_downloading, give started_torrents the info. if self.type == "current_status": if self._data: @@ -162,6 +167,3 @@ def update(self): self._state = self._data.pausedTorrentCount elif self.type == "total_torrents": self._state = self._data.torrentCount - elif self.type == "started_torrent_info": - self._state = self._transmission_api.get_started_torrent_info() - self._torrent_info = self._transmission_api.started_torrent_dict From a1c602a1b89e7ad33c6236eb103efccbac51adb1 Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" Date: Thu, 24 Oct 2019 21:53:41 -0700 Subject: [PATCH 13/17] Confirm changes. --- homeassistant/components/transmission/const.py | 3 --- homeassistant/components/transmission/sensor.py | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/homeassistant/components/transmission/const.py b/homeassistant/components/transmission/const.py index 60f51dfc016677..8610153ab7ca44 100644 --- a/homeassistant/components/transmission/const.py +++ b/homeassistant/components/transmission/const.py @@ -22,8 +22,6 @@ SERVICE_ADD_TORRENT = "add_torrent" DATA_UPDATED = "transmission_data_updated" -<<<<<<< HEAD -======= DATA_TRANSMISSION = "data_transmission" _TRPC = { @@ -35,4 +33,3 @@ "download pending": "download pending", "seed pending": "seed pending", } ->>>>>>> Add information about current downloads. diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index 9f67979bcf7dba..11fb877e1beb7b 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -6,9 +6,6 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import Entity -<<<<<<< HEAD -from .const import DOMAIN, SENSOR_TYPES -======= from .const import ( DATA_TRANSMISSION, DATA_UPDATED, @@ -16,7 +13,7 @@ SENSOR_TYPES, STATE_ATTR_TORRENT_INFO, ) ->>>>>>> Add information about current downloads. + _LOGGER = logging.getLogger(__name__) From acfed0ff45c83481ee7638f9e3934e0480395ccb Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" Date: Thu, 24 Oct 2019 22:01:11 -0700 Subject: [PATCH 14/17] Actually approve changes. --- homeassistant/components/transmission/sensor.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index 11fb877e1beb7b..470ded0eaddb78 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -49,9 +49,6 @@ class TransmissionSensor(Entity): """Representation of a Transmission sensor.""" def __init__( -<<<<<<< HEAD - self, sensor_type, tm_client, client_name, sensor_name, unit_of_measurement -======= self, sensor_type, transmission_api, @@ -59,7 +56,6 @@ def __init__( sensor_name, unit_of_measurement, torrent_info, ->>>>>>> Add information about current downloads. ): """Initialize the sensor.""" self._name = sensor_name @@ -127,12 +123,8 @@ def update(self): if self.type == "completed_torrents": self._state = self._tm_client.api.get_completed_torrent_count() elif self.type == "started_torrents": -<<<<<<< HEAD - self._state = self._tm_client.api.get_started_torrent_count() -======= self._state = self._transmission_api.get_started_torrent_count() self._torrent_info = self._transmission_api.started_torrent_dict ->>>>>>> Remove transmission_downloading, give started_torrents the info. if self.type == "current_status": if self._data: From e130aae07fe438c375eb03ab61f9cc63d6dd2bd2 Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" Date: Thu, 24 Oct 2019 22:18:14 -0700 Subject: [PATCH 15/17] Resolve conflicts. --- homeassistant/components/transmission/const.py | 1 - homeassistant/components/transmission/sensor.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/homeassistant/components/transmission/const.py b/homeassistant/components/transmission/const.py index 8610153ab7ca44..d0b33c9bc7b336 100644 --- a/homeassistant/components/transmission/const.py +++ b/homeassistant/components/transmission/const.py @@ -22,7 +22,6 @@ SERVICE_ADD_TORRENT = "add_torrent" DATA_UPDATED = "transmission_data_updated" -DATA_TRANSMISSION = "data_transmission" _TRPC = { "check pending": "check pending", diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index 470ded0eaddb78..fa973a2ab1ad17 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -7,8 +7,6 @@ from homeassistant.helpers.entity import Entity from .const import ( - DATA_TRANSMISSION, - DATA_UPDATED, DOMAIN, SENSOR_TYPES, STATE_ATTR_TORRENT_INFO, @@ -51,6 +49,7 @@ class TransmissionSensor(Entity): def __init__( self, sensor_type, + tm_client, transmission_api, client_name, sensor_name, From 4070b0f864f0c6ccf6fd59e38f1751a2b657233a Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" Date: Sun, 27 Oct 2019 15:50:04 -0700 Subject: [PATCH 16/17] Remove leftovers from old torrent_info sensor. --- .../components/transmission/__init__.py | 9 +------ .../components/transmission/const.py | 26 ++++++------------- .../components/transmission/sensor.py | 24 ++++------------- 3 files changed, 14 insertions(+), 45 deletions(-) diff --git a/homeassistant/components/transmission/__init__.py b/homeassistant/components/transmission/__init__.py index f6462aedd5ece0..0acd4d314f082f 100644 --- a/homeassistant/components/transmission/__init__.py +++ b/homeassistant/components/transmission/__init__.py @@ -28,7 +28,6 @@ DEFAULT_SCAN_INTERVAL, DOMAIN, SERVICE_ADD_TORRENT, - _TRPC, ) from .errors import AuthenticationError, CannotConnect, UnknownError @@ -310,7 +309,7 @@ def check_started_torrent_info(self): current_down = {} for torrent in all_torrents: - if torrent.status == _TRPC["downloading"]: + if torrent.status == "downloading": info = self.started_torrent_dict[torrent.name] = { "added_date": torrent.addedDate, "percent_done": f"{torrent.percentDone * 100:.2f}", @@ -322,12 +321,6 @@ def check_started_torrent_info(self): current_down[torrent.name] = True - elif torrent.status == _TRPC["download pending"]: - self.started_torrent_dict[torrent.name] = { - "added_date": torrent.addedDate - } - current_down[torrent.name] = True - elif torrent.name in self.started_torrent_dict: self.started_torrent_dict.pop(torrent.name) diff --git a/homeassistant/components/transmission/const.py b/homeassistant/components/transmission/const.py index d0b33c9bc7b336..5540f718ba10f0 100644 --- a/homeassistant/components/transmission/const.py +++ b/homeassistant/components/transmission/const.py @@ -2,14 +2,14 @@ DOMAIN = "transmission" SENSOR_TYPES = { - "active_torrents": ["Active Torrents", None, None], - "current_status": ["Status", None, None], - "download_speed": ["Down Speed", "MB/s", None], - "paused_torrents": ["Paused Torrents", None, None], - "total_torrents": ["Total Torrents", None, None], - "upload_speed": ["Up Speed", "MB/s", None], - "completed_torrents": ["Completed Torrents", None, None], - "started_torrents": ["Started Torrents", None, None], + "active_torrents": ["Active Torrents", None], + "current_status": ["Status", None], + "download_speed": ["Down Speed", "MB/s"], + "paused_torrents": ["Paused Torrents", None], + "total_torrents": ["Total Torrents", None], + "upload_speed": ["Up Speed", "MB/s"], + "completed_torrents": ["Completed Torrents", None], + "started_torrents": ["Started Torrents", None], } SWITCH_TYPES = {"on_off": "Switch", "turtle_mode": "Turtle Mode"} @@ -22,13 +22,3 @@ SERVICE_ADD_TORRENT = "add_torrent" DATA_UPDATED = "transmission_data_updated" - -_TRPC = { - "check pending": "check pending", - "checking": "checking", - "downloading": "downloading", - "seeding": "seeding", - "stopped": "stopped", - "download pending": "download pending", - "seed pending": "seed pending", -} diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index fa973a2ab1ad17..489582de157292 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -6,11 +6,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import Entity -from .const import ( - DOMAIN, - SENSOR_TYPES, - STATE_ATTR_TORRENT_INFO, -) +from .const import DOMAIN, SENSOR_TYPES, STATE_ATTR_TORRENT_INFO _LOGGER = logging.getLogger(__name__) @@ -36,7 +32,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): name, SENSOR_TYPES[sensor_type][0], SENSOR_TYPES[sensor_type][1], - SENSOR_TYPES[sensor_type][2], ) ) @@ -47,14 +42,7 @@ class TransmissionSensor(Entity): """Representation of a Transmission sensor.""" def __init__( - self, - sensor_type, - tm_client, - transmission_api, - client_name, - sensor_name, - unit_of_measurement, - torrent_info, + self, sensor_type, tm_client, client_name, sensor_name, unit_of_measurement ): """Initialize the sensor.""" self._name = sensor_name @@ -64,7 +52,6 @@ def __init__( self._data = None self.client_name = client_name self.type = sensor_type - self._torrent_info = torrent_info @property def name(self): @@ -99,8 +86,8 @@ def available(self): @property def device_state_attributes(self): """Return the state attributes, if any.""" - if self._torrent_info: - return {STATE_ATTR_TORRENT_INFO: self._torrent_info} + 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): @@ -122,8 +109,7 @@ def update(self): if self.type == "completed_torrents": self._state = self._tm_client.api.get_completed_torrent_count() elif self.type == "started_torrents": - self._state = self._transmission_api.get_started_torrent_count() - self._torrent_info = self._transmission_api.started_torrent_dict + self._state = self._tm_client.api.get_started_torrent_count() if self.type == "current_status": if self._data: From 0ed444904f8a5a7815a6d5d42081b16cd28ea8b8 Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" <34154542+JPHutchins@users.noreply.github.com> Date: Sun, 27 Oct 2019 23:38:16 -0700 Subject: [PATCH 17/17] Remove get_started_torrent_info method. Old method to display boolean for the removed torrent_info sensor. --- homeassistant/components/transmission/__init__.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/homeassistant/components/transmission/__init__.py b/homeassistant/components/transmission/__init__.py index 0acd4d314f082f..be41ca85998f6a 100644 --- a/homeassistant/components/transmission/__init__.py +++ b/homeassistant/components/transmission/__init__.py @@ -336,10 +336,6 @@ def get_completed_torrent_count(self): """Get the number of completed torrents.""" return len(self.completed_torrents) - def get_started_torrent_info(self): - """Return True if there is info in state attribute.""" - return bool(self.started_torrent_dict) - def start_torrents(self): """Start all torrents.""" self._api.start_all()