Skip to content

Commit

Permalink
Merge pull request #7 from 7eXx/fix-cpu-temperature-decimals
Browse files Browse the repository at this point in the history
fix: now cpu temp has 2 decimals
  • Loading branch information
7eXx authored Mar 1, 2024
2 parents 0856392 + c577eee commit 0cebe76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "raspi_home_texx"
version = "0.2.0"
version = "0.2.1"
authors = [
{ name="Marco Tessari", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion src/raspi_home_texx/sys_info/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self) -> None:
if platform.system() == "Linux":
try:
with io.open(self.__sensor_file, 'r') as f:
self.temperature = float(f.read().strip()) / 1000
self.temperature = round(float(f.read().strip()) / 1000, 2)
except FileNotFoundError as err:
pass

Expand Down
18 changes: 16 additions & 2 deletions tests/test_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@ def test_init_linux(self, mock_io_open, mock_platform_system):
# Set up mock file content and open function for Linux platform
mock_io_open.return_value.__enter__ = lambda s: s
mock_io_open.return_value.__exit__ = Mock()
mock_io_open.return_value.read.return_value = '50000\n' # Assuming a temperature value of 50.000°C
mock_io_open.return_value.read.return_value = '41234\n' # Assuming a temperature value of 50.000°C

# Create a Cpu instance on Linux
cpu_linux = Cpu()

# Check if the temperature is correctly set
self.assertEqual(cpu_linux.temperature, 50.0)
self.assertEqual(cpu_linux.temperature, 41.23)

@patch('platform.system', return_value='Linux')
@patch('io.open', create=True)
def test_init_linux(self, mock_io_open, mock_platform_system):
# Set up mock file content and open function for Linux platform
mock_io_open.return_value.__enter__ = lambda s: s
mock_io_open.return_value.__exit__ = Mock()
mock_io_open.return_value.read.return_value = '41237\n' # Assuming a temperature value of 50.000°C

# Create a Cpu instance on Linux
cpu_linux = Cpu()

# Check if the temperature is correctly set
self.assertEqual(cpu_linux.temperature, 41.24)

@patch('platform.system', return_value='Windows')
def test_init_windows(self, mock_platform_system):
Expand Down

0 comments on commit 0cebe76

Please sign in to comment.