mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Replace the usage of unit constants by enumerations in Tests [s-u] (#85937)
This commit is contained in:
parent
0b02abf708
commit
9709391b52
@ -18,7 +18,7 @@ from homeassistant.const import (
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -172,7 +172,7 @@ async def test_scrape_uom_and_classes(hass: HomeAssistant) -> None:
|
||||
|
||||
state = hass.states.get("sensor.current_temp")
|
||||
assert state.state == "22.1"
|
||||
assert state.attributes[CONF_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS
|
||||
assert state.attributes[CONF_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS
|
||||
assert state.attributes[CONF_DEVICE_CLASS] == SensorDeviceClass.TEMPERATURE
|
||||
assert state.attributes[CONF_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||
|
||||
|
@ -9,32 +9,16 @@ from homeassistant.components.number import NumberDeviceClass
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
LENGTH_CENTIMETERS,
|
||||
LENGTH_INCHES,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_METERS,
|
||||
LENGTH_MILES,
|
||||
LENGTH_YARD,
|
||||
MASS_GRAMS,
|
||||
MASS_OUNCES,
|
||||
PERCENTAGE,
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_INHG,
|
||||
PRESSURE_KPA,
|
||||
PRESSURE_MMHG,
|
||||
SPEED_INCHES_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILLIMETERS_PER_DAY,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
VOLUME_CUBIC_FEET,
|
||||
VOLUME_CUBIC_METERS,
|
||||
VOLUME_FLUID_OUNCE,
|
||||
VOLUME_LITERS,
|
||||
UnitOfEnergy,
|
||||
UnitOfLength,
|
||||
UnitOfMass,
|
||||
UnitOfPressure,
|
||||
UnitOfSpeed,
|
||||
UnitOfTemperature,
|
||||
UnitOfVolume,
|
||||
UnitOfVolumetricFlux,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -49,10 +33,28 @@ from tests.common import mock_restore_cache_with_extra_data
|
||||
@pytest.mark.parametrize(
|
||||
"unit_system,native_unit,state_unit,native_value,state_value",
|
||||
[
|
||||
(US_CUSTOMARY_SYSTEM, TEMP_FAHRENHEIT, TEMP_FAHRENHEIT, 100, 100),
|
||||
(US_CUSTOMARY_SYSTEM, TEMP_CELSIUS, TEMP_FAHRENHEIT, 38, 100),
|
||||
(METRIC_SYSTEM, TEMP_FAHRENHEIT, TEMP_CELSIUS, 100, 38),
|
||||
(METRIC_SYSTEM, TEMP_CELSIUS, TEMP_CELSIUS, 38, 38),
|
||||
(
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
UnitOfTemperature.FAHRENHEIT,
|
||||
UnitOfTemperature.FAHRENHEIT,
|
||||
100,
|
||||
100,
|
||||
),
|
||||
(
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
UnitOfTemperature.FAHRENHEIT,
|
||||
38,
|
||||
100,
|
||||
),
|
||||
(
|
||||
METRIC_SYSTEM,
|
||||
UnitOfTemperature.FAHRENHEIT,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
100,
|
||||
38,
|
||||
),
|
||||
(METRIC_SYSTEM, UnitOfTemperature.CELSIUS, UnitOfTemperature.CELSIUS, 38, 38),
|
||||
],
|
||||
)
|
||||
async def test_temperature_conversion(
|
||||
@ -94,7 +96,7 @@ async def test_temperature_conversion_wrong_device_class(
|
||||
platform.ENTITIES["0"] = platform.MockSensor(
|
||||
name="Test",
|
||||
native_value="0.0",
|
||||
native_unit_of_measurement=TEMP_FAHRENHEIT,
|
||||
native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
|
||||
device_class=device_class,
|
||||
)
|
||||
|
||||
@ -105,7 +107,7 @@ async def test_temperature_conversion_wrong_device_class(
|
||||
# Check temperature is not converted
|
||||
state = hass.states.get(entity0.entity_id)
|
||||
assert state.state == "0.0"
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_FAHRENHEIT
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.FAHRENHEIT
|
||||
|
||||
|
||||
@pytest.mark.parametrize("state_class", ("measurement", "total_increasing"))
|
||||
@ -407,50 +409,50 @@ async def test_restore_sensor_restore_state(
|
||||
# Smaller to larger unit, InHg is ~33x larger than hPa -> 1 more decimal
|
||||
(
|
||||
SensorDeviceClass.PRESSURE,
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_INHG,
|
||||
PRESSURE_INHG,
|
||||
UnitOfPressure.HPA,
|
||||
UnitOfPressure.INHG,
|
||||
UnitOfPressure.INHG,
|
||||
1000.0,
|
||||
29.53,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.PRESSURE,
|
||||
PRESSURE_KPA,
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_HPA,
|
||||
UnitOfPressure.KPA,
|
||||
UnitOfPressure.HPA,
|
||||
UnitOfPressure.HPA,
|
||||
1.234,
|
||||
12.34,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.PRESSURE,
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_MMHG,
|
||||
PRESSURE_MMHG,
|
||||
UnitOfPressure.HPA,
|
||||
UnitOfPressure.MMHG,
|
||||
UnitOfPressure.MMHG,
|
||||
1000,
|
||||
750,
|
||||
),
|
||||
# Not a supported pressure unit
|
||||
(
|
||||
SensorDeviceClass.PRESSURE,
|
||||
PRESSURE_HPA,
|
||||
UnitOfPressure.HPA,
|
||||
"peer_pressure",
|
||||
PRESSURE_HPA,
|
||||
UnitOfPressure.HPA,
|
||||
1000,
|
||||
1000,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.TEMPERATURE,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
TEMP_FAHRENHEIT,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
UnitOfTemperature.FAHRENHEIT,
|
||||
UnitOfTemperature.FAHRENHEIT,
|
||||
37.5,
|
||||
99.5,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.TEMPERATURE,
|
||||
TEMP_FAHRENHEIT,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfTemperature.FAHRENHEIT,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
100,
|
||||
38.0,
|
||||
),
|
||||
@ -499,25 +501,25 @@ async def test_custom_unit(
|
||||
[
|
||||
# Distance
|
||||
(
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_MILES,
|
||||
LENGTH_MILES,
|
||||
UnitOfLength.KILOMETERS,
|
||||
UnitOfLength.MILES,
|
||||
UnitOfLength.MILES,
|
||||
1000,
|
||||
621,
|
||||
SensorDeviceClass.DISTANCE,
|
||||
),
|
||||
(
|
||||
LENGTH_CENTIMETERS,
|
||||
LENGTH_INCHES,
|
||||
LENGTH_INCHES,
|
||||
UnitOfLength.CENTIMETERS,
|
||||
UnitOfLength.INCHES,
|
||||
UnitOfLength.INCHES,
|
||||
7.24,
|
||||
2.85,
|
||||
SensorDeviceClass.DISTANCE,
|
||||
),
|
||||
(
|
||||
LENGTH_KILOMETERS,
|
||||
UnitOfLength.KILOMETERS,
|
||||
"peer_distance",
|
||||
LENGTH_KILOMETERS,
|
||||
UnitOfLength.KILOMETERS,
|
||||
1000,
|
||||
1000,
|
||||
SensorDeviceClass.DISTANCE,
|
||||
@ -575,109 +577,109 @@ async def test_custom_unit(
|
||||
# Pressure
|
||||
# Smaller to larger unit, InHg is ~33x larger than hPa -> 1 more decimal
|
||||
(
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_INHG,
|
||||
PRESSURE_INHG,
|
||||
UnitOfPressure.HPA,
|
||||
UnitOfPressure.INHG,
|
||||
UnitOfPressure.INHG,
|
||||
1000.0,
|
||||
29.53,
|
||||
SensorDeviceClass.PRESSURE,
|
||||
),
|
||||
(
|
||||
PRESSURE_KPA,
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_HPA,
|
||||
UnitOfPressure.KPA,
|
||||
UnitOfPressure.HPA,
|
||||
UnitOfPressure.HPA,
|
||||
1.234,
|
||||
12.34,
|
||||
SensorDeviceClass.PRESSURE,
|
||||
),
|
||||
(
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_MMHG,
|
||||
PRESSURE_MMHG,
|
||||
UnitOfPressure.HPA,
|
||||
UnitOfPressure.MMHG,
|
||||
UnitOfPressure.MMHG,
|
||||
1000,
|
||||
750,
|
||||
SensorDeviceClass.PRESSURE,
|
||||
),
|
||||
# Not a supported pressure unit
|
||||
(
|
||||
PRESSURE_HPA,
|
||||
UnitOfPressure.HPA,
|
||||
"peer_pressure",
|
||||
PRESSURE_HPA,
|
||||
UnitOfPressure.HPA,
|
||||
1000,
|
||||
1000,
|
||||
SensorDeviceClass.PRESSURE,
|
||||
),
|
||||
# Speed
|
||||
(
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||
UnitOfSpeed.MILES_PER_HOUR,
|
||||
UnitOfSpeed.MILES_PER_HOUR,
|
||||
100,
|
||||
62,
|
||||
SensorDeviceClass.SPEED,
|
||||
),
|
||||
(
|
||||
SPEED_MILLIMETERS_PER_DAY,
|
||||
SPEED_INCHES_PER_HOUR,
|
||||
SPEED_INCHES_PER_HOUR,
|
||||
UnitOfVolumetricFlux.MILLIMETERS_PER_DAY,
|
||||
UnitOfVolumetricFlux.INCHES_PER_HOUR,
|
||||
UnitOfVolumetricFlux.INCHES_PER_HOUR,
|
||||
78,
|
||||
0.13,
|
||||
SensorDeviceClass.SPEED,
|
||||
),
|
||||
(
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||
"peer_distance",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||
100,
|
||||
100,
|
||||
SensorDeviceClass.SPEED,
|
||||
),
|
||||
# Volume
|
||||
(
|
||||
VOLUME_CUBIC_METERS,
|
||||
VOLUME_CUBIC_FEET,
|
||||
VOLUME_CUBIC_FEET,
|
||||
UnitOfVolume.CUBIC_METERS,
|
||||
UnitOfVolume.CUBIC_FEET,
|
||||
UnitOfVolume.CUBIC_FEET,
|
||||
100,
|
||||
3531,
|
||||
SensorDeviceClass.VOLUME,
|
||||
),
|
||||
(
|
||||
VOLUME_LITERS,
|
||||
VOLUME_FLUID_OUNCE,
|
||||
VOLUME_FLUID_OUNCE,
|
||||
UnitOfVolume.LITERS,
|
||||
UnitOfVolume.FLUID_OUNCES,
|
||||
UnitOfVolume.FLUID_OUNCES,
|
||||
2.3,
|
||||
77.8,
|
||||
SensorDeviceClass.VOLUME,
|
||||
),
|
||||
(
|
||||
VOLUME_CUBIC_METERS,
|
||||
UnitOfVolume.CUBIC_METERS,
|
||||
"peer_distance",
|
||||
VOLUME_CUBIC_METERS,
|
||||
UnitOfVolume.CUBIC_METERS,
|
||||
100,
|
||||
100,
|
||||
SensorDeviceClass.VOLUME,
|
||||
),
|
||||
# Weight
|
||||
(
|
||||
MASS_GRAMS,
|
||||
MASS_OUNCES,
|
||||
MASS_OUNCES,
|
||||
UnitOfMass.GRAMS,
|
||||
UnitOfMass.OUNCES,
|
||||
UnitOfMass.OUNCES,
|
||||
100,
|
||||
3.5,
|
||||
SensorDeviceClass.WEIGHT,
|
||||
),
|
||||
(
|
||||
MASS_OUNCES,
|
||||
MASS_GRAMS,
|
||||
MASS_GRAMS,
|
||||
UnitOfMass.OUNCES,
|
||||
UnitOfMass.GRAMS,
|
||||
UnitOfMass.GRAMS,
|
||||
78,
|
||||
2211,
|
||||
SensorDeviceClass.WEIGHT,
|
||||
),
|
||||
(
|
||||
MASS_GRAMS,
|
||||
UnitOfMass.GRAMS,
|
||||
"peer_distance",
|
||||
MASS_GRAMS,
|
||||
UnitOfMass.GRAMS,
|
||||
100,
|
||||
100,
|
||||
SensorDeviceClass.WEIGHT,
|
||||
@ -746,10 +748,10 @@ async def test_custom_unit_change(
|
||||
# Distance
|
||||
(
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_MILES,
|
||||
LENGTH_METERS,
|
||||
LENGTH_YARD,
|
||||
UnitOfLength.KILOMETERS,
|
||||
UnitOfLength.MILES,
|
||||
UnitOfLength.METERS,
|
||||
UnitOfLength.YARDS,
|
||||
1000,
|
||||
621,
|
||||
1000000,
|
||||
@ -875,9 +877,9 @@ async def test_unit_conversion_priority(
|
||||
# Distance
|
||||
(
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_YARD,
|
||||
LENGTH_METERS,
|
||||
UnitOfLength.KILOMETERS,
|
||||
UnitOfLength.YARDS,
|
||||
UnitOfLength.METERS,
|
||||
1000,
|
||||
1093613,
|
||||
SensorDeviceClass.DISTANCE,
|
||||
@ -956,16 +958,16 @@ async def test_unit_conversion_priority_suggested_unit_change(
|
||||
# Distance
|
||||
(
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_MILES,
|
||||
UnitOfLength.KILOMETERS,
|
||||
UnitOfLength.MILES,
|
||||
1000,
|
||||
621,
|
||||
SensorDeviceClass.DISTANCE,
|
||||
),
|
||||
(
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
LENGTH_METERS,
|
||||
LENGTH_MILES,
|
||||
UnitOfLength.METERS,
|
||||
UnitOfLength.MILES,
|
||||
1000000,
|
||||
621.371,
|
||||
SensorDeviceClass.DISTANCE,
|
||||
|
@ -5,8 +5,7 @@ from homeassistant.components.sensor import SensorDeviceClass, significant_chang
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
|
||||
AQI_ATTRS = {
|
||||
@ -23,12 +22,12 @@ HUMIDITY_ATTRS = {
|
||||
|
||||
TEMP_CELSIUS_ATTRS = {
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
}
|
||||
|
||||
TEMP_FREEDOM_ATTRS = {
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.FAHRENHEIT,
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
"""Test the sma sensor platform."""
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, POWER_WATT
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfPower
|
||||
|
||||
|
||||
async def test_sensors(hass, init_integration):
|
||||
"""Test states of the sensors."""
|
||||
state = hass.states.get("sensor.sma_device_grid_power")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
|
||||
|
@ -31,7 +31,7 @@ from homeassistant.components.weather import (
|
||||
ATTR_WEATHER_WIND_SPEED_UNIT,
|
||||
DOMAIN as WEATHER_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, SPEED_METERS_PER_SECOND, STATE_UNKNOWN
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, STATE_UNKNOWN, UnitOfSpeed
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.util.dt import utcnow
|
||||
@ -343,7 +343,7 @@ async def test_custom_speed_unit(
|
||||
entity_reg.async_update_entity_options(
|
||||
state.entity_id,
|
||||
WEATHER_DOMAIN,
|
||||
{ATTR_WEATHER_WIND_SPEED_UNIT: SPEED_METERS_PER_SECOND},
|
||||
{ATTR_WEATHER_WIND_SPEED_UNIT: UnitOfSpeed.METERS_PER_SECOND},
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
@ -9,8 +9,8 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ICON,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
DATA_GIGABYTES,
|
||||
STATE_UNAVAILABLE,
|
||||
UnitOfInformation,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -56,7 +56,7 @@ async def test_sensors(
|
||||
state = hass.states.get("sensor.sonarr_disk_space")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:harddisk"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.attributes.get("C:\\") == "263.10/465.42GB (56.53%)"
|
||||
assert state.state == "263.10"
|
||||
|
||||
|
@ -7,7 +7,7 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.spaceapi import DOMAIN, SPACEAPI_VERSION, URL_API_SPACEAPI
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, TEMP_CELSIUS
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, UnitOfTemperature
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import mock_coro
|
||||
@ -62,8 +62,18 @@ CONFIG = {
|
||||
|
||||
SENSOR_OUTPUT = {
|
||||
"temperature": [
|
||||
{"location": "Home", "name": "temp1", "unit": TEMP_CELSIUS, "value": "25"},
|
||||
{"location": "Home", "name": "temp2", "unit": TEMP_CELSIUS, "value": "23"},
|
||||
{
|
||||
"location": "Home",
|
||||
"name": "temp1",
|
||||
"unit": UnitOfTemperature.CELSIUS,
|
||||
"value": "25",
|
||||
},
|
||||
{
|
||||
"location": "Home",
|
||||
"name": "temp2",
|
||||
"unit": UnitOfTemperature.CELSIUS,
|
||||
"value": "23",
|
||||
},
|
||||
],
|
||||
"humidity": [
|
||||
{"location": "Home", "name": "hum1", "unit": PERCENTAGE, "value": "88"}
|
||||
@ -78,10 +88,14 @@ def mock_client(hass, hass_client):
|
||||
hass.loop.run_until_complete(async_setup_component(hass, "spaceapi", CONFIG))
|
||||
|
||||
hass.states.async_set(
|
||||
"test.temp1", 25, attributes={ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
"test.temp1",
|
||||
25,
|
||||
attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
hass.states.async_set(
|
||||
"test.temp2", 23, attributes={ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
"test.temp2",
|
||||
23,
|
||||
attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
hass.states.async_set(
|
||||
"test.hum1", 88, attributes={ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE}
|
||||
|
@ -11,7 +11,7 @@ from homeassistant.components.srp_energy.const import (
|
||||
SRP_ENERGY_DOMAIN,
|
||||
)
|
||||
from homeassistant.components.srp_energy.sensor import SrpEntity, async_setup_entry
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.const import UnitOfEnergy
|
||||
|
||||
|
||||
async def test_async_setup_entry(hass):
|
||||
@ -89,7 +89,7 @@ async def test_srp_entity(hass):
|
||||
assert srp_entity.name == f"{DEFAULT_NAME} {SENSOR_NAME}"
|
||||
assert srp_entity.unique_id == SENSOR_TYPE
|
||||
assert srp_entity.state is None
|
||||
assert srp_entity.unit_of_measurement == ENERGY_KILO_WATT_HOUR
|
||||
assert srp_entity.unit_of_measurement == UnitOfEnergy.KILO_WATT_HOUR
|
||||
assert srp_entity.icon == ICON
|
||||
assert srp_entity.usage == "2.00"
|
||||
assert srp_entity.should_poll is False
|
||||
|
@ -3,7 +3,7 @@ from http import HTTPStatus
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.startca.sensor import StartcaData
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, DATA_GIGABYTES, PERCENTAGE
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, UnitOfInformation
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
|
||||
@ -59,47 +59,47 @@ async def test_capped_setup(hass, aioclient_mock):
|
||||
assert state.state == "76.24"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_usage")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_data_limit")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "400"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_download")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_upload")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_total")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "311.43"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_download")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_upload")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_total")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "311.43"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_total_download")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_total_upload")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_remaining")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "95.05"
|
||||
|
||||
|
||||
@ -155,47 +155,47 @@ async def test_unlimited_setup(hass, aioclient_mock):
|
||||
assert state.state == "0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_usage")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_data_limit")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "inf"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_download")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_upload")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_total")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_download")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_upload")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_total")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "311.43"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_total_download")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_total_upload")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_remaining")
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == DATA_GIGABYTES
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.GIGABYTES
|
||||
assert state.state == "inf"
|
||||
|
||||
|
||||
|
@ -21,7 +21,7 @@ from homeassistant.const import (
|
||||
SERVICE_RELOAD,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -85,14 +85,14 @@ async def test_sensor_defaults_numeric(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.test")
|
||||
assert state is not None
|
||||
assert state.state == str(round(sum(VALUES_NUMERIC) / len(VALUES_NUMERIC), 2))
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||
assert state.attributes.get("buffer_usage_ratio") == round(9 / 20, 2)
|
||||
assert state.attributes.get("source_value_valid") is True
|
||||
@ -113,14 +113,16 @@ async def test_sensor_defaults_numeric(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
"0",
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
new_state = hass.states.get("sensor.test")
|
||||
new_mean = round(sum(VALUES_NUMERIC) / (len(VALUES_NUMERIC) + 1), 2)
|
||||
assert new_state is not None
|
||||
assert new_state.state == str(new_mean)
|
||||
assert new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert (
|
||||
new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
|
||||
)
|
||||
assert new_state.attributes.get("buffer_usage_ratio") == round(10 / 20, 2)
|
||||
assert new_state.attributes.get("source_value_valid") is True
|
||||
|
||||
@ -131,7 +133,9 @@ async def test_sensor_defaults_numeric(hass: HomeAssistant):
|
||||
new_state = hass.states.get("sensor.test")
|
||||
assert new_state is not None
|
||||
assert new_state.state == str(new_mean)
|
||||
assert new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert (
|
||||
new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
|
||||
)
|
||||
assert new_state.attributes.get("source_value_valid") is False
|
||||
|
||||
# Source sensor has the STATE_UNKNOWN state, unit and state should not change
|
||||
@ -141,7 +145,9 @@ async def test_sensor_defaults_numeric(hass: HomeAssistant):
|
||||
new_state = hass.states.get("sensor.test")
|
||||
assert new_state is not None
|
||||
assert new_state.state == str(new_mean)
|
||||
assert new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert (
|
||||
new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
|
||||
)
|
||||
assert new_state.attributes.get("source_value_valid") is False
|
||||
|
||||
# Source sensor is removed, unit and state should not change
|
||||
@ -151,7 +157,9 @@ async def test_sensor_defaults_numeric(hass: HomeAssistant):
|
||||
new_state = hass.states.get("sensor.test")
|
||||
assert new_state is not None
|
||||
assert new_state.state == str(new_mean)
|
||||
assert new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert (
|
||||
new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
|
||||
)
|
||||
assert new_state.attributes.get("source_value_valid") is False
|
||||
|
||||
|
||||
@ -178,7 +186,7 @@ async def test_sensor_defaults_binary(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"binary_sensor.test_monitored",
|
||||
value,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -223,12 +231,12 @@ async def test_sensor_source_with_force_update(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored_normal",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored_force",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -265,7 +273,7 @@ async def test_sampling_size_reduced(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -299,7 +307,7 @@ async def test_sampling_size_1(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -347,7 +355,7 @@ async def test_age_limit_expiry(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -431,7 +439,7 @@ async def test_precision(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -483,7 +491,7 @@ async def test_percentile(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -539,7 +547,7 @@ async def test_device_class(hass: HomeAssistant):
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
},
|
||||
)
|
||||
@ -586,7 +594,7 @@ async def test_state_class(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -1024,12 +1032,12 @@ async def test_state_characteristics(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(VALUES_NUMERIC[i]),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
hass.states.async_set(
|
||||
"binary_sensor.test_monitored",
|
||||
str(VALUES_BINARY[i]),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -1126,7 +1134,7 @@ async def test_invalid_state_characteristic(hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(VALUES_NUMERIC[0]),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -1146,7 +1154,7 @@ async def test_initialize_from_database(recorder_mock, hass: HomeAssistant):
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await async_wait_recording_done(hass)
|
||||
@ -1172,7 +1180,7 @@ async def test_initialize_from_database(recorder_mock, hass: HomeAssistant):
|
||||
state = hass.states.get("sensor.test")
|
||||
assert state is not None
|
||||
assert state.state == str(round(sum(VALUES_NUMERIC) / len(VALUES_NUMERIC), 2))
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
|
||||
|
||||
|
||||
async def test_initialize_from_database_with_maxage(recorder_mock, hass: HomeAssistant):
|
||||
@ -1201,7 +1209,7 @@ async def test_initialize_from_database_with_maxage(recorder_mock, hass: HomeAss
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored",
|
||||
str(value),
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_data["return_time"] += timedelta(hours=1)
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Tests for the steamist sensos."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, TIME_MINUTES
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import (
|
||||
@ -16,10 +16,10 @@ async def test_steam_active(hass: HomeAssistant) -> None:
|
||||
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_ACTIVE)
|
||||
state = hass.states.get("sensor.steam_temperature")
|
||||
assert state.state == "39"
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS
|
||||
state = hass.states.get("sensor.steam_minutes_remain")
|
||||
assert state.state == "14"
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TIME_MINUTES
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTime.MINUTES
|
||||
|
||||
|
||||
async def test_steam_inactive(hass: HomeAssistant) -> None:
|
||||
@ -27,7 +27,7 @@ async def test_steam_inactive(hass: HomeAssistant) -> None:
|
||||
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_INACTIVE)
|
||||
state = hass.states.get("sensor.steam_temperature")
|
||||
assert state.state == "21"
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS
|
||||
state = hass.states.get("sensor.steam_minutes_remain")
|
||||
assert state.state == "0"
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TIME_MINUTES
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTime.MINUTES
|
||||
|
@ -4,7 +4,7 @@ from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@ -23,7 +23,9 @@ async def test_sensor_upper(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored", 16, {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
"sensor.test_monitored",
|
||||
16,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -156,7 +158,9 @@ async def test_sensor_in_range_no_hysteresis(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored", 16, {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
"sensor.test_monitored",
|
||||
16,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -205,7 +209,9 @@ async def test_sensor_in_range_with_hysteresis(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored", 16, {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
"sensor.test_monitored",
|
||||
16,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -303,7 +309,9 @@ async def test_sensor_in_range_unknown_state(hass, caplog):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
"sensor.test_monitored", 16, {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
"sensor.test_monitored",
|
||||
16,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -30,7 +30,7 @@ from homeassistant.const import (
|
||||
CONF_LONGITUDE,
|
||||
CONF_RADIUS,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
LENGTH_KILOMETERS,
|
||||
UnitOfLength,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
@ -152,7 +152,7 @@ async def test_setup(hass):
|
||||
ATTR_TYPE: "Type 1",
|
||||
ATTR_ALERT: "Alert 1",
|
||||
ATTR_MAGNITUDE: 5.7,
|
||||
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS,
|
||||
ATTR_SOURCE: "usgs_earthquakes_feed",
|
||||
ATTR_ICON: "mdi:pulse",
|
||||
}
|
||||
@ -166,7 +166,7 @@ async def test_setup(hass):
|
||||
ATTR_LATITUDE: -31.1,
|
||||
ATTR_LONGITUDE: 150.1,
|
||||
ATTR_FRIENDLY_NAME: "Title 2",
|
||||
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS,
|
||||
ATTR_SOURCE: "usgs_earthquakes_feed",
|
||||
ATTR_ICON: "mdi:pulse",
|
||||
}
|
||||
@ -180,7 +180,7 @@ async def test_setup(hass):
|
||||
ATTR_LATITUDE: -31.2,
|
||||
ATTR_LONGITUDE: 150.2,
|
||||
ATTR_FRIENDLY_NAME: "Title 3",
|
||||
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS,
|
||||
ATTR_SOURCE: "usgs_earthquakes_feed",
|
||||
ATTR_ICON: "mdi:pulse",
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_PLATFORM,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
Platform,
|
||||
UnitOfEnergy,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -90,7 +90,7 @@ async def test_services(hass, meter):
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
entity_id = config[DOMAIN]["energy_bill"]["source"]
|
||||
hass.states.async_set(
|
||||
entity_id, 1, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id, 1, {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -99,7 +99,7 @@ async def test_services(hass, meter):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
3,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -120,7 +120,7 @@ async def test_services(hass, meter):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
4,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -148,7 +148,7 @@ async def test_services(hass, meter):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
5,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -214,7 +214,7 @@ async def test_services_config_entry(hass):
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
entity_id = "sensor.energy"
|
||||
hass.states.async_set(
|
||||
entity_id, 1, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id, 1, {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -223,7 +223,7 @@ async def test_services_config_entry(hass):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
3,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -244,7 +244,7 @@ async def test_services_config_entry(hass):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
4,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -272,7 +272,7 @@ async def test_services_config_entry(hass):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
5,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
@ -32,10 +32,10 @@ from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
UnitOfEnergy,
|
||||
)
|
||||
from homeassistant.core import CoreState, State
|
||||
from homeassistant.helpers import entity_registry
|
||||
@ -105,7 +105,7 @@ async def test_state(hass, yaml_config, config_entry_config):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id, 2, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id, 2, {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -113,26 +113,26 @@ async def test_state(hass, yaml_config, config_entry_config):
|
||||
assert state is not None
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get("status") == COLLECTING
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
state = hass.states.get("sensor.energy_bill_midpeak")
|
||||
assert state is not None
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get("status") == PAUSED
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
state = hass.states.get("sensor.energy_bill_offpeak")
|
||||
assert state is not None
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get("status") == PAUSED
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
3,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -166,7 +166,7 @@ async def test_state(hass, yaml_config, config_entry_config):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
6,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -210,7 +210,7 @@ async def test_state(hass, yaml_config, config_entry_config):
|
||||
|
||||
# test invalid state
|
||||
hass.states.async_set(
|
||||
entity_id, "*", {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id, "*", {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.energy_bill_midpeak")
|
||||
@ -219,7 +219,9 @@ async def test_state(hass, yaml_config, config_entry_config):
|
||||
|
||||
# test unavailable source
|
||||
hass.states.async_set(
|
||||
entity_id, STATE_UNAVAILABLE, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id,
|
||||
STATE_UNAVAILABLE,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.energy_bill_midpeak")
|
||||
@ -306,7 +308,7 @@ async def test_init(hass, yaml_config, config_entry_config):
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id, 2, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id, 2, {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -314,12 +316,12 @@ async def test_init(hass, yaml_config, config_entry_config):
|
||||
state = hass.states.get("sensor.energy_bill_onpeak")
|
||||
assert state is not None
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
state = hass.states.get("sensor.energy_bill_offpeak")
|
||||
assert state is not None
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
@ -467,7 +469,7 @@ async def test_device_class(hass, yaml_config, config_entry_configs):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id_energy, 2, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id_energy, 2, {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
hass.states.async_set(
|
||||
entity_id_gas, 2, {ATTR_UNIT_OF_MEASUREMENT: "some_archaic_unit"}
|
||||
@ -479,7 +481,7 @@ async def test_device_class(hass, yaml_config, config_entry_configs):
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) is SensorDeviceClass.ENERGY.value
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.TOTAL
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
state = hass.states.get("sensor.gas_meter")
|
||||
assert state is not None
|
||||
@ -534,7 +536,7 @@ async def test_restore_state(hass, yaml_config, config_entry_config):
|
||||
attributes={
|
||||
ATTR_STATUS: PAUSED,
|
||||
ATTR_LAST_RESET: last_reset,
|
||||
ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR,
|
||||
},
|
||||
),
|
||||
{
|
||||
@ -555,7 +557,7 @@ async def test_restore_state(hass, yaml_config, config_entry_config):
|
||||
attributes={
|
||||
ATTR_STATUS: PAUSED,
|
||||
ATTR_LAST_RESET: last_reset,
|
||||
ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR,
|
||||
},
|
||||
),
|
||||
{
|
||||
@ -573,7 +575,7 @@ async def test_restore_state(hass, yaml_config, config_entry_config):
|
||||
attributes={
|
||||
ATTR_STATUS: COLLECTING,
|
||||
ATTR_LAST_RESET: last_reset,
|
||||
ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR,
|
||||
},
|
||||
),
|
||||
{
|
||||
@ -591,7 +593,7 @@ async def test_restore_state(hass, yaml_config, config_entry_config):
|
||||
attributes={
|
||||
ATTR_STATUS: COLLECTING,
|
||||
ATTR_LAST_RESET: last_reset,
|
||||
ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR,
|
||||
},
|
||||
),
|
||||
{},
|
||||
@ -618,7 +620,7 @@ async def test_restore_state(hass, yaml_config, config_entry_config):
|
||||
assert state.state == "3"
|
||||
assert state.attributes.get("status") == PAUSED
|
||||
assert state.attributes.get("last_reset") == last_reset
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
state = hass.states.get("sensor.energy_bill_midpeak")
|
||||
assert state.state == "5"
|
||||
@ -627,7 +629,7 @@ async def test_restore_state(hass, yaml_config, config_entry_config):
|
||||
assert state.state == "6"
|
||||
assert state.attributes.get("status") == COLLECTING
|
||||
assert state.attributes.get("last_reset") == last_reset
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
state = hass.states.get("sensor.energy_bill_superpeak")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
@ -694,7 +696,7 @@ async def test_net_consumption(hass, yaml_config, config_entry_config):
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
hass.states.async_set(
|
||||
entity_id, 2, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id, 2, {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -703,7 +705,7 @@ async def test_net_consumption(hass, yaml_config, config_entry_config):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
1,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -762,7 +764,7 @@ async def test_non_net_consumption(hass, yaml_config, config_entry_config, caplo
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
hass.states.async_set(
|
||||
entity_id, 2, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id, 2, {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -771,7 +773,7 @@ async def test_non_net_consumption(hass, yaml_config, config_entry_config, caplo
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
1,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -781,7 +783,7 @@ async def test_non_net_consumption(hass, yaml_config, config_entry_config, caplo
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
None,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -848,7 +850,7 @@ async def test_delta_values(hass, yaml_config, config_entry_config, caplog):
|
||||
|
||||
async_fire_time_changed(hass, now)
|
||||
hass.states.async_set(
|
||||
entity_id, 1, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id, 1, {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -861,7 +863,7 @@ async def test_delta_values(hass, yaml_config, config_entry_config, caplog):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
None,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -873,7 +875,7 @@ async def test_delta_values(hass, yaml_config, config_entry_config, caplog):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
3,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -888,7 +890,7 @@ async def test_delta_values(hass, yaml_config, config_entry_config, caplog):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
6,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -925,7 +927,7 @@ async def _test_self_reset(hass, config, start_time, expect_reset=True):
|
||||
|
||||
async_fire_time_changed(hass, now)
|
||||
hass.states.async_set(
|
||||
entity_id, 1, {ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR}
|
||||
entity_id, 1, {ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -935,7 +937,7 @@ async def _test_self_reset(hass, config, start_time, expect_reset=True):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
3,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -947,7 +949,7 @@ async def _test_self_reset(hass, config, start_time, expect_reset=True):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
6,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -978,7 +980,7 @@ async def _test_self_reset(hass, config, start_time, expect_reset=True):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
10,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR},
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR},
|
||||
force_update=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
Loading…
x
Reference in New Issue
Block a user