1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-22 11:50:05 +00:00
Files
.devcontainer
.github
.vscode
docs
homeassistant
machine
pylint
rootfs
script
tests
auth
backports
components
fixtures
hassfest
helpers
__init__.py
test_aiohttp_client.py
test_aiohttp_compat.py
test_area_registry.py
test_check_config.py
test_collection.py
test_condition.py
test_config_entry_flow.py
test_config_entry_oauth2_flow.py
test_config_validation.py
test_debounce.py
test_deprecation.py
test_device_registry.py
test_discovery.py
test_discovery_flow.py
test_dispatcher.py
test_entity.py
test_entity_component.py
test_entity_platform.py
test_entity_registry.py
test_entity_values.py
test_entityfilter.py
test_event.py
test_frame.py
test_httpx_client.py
test_icon.py
test_init.py
test_instance_id.py
test_integration_platform.py
test_intent.py
test_issue_registry.py
test_json.py
test_location.py
test_network.py
test_ratelimit.py
test_recorder.py
test_reload.py
test_restore_state.py
test_schema_config_entry_flow.py
test_script.py
test_script_variables.py
test_selector.py
test_service.py
test_significant_change.py
test_singleton.py
test_start.py
test_state.py
test_storage.py
test_storage_remove.py
test_sun.py
test_system_info.py
test_temperature.py
test_template.py
test_translation.py
test_trigger.py
test_update_coordinator.py
pylint
resources
scripts
test_util
testing_config
util
__init__.py
asyncio_legacy.py
bandit.yaml
common.py
conftest.py
ignore_uncaught_exceptions.py
ruff.toml
syrupy.py
test_bootstrap.py
test_config.py
test_config_entries.py
test_core.py
test_data_entry_flow.py
test_exceptions.py
test_loader.py
test_main.py
test_requirements.py
test_runner.py
test_setup.py
test_test_fixtures.py
typing.py
.core_files.yaml
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hadolint.yaml
.pre-commit-config.yaml
.prettierignore
.readthedocs.yml
.strict-typing
.yamllint
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
build.yaml
codecov.yml
mypy.ini
pyproject.toml
requirements.txt
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
requirements_test_pre_commit.txt
setup.cfg
core/tests/helpers/test_temperature.py

39 lines
1.2 KiB
Python

"""Tests Home Assistant temperature helpers."""
import pytest
from homeassistant.const import (
PRECISION_HALVES,
PRECISION_TENTHS,
PRECISION_WHOLE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
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, TEMP_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, TEMP_CELSIUS, PRECISION_HALVES) == 24.5
def test_celsius_tenths(hass: HomeAssistant) -> None:
"""Test temperature to celsius rounding to tenths."""
assert display_temp(hass, TEMP, TEMP_CELSIUS, PRECISION_TENTHS) == 24.6
def test_fahrenheit_wholes(hass: HomeAssistant) -> None:
"""Test temperature to fahrenheit rounding to wholes."""
assert display_temp(hass, TEMP, TEMP_FAHRENHEIT, PRECISION_WHOLE) == -4