Skip to content

Commit

Permalink
hddtemp module: remove deprecated telnetlib dependency (fixes #2261) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
valdur55 authored Oct 22, 2024
1 parent a306d4c commit 51e7d8f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions py3status/modules/hddtemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
Requires:
hddtemp: utility to monitor hard drive temperatures
nc: netcat / ncat is command-line utility for reading data from hddtemp
telnet interface
Bible of HDD failures:
Hard disk temperatures higher than 45°C led to higher failure rates.
Expand Down Expand Up @@ -108,7 +110,8 @@
"""

from string import printable
from telnetlib import Telnet

STRING_NOT_INSTALLED = "shell command {} not installed"


class Py3status:
Expand All @@ -130,12 +133,17 @@ class Py3status:
]

def post_config_hook(self):
if not self.py3.check_commands("hddtemp"):
raise Exception(STRING_NOT_INSTALLED.format("hddtemp"))
if not self.py3.check_commands("nc"):
raise Exception(STRING_NOT_INSTALLED.format("netcat / ncat"))

self.keys = ["path", "name", "temperature", "unit"]
self.cache_names = {}
self.thresholds_init = self.py3.get_color_names_list(self.format_hdd)

def hddtemp(self):
line = Telnet("localhost", 7634).read_all().decode("utf-8", "ignore")
line = self.py3.command_output("nc localhost 7634")
new_data = []

for chunk in line[1:-1].split("||"):
Expand Down

0 comments on commit 51e7d8f

Please sign in to comment.