Openhardwaremonitor (#8056)

* Open Hardware Monitor sensor

Platform which is able to connect to the JSON API of Open Hardware Monitor and adds sensors for the devices.

* Remove copyright in header, not needed.

* - Removed old code
- Fixed typo’s in comments
- Removed log spamming
- Removed code that was unnecessary
- Use requests instead of urllib
- Moved sensor update functionality to data handler, to remove unwanted constructor parameters

* Fixed typo in comment
Added tests

* Added default fixture, to stabilize tests

* - Fix for values deeper than 4 levels, no longer relies on fixed level
- Fixed tests

* Removed timer in preference of helper methods

* Moved update functionality back to Entity….
Updated SCAN INTERVAL

* Added timeout to request
Removed retry when Open Hardware Monitor API is not reachable
Fixed naming of sensors
Flow optimalisations
Fixed tests to use states

* Remove unused import
This commit is contained in:
Wim Haanstra authored and Paulus Schoutsen committed 2017-06-25 13:48:05 -07:00
1 parent 8358542ce0
commit 2f2952e0ec
3 files changed
+794

No files matched your search

@@ -0,0 +1,40 @@
"""The tests for the Open Hardware Monitor platform."""
import unittest
import requests_mock
from homeassistant.setup import setup_component
from tests.common import load_fixture, get_test_home_assistant
class TestOpenHardwareMonitorSetup(unittest.TestCase):
"""Test the Open Hardware Monitor platform."""
def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.config = {
'sensor': {
'platform': 'openhardwaremonitor',
'host': 'localhost',
'port': 8085
}
}
def tearDown(self): # pylint: disable=invalid-name
"""Stop everything that was started."""
self.hass.stop()
@requests_mock.Mocker()
def test_setup(self, mock_req):
"""Test for successfully setting up the platform."""
mock_req.get('http://localhost:8085/data.json',
text=load_fixture('openhardwaremonitor.json'))
self.assertTrue(setup_component(self.hass, 'sensor', self.config))
entities = self.hass.states.async_entity_ids('sensor')
self.assertEqual(len(entities), 38)
state = self.hass.states.get(
'sensor.testpc_intel_core_i77700_clocks_bus_speed')
self.assertIsNot(state, None)
self.assertEqual(state.state, '100')