Use TEMP_CELSIUS constant (#33963)

This commit is contained in:
springstan 2020-04-10 19:17:46 +02:00 committed by GitHub
parent ca0648afe8
commit 78d87dc40f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 129 additions and 96 deletions

View File

@ -18,6 +18,7 @@ from homeassistant.const import (
SPEED_KILOMETERS_PER_HOUR,
SPEED_METERS_PER_SECOND,
SPEED_MILES_PER_HOUR,
TEMP_CELSIUS,
TIME_HOURS,
UNIT_PERCENTAGE,
UNIT_UV_INDEX,
@ -134,31 +135,31 @@ SENSOR_TYPES = {
],
"temperature": [
"Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["currently", "hourly"],
],
"apparent_temperature": [
"Apparent Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["currently", "hourly"],
],
"dew_point": [
"Dew Point",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["currently", "hourly", "daily"],
],
@ -244,81 +245,81 @@ SENSOR_TYPES = {
],
"apparent_temperature_max": [
"Daily High Apparent Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["daily"],
],
"apparent_temperature_high": [
"Daytime High Apparent Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["daily"],
],
"apparent_temperature_min": [
"Daily Low Apparent Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["daily"],
],
"apparent_temperature_low": [
"Overnight Low Apparent Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["daily"],
],
"temperature_max": [
"Daily High Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["daily"],
],
"temperature_high": [
"Daytime High Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["daily"],
],
"temperature_min": [
"Daily Low Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["daily"],
],
"temperature_low": [
"Overnight Low Temperature",
"°C",
TEMP_CELSIUS,
"°F",
"°C",
"°C",
"°C",
TEMP_CELSIUS,
TEMP_CELSIUS,
TEMP_CELSIUS,
"mdi:thermometer",
["daily"],
],

View File

@ -1,7 +1,7 @@
"""Support for Eight Sleep sensors."""
import logging
from homeassistant.const import UNIT_PERCENTAGE
from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE
from . import (
CONF_SENSORS,
@ -166,7 +166,7 @@ class EightUserSensor(EightSleepUserEntity):
return "Score"
if "bed_temp" in self._sensor:
if self._units == "si":
return "°C"
return TEMP_CELSIUS
return "°F"
return None
@ -329,7 +329,7 @@ class EightRoomSensor(EightSleepUserEntity):
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
if self._units == "si":
return "°C"
return TEMP_CELSIUS
return "°F"
@property

View File

@ -9,6 +9,7 @@ from homeassistant.const import (
ENERGY_WATT_HOUR,
POWER_WATT,
SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS,
UNIT_PERCENTAGE,
VOLUME_CUBIC_METERS,
)
@ -34,8 +35,8 @@ HM_STATE_HA_CAST = {
HM_UNIT_HA_CAST = {
"HUMIDITY": UNIT_PERCENTAGE,
"TEMPERATURE": "°C",
"ACTUAL_TEMPERATURE": "°C",
"TEMPERATURE": TEMP_CELSIUS,
"ACTUAL_TEMPERATURE": TEMP_CELSIUS,
"BRIGHTNESS": "#",
"POWER": POWER_WATT,
"CURRENT": "mA",

View File

@ -16,6 +16,7 @@ from homeassistant.const import (
CONF_NAME,
CONF_SCAN_INTERVAL,
EVENT_HOMEASSISTANT_START,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UNIT_PERCENTAGE,
)
@ -50,7 +51,7 @@ ATTR_LAST_SUCCESSFUL_UPDATE = "last_successful_update"
# Sensor types are defined like: Name, units, icon
SENSOR_TYPES = {
"temperature": ["Temperature", "°C", "mdi:thermometer"],
"temperature": ["Temperature", TEMP_CELSIUS, "mdi:thermometer"],
"light": ["Light intensity", "lx", "mdi:white-balance-sunny"],
"moisture": ["Moisture", UNIT_PERCENTAGE, "mdi:water-percent"],
"conductivity": ["Conductivity", "µS/cm", "mdi:flash-circle"],

View File

@ -15,6 +15,7 @@ from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE,
TEMP_CELSIUS,
UNIT_PERCENTAGE,
)
import homeassistant.helpers.config_validation as cv
@ -46,7 +47,7 @@ DEFAULT_TIMEOUT = 10
# Sensor types are defined like: Name, units
SENSOR_TYPES = {
"temperature": [DEVICE_CLASS_TEMPERATURE, "Temperature", "°C"],
"temperature": [DEVICE_CLASS_TEMPERATURE, "Temperature", TEMP_CELSIUS],
"humidity": [DEVICE_CLASS_HUMIDITY, "Humidity", UNIT_PERCENTAGE],
"battery": [DEVICE_CLASS_BATTERY, "Battery", UNIT_PERCENTAGE],
}

View File

@ -7,7 +7,12 @@ from aionotion.errors import InvalidCredentialsError, NotionError
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.const import ATTR_ATTRIBUTION, CONF_PASSWORD, CONF_USERNAME
from homeassistant.const import (
ATTR_ATTRIBUTION,
CONF_PASSWORD,
CONF_USERNAME,
TEMP_CELSIUS,
)
from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import (
@ -57,7 +62,7 @@ BINARY_SENSOR_TYPES = {
SENSOR_WINDOW_HINGED_HORIZONTAL: ("Hinged Window", "window"),
SENSOR_WINDOW_HINGED_VERTICAL: ("Hinged Window", "window"),
}
SENSOR_TYPES = {SENSOR_TEMPERATURE: ("Temperature", "temperature", "°C")}
SENSOR_TYPES = {SENSOR_TEMPERATURE: ("Temperature", "temperature", TEMP_CELSIUS)}
CONFIG_SCHEMA = vol.Schema(
{

View File

@ -1,6 +1,7 @@
"""This platform provides support for sensor data from RainMachine."""
import logging
from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -57,7 +58,7 @@ SENSORS = {
TYPE_FREEZE_TEMP: (
"Freeze Protect Temperature",
"mdi:thermometer",
"°C",
TEMP_CELSIUS,
"temperature",
True,
DATA_RESTRICTIONS_UNIVERSAL,
@ -84,7 +85,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
sensor_type,
(name, icon, unit, device_class, enabled_by_default, api_category),
) in SENSORS.items()
],
]
)

View File

@ -38,7 +38,7 @@ class VelbusClimate(VelbusEntity, ClimateDevice):
@property
def temperature_unit(self):
"""Return the unit this state is expressed in."""
if self._module.get_unit(self._channel) == "°C":
if self._module.get_unit(self._channel) == TEMP_CELSIUS:
return TEMP_CELSIUS
return TEMP_FAHRENHEIT

View File

@ -18,6 +18,7 @@ from homeassistant.const import (
CONF_MONITORED_CONDITIONS,
CONF_NAME,
SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS,
UNIT_PERCENTAGE,
__version__,
)
@ -56,9 +57,9 @@ SENSOR_TYPES = {
),
"wind_max_bearing": ("Top Wind Bearing", "°", "WSR °", int),
"sun_last_hour": ("Sun Last Hour", UNIT_PERCENTAGE, f"SO {UNIT_PERCENTAGE}", int),
"temperature": ("Temperature", "°C", "T °C", float),
"temperature": ("Temperature", TEMP_CELSIUS, f"T {TEMP_CELSIUS}", float),
"precipitation": ("Precipitation", "l/m²", "N l/m²", float),
"dewpoint": ("Dew Point", "°C", "TP °C", float),
"dewpoint": ("Dew Point", TEMP_CELSIUS, f"TP {TEMP_CELSIUS}", float),
# The following probably not useful for general consumption,
# but we need them to fill in internal attributes
"station_name": ("Station Name", None, "Name", str),

View File

@ -6,6 +6,7 @@ from homeassistant.const import (
ATTR_FRIENDLY_NAME,
ATTR_UNIT_OF_MEASUREMENT,
DEVICE_CLASS_HUMIDITY,
TEMP_CELSIUS,
)
from .common import setup_platform
@ -41,4 +42,4 @@ async def test_attributes(hass):
state = hass.states.get("sensor.environment_sensor_temperature")
# Abodepy device JSON reports 19.5, but Home Assistant shows 19.4
assert state.state == "19.4"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "°C"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS

View File

@ -12,7 +12,7 @@ from homeassistant.components.canary.sensor import (
STATE_AIR_QUALITY_VERY_ABNORMAL,
CanarySensor,
)
from homeassistant.const import UNIT_PERCENTAGE
from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE
from tests.common import get_test_home_assistant
from tests.components.canary.test_init import mock_device, mock_location
@ -69,7 +69,7 @@ class TestCanarySensorSetup(unittest.TestCase):
sensor.update()
assert sensor.name == "Home Family Room Temperature"
assert sensor.unit_of_measurement == "°C"
assert sensor.unit_of_measurement == TEMP_CELSIUS
assert sensor.state == 21.12
assert sensor.icon == "mdi:thermometer"

View File

@ -4,6 +4,7 @@ import voluptuous_serialize
import homeassistant.components.automation as automation
from homeassistant.components.climate import DOMAIN, const, device_trigger
from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers import config_validation as cv, device_registry
from homeassistant.setup import async_setup_component
@ -228,13 +229,13 @@ async def test_get_trigger_capabilities_temp_humid(hass, type):
capabilities["extra_fields"], custom_serializer=cv.custom_serializer
) == [
{
"description": {"suffix": "°C"},
"description": {"suffix": TEMP_CELSIUS},
"name": "above",
"optional": True,
"type": "float",
},
{
"description": {"suffix": "°C"},
"description": {"suffix": TEMP_CELSIUS},
"name": "below",
"optional": True,
"type": "float",

View File

@ -208,7 +208,7 @@ class DysonTest(unittest.TestCase):
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state is None
assert sensor.unit_of_measurement == "°C"
assert sensor.unit_of_measurement == TEMP_CELSIUS
assert sensor.name == "Device_name Temperature"
assert sensor.entity_id == "sensor.dyson_1"
@ -219,7 +219,7 @@ class DysonTest(unittest.TestCase):
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == 21.9
assert sensor.unit_of_measurement == "°C"
assert sensor.unit_of_measurement == TEMP_CELSIUS
assert sensor.name == "Device_name Temperature"
assert sensor.entity_id == "sensor.dyson_1"
@ -241,7 +241,7 @@ class DysonTest(unittest.TestCase):
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == STATE_OFF
assert sensor.unit_of_measurement == "°C"
assert sensor.unit_of_measurement == TEMP_CELSIUS
assert sensor.name == "Device_name Temperature"
assert sensor.entity_id == "sensor.dyson_1"

View File

@ -5,6 +5,7 @@ from unittest.mock import Mock, patch
import requests
from homeassistant.components.fritzbox.climate import FritzboxThermostat
from homeassistant.const import TEMP_CELSIUS
class TestFritzboxClimate(unittest.TestCase):
@ -51,7 +52,7 @@ class TestFritzboxClimate(unittest.TestCase):
def test_temperature_unit(self):
"""Test temperature_unit property."""
assert "°C" == self.thermostat.temperature_unit
assert TEMP_CELSIUS == self.thermostat.temperature_unit
def test_precision(self):
"""Test precision property."""

View File

@ -3,6 +3,7 @@ import socket
import unittest
from unittest.mock import patch
from homeassistant.const import TEMP_CELSIUS
from homeassistant.setup import setup_component
from tests.common import get_test_home_assistant
@ -64,25 +65,25 @@ class TestHDDTempSensor(unittest.TestCase):
"/dev/sda1": {
"device": "/dev/sda1",
"temperature": "29",
"unit_of_measurement": "°C",
"unit_of_measurement": TEMP_CELSIUS,
"model": "WDC WD30EZRX-12DC0B0",
},
"/dev/sdb1": {
"device": "/dev/sdb1",
"temperature": "32",
"unit_of_measurement": "°C",
"unit_of_measurement": TEMP_CELSIUS,
"model": "WDC WD15EADS-11P7B2",
},
"/dev/sdc1": {
"device": "/dev/sdc1",
"temperature": "29",
"unit_of_measurement": "°C",
"unit_of_measurement": TEMP_CELSIUS,
"model": "WDC WD20EARX-22MMMB0",
},
"/dev/sdd1": {
"device": "/dev/sdd1",
"temperature": "32",
"unit_of_measurement": "°C",
"unit_of_measurement": TEMP_CELSIUS,
"model": "WDC WD15EARS-00Z5B1",
},
}

View File

@ -48,6 +48,7 @@ from homeassistant.const import (
ATTR_TEMPERATURE,
CONF_TEMPERATURE_UNIT,
EVENT_HOMEASSISTANT_START,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.core import CoreState
@ -86,7 +87,7 @@ async def test_thermostat(hass, hk_driver, cls, events):
HVAC_MODE_COOL,
HVAC_MODE_OFF,
HVAC_MODE_AUTO,
],
]
},
)
await hass.async_block_till_done()
@ -418,14 +419,14 @@ async def test_thermostat_humidity(hass, hk_driver, cls, events):
assert acc.char_target_humidity.properties[PROP_MIN_VALUE] == DEFAULT_MIN_HUMIDITY
hass.states.async_set(
entity_id, HVAC_MODE_HEAT_COOL, {ATTR_HUMIDITY: 65, ATTR_CURRENT_HUMIDITY: 40},
entity_id, HVAC_MODE_HEAT_COOL, {ATTR_HUMIDITY: 65, ATTR_CURRENT_HUMIDITY: 40}
)
await hass.async_block_till_done()
assert acc.char_current_humidity.value == 40
assert acc.char_target_humidity.value == 65
hass.states.async_set(
entity_id, HVAC_MODE_COOL, {ATTR_HUMIDITY: 35, ATTR_CURRENT_HUMIDITY: 70},
entity_id, HVAC_MODE_COOL, {ATTR_HUMIDITY: 35, ATTR_CURRENT_HUMIDITY: 70}
)
await hass.async_block_till_done()
assert acc.char_current_humidity.value == 70
@ -618,7 +619,7 @@ async def test_thermostat_restore(hass, hk_driver, cls, events):
registry = await entity_registry.async_get_registry(hass)
registry.async_get_or_create(
"climate", "generic", "1234", suggested_object_id="simple",
"climate", "generic", "1234", suggested_object_id="simple"
)
registry.async_get_or_create(
"climate",
@ -898,7 +899,7 @@ async def test_water_heater(hass, hk_driver, cls, events):
assert call_set_temperature[0].data[ATTR_TEMPERATURE] == 52.0
assert acc.char_target_temp.value == 52.0
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] == "52.0°C"
assert events[-1].data[ATTR_VALUE] == f"52.0{TEMP_CELSIUS}"
await hass.async_add_executor_job(acc.char_target_heat_cool.client_update_value, 0)
await hass.async_block_till_done()
@ -975,7 +976,7 @@ async def test_water_heater_restore(hass, hk_driver, cls, events):
registry = await entity_registry.async_get_registry(hass)
registry.async_get_or_create(
"water_heater", "generic", "1234", suggested_object_id="simple",
"water_heater", "generic", "1234", suggested_object_id="simple"
)
registry.async_get_or_create(
"water_heater",

View File

@ -4,7 +4,11 @@ from unittest.mock import DEFAULT, Mock, patch
import homeassistant.components.mhz19.sensor as mhz19
from homeassistant.components.sensor import DOMAIN
from homeassistant.const import CONCENTRATION_PARTS_PER_MILLION, TEMP_FAHRENHEIT
from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.setup import setup_component
from tests.common import assert_setup_component, get_test_home_assistant
@ -115,7 +119,7 @@ class TestMHZ19Sensor(unittest.TestCase):
assert sensor.name == "name: Temperature"
assert sensor.state == 24
assert sensor.unit_of_measurement == "°C"
assert sensor.unit_of_measurement == TEMP_CELSIUS
assert sensor.should_poll
assert sensor.device_state_attributes == {"co2_concentration": 1000}

View File

@ -221,7 +221,7 @@ class TestMinMaxSensor(unittest.TestCase):
state = self.hass.states.get("sensor.test")
assert str(float(self.values[0])) == state.state
assert state.attributes.get("unit_of_measurement") == "°C"
assert state.attributes.get("unit_of_measurement") == TEMP_CELSIUS
self.hass.states.set(
entity_ids[1], self.values[1], {ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT}

View File

@ -16,6 +16,7 @@ from homeassistant.const import (
ATTR_SERVICE,
EVENT_CALL_SERVICE,
EVENT_HOMEASSISTANT_STOP,
TEMP_CELSIUS,
)
from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryNotReady
@ -342,7 +343,7 @@ class TestMQTTCallbacks(unittest.TestCase):
mqtt.subscribe(self.hass, "test-topic", self.record_calls, encoding="ascii")
mqtt.subscribe(self.hass, "test-topic", self.record_calls)
fire_mqtt_message(self.hass, "test-topic", "°C")
fire_mqtt_message(self.hass, "test-topic", TEMP_CELSIUS)
self.hass.block_till_done()
assert len(self.calls) == 1

View File

@ -1,5 +1,7 @@
"""The sensor tests for the nexia platform."""
from homeassistant.const import TEMP_CELSIUS
from .util import async_init_integration
@ -15,7 +17,7 @@ async def test_create_sensors(hass):
"attribution": "Data provided by mynexia.com",
"device_class": "temperature",
"friendly_name": "Nick Office Temperature",
"unit_of_measurement": "°C",
"unit_of_measurement": TEMP_CELSIUS,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
@ -82,7 +84,7 @@ async def test_create_sensors(hass):
"attribution": "Data provided by mynexia.com",
"device_class": "temperature",
"friendly_name": "Master Suite Outdoor Temperature",
"unit_of_measurement": "°C",
"unit_of_measurement": TEMP_CELSIUS,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears

View File

@ -12,7 +12,7 @@ from homeassistant.components.rflink import (
EVENT_KEY_SENSOR,
TMP_ENTITY,
)
from homeassistant.const import STATE_UNKNOWN, UNIT_PERCENTAGE
from homeassistant.const import STATE_UNKNOWN, TEMP_CELSIUS, UNIT_PERCENTAGE
from tests.components.rflink.test_init import mock_rflink
@ -42,23 +42,27 @@ async def test_default_setup(hass, monkeypatch):
config_sensor = hass.states.get("sensor.test")
assert config_sensor
assert config_sensor.state == "unknown"
assert config_sensor.attributes["unit_of_measurement"] == "°C"
assert config_sensor.attributes["unit_of_measurement"] == TEMP_CELSIUS
# test event for config sensor
event_callback({"id": "test", "sensor": "temperature", "value": 1, "unit": "°C"})
event_callback(
{"id": "test", "sensor": "temperature", "value": 1, "unit": TEMP_CELSIUS}
)
await hass.async_block_till_done()
assert hass.states.get("sensor.test").state == "1"
# test event for new unconfigured sensor
event_callback({"id": "test2", "sensor": "temperature", "value": 0, "unit": "°C"})
event_callback(
{"id": "test2", "sensor": "temperature", "value": 0, "unit": TEMP_CELSIUS}
)
await hass.async_block_till_done()
# test state of new sensor
new_sensor = hass.states.get("sensor.test2")
assert new_sensor
assert new_sensor.state == "0"
assert new_sensor.attributes["unit_of_measurement"] == "°C"
assert new_sensor.attributes["unit_of_measurement"] == TEMP_CELSIUS
assert new_sensor.attributes["icon"] == "mdi:thermometer"
@ -73,7 +77,9 @@ async def test_disable_automatic_add(hass, monkeypatch):
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
# test event for new unconfigured sensor
event_callback({"id": "test2", "sensor": "temperature", "value": 0, "unit": "°C"})
event_callback(
{"id": "test2", "sensor": "temperature", "value": 0, "unit": TEMP_CELSIUS}
)
await hass.async_block_till_done()
# make sure new device is not added

View File

@ -5,7 +5,7 @@ from unittest.mock import patch
import pytest
from homeassistant.components.spaceapi import DOMAIN, SPACEAPI_VERSION, URL_API_SPACEAPI
from homeassistant.const import UNIT_PERCENTAGE
from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE
from homeassistant.setup import async_setup_component
from tests.common import mock_coro
@ -60,8 +60,8 @@ CONFIG = {
SENSOR_OUTPUT = {
"temperature": [
{"location": "Home", "name": "temp1", "unit": "°C", "value": "25"},
{"location": "Home", "name": "temp2", "unit": "°C", "value": "23"},
{"location": "Home", "name": "temp1", "unit": TEMP_CELSIUS, "value": "25"},
{"location": "Home", "name": "temp2", "unit": TEMP_CELSIUS, "value": "23"},
],
"humidity": [
{"location": "Home", "name": "hum1", "unit": UNIT_PERCENTAGE, "value": "88"}
@ -75,8 +75,12 @@ def mock_client(hass, hass_client):
with patch("homeassistant.components.spaceapi", return_value=mock_coro(True)):
hass.loop.run_until_complete(async_setup_component(hass, "spaceapi", CONFIG))
hass.states.async_set("test.temp1", 25, attributes={"unit_of_measurement": "°C"})
hass.states.async_set("test.temp2", 23, attributes={"unit_of_measurement": "°C"})
hass.states.async_set(
"test.temp1", 25, attributes={"unit_of_measurement": TEMP_CELSIUS}
)
hass.states.async_set(
"test.temp2", 23, attributes={"unit_of_measurement": TEMP_CELSIUS}
)
hass.states.async_set(
"test.hum1", 88, attributes={"unit_of_measurement": UNIT_PERCENTAGE}
)

View File

@ -102,7 +102,7 @@ class TestStatisticsSensor(unittest.TestCase):
assert self.mean == state.attributes.get("mean")
assert self.count == state.attributes.get("count")
assert self.total == state.attributes.get("total")
assert "°C" == state.attributes.get("unit_of_measurement")
assert TEMP_CELSIUS == state.attributes.get("unit_of_measurement")
assert self.change == state.attributes.get("change")
assert self.average_change == state.attributes.get("average_change")

View File

@ -41,7 +41,7 @@ async def async_test_humidity(hass, cluster, entity_id):
async def async_test_temperature(hass, cluster, entity_id):
"""Test temperature sensor."""
await send_attributes_report(hass, cluster, {1: 1, 0: 2900, 2: 100})
assert_state(hass, entity_id, "29.0", "°C")
assert_state(hass, entity_id, "29.0", TEMP_CELSIUS)
async def async_test_pressure(hass, cluster, entity_id):