1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Move temperature display helper from components to helpers (#10555)

This commit is contained in:
Fabian Affolter
2017-11-14 10:36:18 +01:00
committed by Pascal Vizeli
parent b1afed9e52
commit d25f676711
9 changed files with 186 additions and 116 deletions

View File

@@ -0,0 +1,49 @@
"""Tests Home Assistant temperature helpers."""
import unittest
from tests.common import get_test_home_assistant
from homeassistant.const import (
TEMP_CELSIUS, PRECISION_WHOLE, TEMP_FAHRENHEIT, PRECISION_HALVES,
PRECISION_TENTHS)
from homeassistant.helpers.temperature import display_temp
from homeassistant.util.unit_system import METRIC_SYSTEM
TEMP = 24.636626
class TestHelpersTemperature(unittest.TestCase):
"""Setup the temperature tests."""
def setUp(self):
"""Setup the tests."""
self.hass = get_test_home_assistant()
self.hass.config.unit_system = METRIC_SYSTEM
def tearDown(self):
"""Stop down stuff we started."""
self.hass.stop()
def test_temperature_not_a_number(self):
"""Test that temperature is a number."""
temp = "Temperature"
with self.assertRaises(Exception) as context:
display_temp(self.hass, temp, TEMP_CELSIUS, PRECISION_HALVES)
self.assertTrue("Temperature is not a number: {}".format(temp)
in str(context.exception))
def test_celsius_halves(self):
"""Test temperature to celsius rounding to halves."""
self.assertEqual(24.5, display_temp(
self.hass, TEMP, TEMP_CELSIUS, PRECISION_HALVES))
def test_celsius_tenths(self):
"""Test temperature to celsius rounding to tenths."""
self.assertEqual(24.6, display_temp(
self.hass, TEMP, TEMP_CELSIUS, PRECISION_TENTHS))
def test_fahrenheit_wholes(self):
"""Test temperature to fahrenheit rounding to wholes."""
self.assertEqual(-4, display_temp(
self.hass, TEMP, TEMP_FAHRENHEIT, PRECISION_WHOLE))