Add hddtemp sensor device even if unreachable. (#10623)
* Add hddtemp sensor device even if unreachable. * Removed old commented code. * Move unit detection logic into update.
This commit is contained in:
parent
e9b691173a
commit
be5f0fb3ac
2 changed files with 41 additions and 16 deletions
|
@ -1,4 +1,6 @@
|
|||
"""The tests for the hddtemp platform."""
|
||||
import socket
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
@ -56,6 +58,13 @@ VALID_CONFIG_HOST = {
|
|||
}
|
||||
}
|
||||
|
||||
VALID_CONFIG_HOST_UNREACHABLE = {
|
||||
'sensor': {
|
||||
'platform': 'hddtemp',
|
||||
'host': 'bob.local',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TelnetMock():
|
||||
"""Mock class for the telnetlib.Telnet object."""
|
||||
|
@ -75,6 +84,8 @@ class TelnetMock():
|
|||
"""Return sample values."""
|
||||
if self.host == 'alice.local':
|
||||
raise ConnectionRefusedError
|
||||
elif self.host == 'bob.local':
|
||||
raise socket.gaierror
|
||||
else:
|
||||
return self.sample_data
|
||||
return None
|
||||
|
@ -161,7 +172,10 @@ class TestHDDTempSensor(unittest.TestCase):
|
|||
"""Test hddtemp wrong disk configuration."""
|
||||
assert setup_component(self.hass, 'sensor', VALID_CONFIG_WRONG_DISK)
|
||||
|
||||
self.assertEqual(len(self.hass.states.all()), 0)
|
||||
self.assertEqual(len(self.hass.states.all()), 1)
|
||||
state = self.hass.states.get('sensor.hd_temperature_devsdx1')
|
||||
self.assertEqual(state.attributes.get('friendly_name'),
|
||||
'HD Temperature ' + '/dev/sdx1')
|
||||
|
||||
@patch('telnetlib.Telnet', new=TelnetMock)
|
||||
def test_hddtemp_multiple_disks(self):
|
||||
|
@ -189,7 +203,14 @@ class TestHDDTempSensor(unittest.TestCase):
|
|||
'HD Temperature ' + reference['device'])
|
||||
|
||||
@patch('telnetlib.Telnet', new=TelnetMock)
|
||||
def test_hddtemp_host_unreachable(self):
|
||||
def test_hddtemp_host_refused(self):
|
||||
"""Test hddtemp if host unreachable."""
|
||||
assert setup_component(self.hass, 'sensor', VALID_CONFIG_HOST)
|
||||
self.assertEqual(len(self.hass.states.all()), 0)
|
||||
|
||||
@patch('telnetlib.Telnet', new=TelnetMock)
|
||||
def test_hddtemp_host_unreachable(self):
|
||||
"""Test hddtemp if host unreachable."""
|
||||
assert setup_component(self.hass, 'sensor',
|
||||
VALID_CONFIG_HOST_UNREACHABLE)
|
||||
self.assertEqual(len(self.hass.states.all()), 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue