forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_temperature.py
38 lines (26 loc) · 1.23 KB
/
test_temperature.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Tests Home Assistant temperature helpers."""
import pytest
from homeassistant.const import (
PRECISION_HALVES,
PRECISION_TENTHS,
PRECISION_WHOLE,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.temperature import display_temp
TEMP = 24.636626
def test_temperature_not_a_number(hass: HomeAssistant) -> None:
"""Test that temperature is a number."""
temp = "Temperature"
with pytest.raises(Exception) as exception:
display_temp(hass, temp, UnitOfTemperature.CELSIUS, PRECISION_HALVES)
assert f"Temperature is not a number: {temp}" in str(exception.value)
def test_celsius_halves(hass: HomeAssistant) -> None:
"""Test temperature to celsius rounding to halves."""
assert display_temp(hass, TEMP, UnitOfTemperature.CELSIUS, PRECISION_HALVES) == 24.5
def test_celsius_tenths(hass: HomeAssistant) -> None:
"""Test temperature to celsius rounding to tenths."""
assert display_temp(hass, TEMP, UnitOfTemperature.CELSIUS, PRECISION_TENTHS) == 24.6
def test_fahrenheit_wholes(hass: HomeAssistant) -> None:
"""Test temperature to fahrenheit rounding to wholes."""
assert display_temp(hass, TEMP, UnitOfTemperature.FAHRENHEIT, PRECISION_WHOLE) == -4