Add and use percentage constant (#32094)
* Add and use percentage constant * Fix pylint error and broken test
This commit is contained in:
1 parent
c7f128f286
commit
f1a0ca7cd3
155 files changed
+735
-459
No files matched your search
@@ -9,6 +9,7 @@ from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
|
||||
|
||||
@@ -168,7 +169,7 @@ def test_sensor_icon(temperature_sensor):
|
||||
def test_unit_of_measure(default_sensor, battery_sensor):
|
||||
"""Test the unit_of_measurement property."""
|
||||
assert default_sensor.unit_of_measurement is None
|
||||
assert battery_sensor.unit_of_measurement == "%"
|
||||
assert battery_sensor.unit_of_measurement == UNIT_PERCENTAGE
|
||||
|
||||
|
||||
def test_device_class(default_sensor, temperature_sensor, humidity_sensor):
|
||||
|
||||
@@ -23,6 +23,7 @@ from homeassistant.const import (
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_UNAVAILABLE,
|
||||
TEMP_CELSIUS,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import parse_datetime, utcnow
|
||||
@@ -156,7 +157,7 @@ async def test_awair_score(hass):
|
||||
sensor = hass.states.get("sensor.awair_score")
|
||||
assert sensor.state == "78"
|
||||
assert sensor.attributes["device_class"] == DEVICE_CLASS_SCORE
|
||||
assert sensor.attributes["unit_of_measurement"] == "%"
|
||||
assert sensor.attributes["unit_of_measurement"] == UNIT_PERCENTAGE
|
||||
|
||||
|
||||
async def test_awair_temp(hass):
|
||||
@@ -176,7 +177,7 @@ async def test_awair_humid(hass):
|
||||
sensor = hass.states.get("sensor.awair_humidity")
|
||||
assert sensor.state == "32.7"
|
||||
assert sensor.attributes["device_class"] == DEVICE_CLASS_HUMIDITY
|
||||
assert sensor.attributes["unit_of_measurement"] == "%"
|
||||
assert sensor.attributes["unit_of_measurement"] == UNIT_PERCENTAGE
|
||||
|
||||
|
||||
async def test_awair_co2(hass):
|
||||
|
||||
@@ -12,6 +12,7 @@ from homeassistant.components.canary.sensor import (
|
||||
STATE_AIR_QUALITY_VERY_ABNORMAL,
|
||||
CanarySensor,
|
||||
)
|
||||
from homeassistant.const import UNIT_PERCENTAGE
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
from tests.components.canary.test_init import mock_device, mock_location
|
||||
@@ -97,7 +98,7 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||
sensor.update()
|
||||
|
||||
assert "Home Family Room Humidity" == sensor.name
|
||||
assert "%" == sensor.unit_of_measurement
|
||||
assert UNIT_PERCENTAGE == sensor.unit_of_measurement
|
||||
assert 50.46 == sensor.state
|
||||
assert "mdi:water-percent" == sensor.icon
|
||||
|
||||
@@ -184,7 +185,7 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||
sensor.update()
|
||||
|
||||
assert "Home Family Room Battery" == sensor.name
|
||||
assert "%" == sensor.unit_of_measurement
|
||||
assert UNIT_PERCENTAGE == sensor.unit_of_measurement
|
||||
assert 70.46 == sensor.state
|
||||
assert "mdi:battery-70" == sensor.icon
|
||||
|
||||
|
||||
@@ -8,7 +8,13 @@ from libpurecool.dyson_pure_cool_link import DysonPureCoolLink
|
||||
|
||||
from homeassistant.components import dyson as dyson_parent
|
||||
from homeassistant.components.dyson import sensor as dyson
|
||||
from homeassistant.const import STATE_OFF, TEMP_CELSIUS, TEMP_FAHRENHEIT, TIME_HOURS
|
||||
from homeassistant.const import (
|
||||
STATE_OFF,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
TIME_HOURS,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@@ -169,7 +175,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 == "%"
|
||||
assert sensor.unit_of_measurement == UNIT_PERCENTAGE
|
||||
assert sensor.name == "Device_name Humidity"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
@@ -180,7 +186,7 @@ class DysonTest(unittest.TestCase):
|
||||
sensor.entity_id = "sensor.dyson_1"
|
||||
assert not sensor.should_poll
|
||||
assert sensor.state == 45
|
||||
assert sensor.unit_of_measurement == "%"
|
||||
assert sensor.unit_of_measurement == UNIT_PERCENTAGE
|
||||
assert sensor.name == "Device_name Humidity"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
@@ -191,7 +197,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 == "%"
|
||||
assert sensor.unit_of_measurement == UNIT_PERCENTAGE
|
||||
assert sensor.name == "Device_name Humidity"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
TEMP_CELSIUS,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.setup import async_setup_component
|
||||
@@ -40,10 +41,10 @@ async def test_default_setup(hass, aioclient_mock):
|
||||
metrics = {
|
||||
"co2": ["1232.0", CONCENTRATION_PARTS_PER_MILLION],
|
||||
"temperature": ["21.1", TEMP_CELSIUS],
|
||||
"humidity": ["49.5", "%"],
|
||||
"humidity": ["49.5", UNIT_PERCENTAGE],
|
||||
"pm2_5": ["144.8", CONCENTRATION_MICROGRAMS_PER_CUBIC_METER],
|
||||
"voc": ["340.7", CONCENTRATION_PARTS_PER_BILLION],
|
||||
"index": ["138.9", "%"],
|
||||
"index": ["138.9", UNIT_PERCENTAGE],
|
||||
}
|
||||
|
||||
for name, value in metrics.items():
|
||||
|
||||
@@ -26,6 +26,7 @@ from homeassistant.const import (
|
||||
CONF_TYPE,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.core import State
|
||||
|
||||
@@ -180,7 +181,7 @@ def test_type_media_player(type_name, entity_id, state, attrs, config):
|
||||
"HumiditySensor",
|
||||
"sensor.humidity",
|
||||
"20",
|
||||
{ATTR_DEVICE_CLASS: "humidity", ATTR_UNIT_OF_MEASUREMENT: "%"},
|
||||
{ATTR_DEVICE_CLASS: "humidity", ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE},
|
||||
),
|
||||
("LightSensor", "sensor.light", "900", {ATTR_DEVICE_CLASS: "illuminance"}),
|
||||
("LightSensor", "sensor.light", "900", {ATTR_UNIT_OF_MEASUREMENT: "lm"}),
|
||||
|
||||
@@ -21,6 +21,7 @@ from homeassistant.const import (
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.core import CoreState
|
||||
from homeassistant.helpers import entity_registry
|
||||
@@ -127,7 +128,7 @@ async def test_light_brightness(hass, hk_driver, cls, events):
|
||||
assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
|
||||
assert call_turn_on[0].data[ATTR_BRIGHTNESS_PCT] == 20
|
||||
assert len(events) == 1
|
||||
assert events[-1].data[ATTR_VALUE] == "brightness at 20%"
|
||||
assert events[-1].data[ATTR_VALUE] == f"brightness at 20{UNIT_PERCENTAGE}"
|
||||
|
||||
await hass.async_add_job(acc.char_on.client_update_value, 1)
|
||||
await hass.async_add_job(acc.char_brightness.client_update_value, 40)
|
||||
@@ -136,7 +137,7 @@ async def test_light_brightness(hass, hk_driver, cls, events):
|
||||
assert call_turn_on[1].data[ATTR_ENTITY_ID] == entity_id
|
||||
assert call_turn_on[1].data[ATTR_BRIGHTNESS_PCT] == 40
|
||||
assert len(events) == 2
|
||||
assert events[-1].data[ATTR_VALUE] == "brightness at 40%"
|
||||
assert events[-1].data[ATTR_VALUE] == f"brightness at 40{UNIT_PERCENTAGE}"
|
||||
|
||||
await hass.async_add_job(acc.char_on.client_update_value, 1)
|
||||
await hass.async_add_job(acc.char_brightness.client_update_value, 0)
|
||||
@@ -235,9 +236,7 @@ async def test_light_restore(hass, hk_driver, cls, events):
|
||||
|
||||
registry = await entity_registry.async_get_registry(hass)
|
||||
|
||||
registry.async_get_or_create(
|
||||
"light", "hue", "1234", suggested_object_id="simple",
|
||||
)
|
||||
registry.async_get_or_create("light", "hue", "1234", suggested_object_id="simple")
|
||||
registry.async_get_or_create(
|
||||
"light",
|
||||
"hue",
|
||||
|
||||
@@ -26,6 +26,7 @@ from homeassistant.const import (
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.core import CoreState
|
||||
from homeassistant.helpers import entity_registry
|
||||
@@ -287,7 +288,7 @@ async def test_sensor_restore(hass, hk_driver, events):
|
||||
"12345",
|
||||
suggested_object_id="humidity",
|
||||
device_class="humidity",
|
||||
unit_of_measurement="%",
|
||||
unit_of_measurement=UNIT_PERCENTAGE,
|
||||
)
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -27,6 +27,7 @@ from homeassistant.const import (
|
||||
POWER_WATT,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@@ -55,7 +56,7 @@ async def test_hmip_accesspoint_status(hass, default_mock_hap_factory):
|
||||
)
|
||||
assert hmip_device
|
||||
assert ha_state.state == "8.0"
|
||||
assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "%"
|
||||
assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UNIT_PERCENTAGE
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "dutyCycle", 17.3)
|
||||
|
||||
@@ -77,7 +78,7 @@ async def test_hmip_heating_thermostat(hass, default_mock_hap_factory):
|
||||
)
|
||||
|
||||
assert ha_state.state == "0"
|
||||
assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "%"
|
||||
assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UNIT_PERCENTAGE
|
||||
await async_manipulate_test_data(hass, hmip_device, "valvePosition", 0.37)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == "37"
|
||||
@@ -111,7 +112,7 @@ async def test_hmip_humidity_sensor(hass, default_mock_hap_factory):
|
||||
)
|
||||
|
||||
assert ha_state.state == "40"
|
||||
assert ha_state.attributes["unit_of_measurement"] == "%"
|
||||
assert ha_state.attributes["unit_of_measurement"] == UNIT_PERCENTAGE
|
||||
await async_manipulate_test_data(hass, hmip_device, "humidity", 45)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == "45"
|
||||
|
||||
@@ -4,7 +4,13 @@ import unittest
|
||||
from unittest import mock
|
||||
|
||||
import homeassistant.components.influxdb as influxdb
|
||||
from homeassistant.const import EVENT_STATE_CHANGED, STATE_OFF, STATE_ON, STATE_STANDBY
|
||||
from homeassistant.const import (
|
||||
EVENT_STATE_CHANGED,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_STANDBY,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
@@ -102,7 +108,7 @@ class TestInfluxDB(unittest.TestCase):
|
||||
"unit_of_measurement": "foobars",
|
||||
"longitude": "1.1",
|
||||
"latitude": "2.2",
|
||||
"battery_level": "99%",
|
||||
"battery_level": f"99{UNIT_PERCENTAGE}",
|
||||
"temperature": "20c",
|
||||
"last_seen": "Last seen 23 minutes ago",
|
||||
"updated_at": datetime.datetime(2017, 1, 1, 0, 0),
|
||||
@@ -124,7 +130,7 @@ class TestInfluxDB(unittest.TestCase):
|
||||
"fields": {
|
||||
"longitude": 1.1,
|
||||
"latitude": 2.2,
|
||||
"battery_level_str": "99%",
|
||||
"battery_level_str": f"99{UNIT_PERCENTAGE}",
|
||||
"battery_level": 99.0,
|
||||
"temperature_str": "20c",
|
||||
"temperature": 20.0,
|
||||
|
||||
@@ -7,6 +7,7 @@ from homeassistant.const import (
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
@@ -233,7 +234,7 @@ class TestMinMaxSensor(unittest.TestCase):
|
||||
assert "ERR" == state.attributes.get("unit_of_measurement")
|
||||
|
||||
self.hass.states.set(
|
||||
entity_ids[2], self.values[2], {ATTR_UNIT_OF_MEASUREMENT: "%"}
|
||||
entity_ids[2], self.values[2], {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE}
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.const import UNIT_PERCENTAGE
|
||||
from homeassistant.helpers import device_registry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -24,7 +25,7 @@ async def test_sensor(hass, create_registrations, webhook_client):
|
||||
"state": 100,
|
||||
"type": "sensor",
|
||||
"unique_id": "battery_state",
|
||||
"unit_of_measurement": "%",
|
||||
"unit_of_measurement": UNIT_PERCENTAGE,
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -40,7 +41,7 @@ async def test_sensor(hass, create_registrations, webhook_client):
|
||||
|
||||
assert entity.attributes["device_class"] == "battery"
|
||||
assert entity.attributes["icon"] == "mdi:battery"
|
||||
assert entity.attributes["unit_of_measurement"] == "%"
|
||||
assert entity.attributes["unit_of_measurement"] == UNIT_PERCENTAGE
|
||||
assert entity.attributes["foo"] == "bar"
|
||||
assert entity.domain == "sensor"
|
||||
assert entity.name == "Test 1 Battery State"
|
||||
@@ -104,7 +105,7 @@ async def test_sensor_id_no_dupes(hass, create_registrations, webhook_client):
|
||||
"state": 100,
|
||||
"type": "sensor",
|
||||
"unique_id": "battery_state",
|
||||
"unit_of_measurement": "%",
|
||||
"unit_of_measurement": UNIT_PERCENTAGE,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,12 @@ from homeassistant.components.mold_indicator.sensor import (
|
||||
ATTR_DEWPOINT,
|
||||
)
|
||||
import homeassistant.components.sensor as sensor
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, STATE_UNKNOWN, TEMP_CELSIUS
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
@@ -25,7 +30,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
|
||||
"test.outdoortemp", "10", {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
)
|
||||
self.hass.states.set(
|
||||
"test.indoorhumidity", "50", {ATTR_UNIT_OF_MEASUREMENT: "%"}
|
||||
"test.indoorhumidity", "50", {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE}
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
@@ -50,7 +55,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
|
||||
|
||||
moldind = self.hass.states.get("sensor.mold_indicator")
|
||||
assert moldind
|
||||
assert "%" == moldind.attributes.get("unit_of_measurement")
|
||||
assert UNIT_PERCENTAGE == moldind.attributes.get("unit_of_measurement")
|
||||
|
||||
def test_invalidcalib(self):
|
||||
"""Test invalid sensor values."""
|
||||
@@ -61,7 +66,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
|
||||
"test.outdoortemp", "10", {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
)
|
||||
self.hass.states.set(
|
||||
"test.indoorhumidity", "0", {ATTR_UNIT_OF_MEASUREMENT: "%"}
|
||||
"test.indoorhumidity", "0", {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE}
|
||||
)
|
||||
|
||||
assert setup_component(
|
||||
@@ -94,7 +99,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
|
||||
"test.outdoortemp", "10", {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
)
|
||||
self.hass.states.set(
|
||||
"test.indoorhumidity", "-1", {ATTR_UNIT_OF_MEASUREMENT: "%"}
|
||||
"test.indoorhumidity", "-1", {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE}
|
||||
)
|
||||
|
||||
assert setup_component(
|
||||
@@ -120,7 +125,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
|
||||
assert moldind.attributes.get(ATTR_CRITICAL_TEMP) is None
|
||||
|
||||
self.hass.states.set(
|
||||
"test.indoorhumidity", "A", {ATTR_UNIT_OF_MEASUREMENT: "%"}
|
||||
"test.indoorhumidity", "A", {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE}
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
moldind = self.hass.states.get("sensor.mold_indicator")
|
||||
@@ -220,7 +225,9 @@ class TestSensorMoldIndicator(unittest.TestCase):
|
||||
"test.outdoortemp", "25", {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
|
||||
)
|
||||
self.hass.states.set(
|
||||
"test.indoorhumidity", STATE_UNKNOWN, {ATTR_UNIT_OF_MEASUREMENT: "%"}
|
||||
"test.indoorhumidity",
|
||||
STATE_UNKNOWN,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE},
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
moldind = self.hass.states.get("sensor.mold_indicator")
|
||||
@@ -230,7 +237,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
|
||||
assert moldind.attributes.get(ATTR_CRITICAL_TEMP) is None
|
||||
|
||||
self.hass.states.set(
|
||||
"test.indoorhumidity", "20", {ATTR_UNIT_OF_MEASUREMENT: "%"}
|
||||
"test.indoorhumidity", "20", {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE}
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
moldind = self.hass.states.get("sensor.mold_indicator")
|
||||
@@ -276,7 +283,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
|
||||
assert self.hass.states.get("sensor.mold_indicator").state == "57"
|
||||
|
||||
self.hass.states.set(
|
||||
"test.indoorhumidity", "20", {ATTR_UNIT_OF_MEASUREMENT: "%"}
|
||||
"test.indoorhumidity", "20", {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE}
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
assert self.hass.states.get("sensor.mold_indicator").state == "23"
|
||||
@@ -12,7 +12,7 @@ from homeassistant.components.rflink import (
|
||||
EVENT_KEY_SENSOR,
|
||||
TMP_ENTITY,
|
||||
)
|
||||
from homeassistant.const import STATE_UNKNOWN
|
||||
from homeassistant.const import STATE_UNKNOWN, UNIT_PERCENTAGE
|
||||
|
||||
from tests.components.rflink.test_init import mock_rflink
|
||||
|
||||
@@ -141,7 +141,12 @@ async def test_aliases(hass, monkeypatch):
|
||||
|
||||
# test event for config sensor
|
||||
event_callback(
|
||||
{"id": "test_alias_02_0", "sensor": "humidity", "value": 65, "unit": "%"}
|
||||
{
|
||||
"id": "test_alias_02_0",
|
||||
"sensor": "humidity",
|
||||
"value": 65,
|
||||
"unit": UNIT_PERCENTAGE,
|
||||
}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -149,7 +154,7 @@ async def test_aliases(hass, monkeypatch):
|
||||
updated_sensor = hass.states.get("sensor.test_02")
|
||||
assert updated_sensor
|
||||
assert updated_sensor.state == "65"
|
||||
assert updated_sensor.attributes["unit_of_measurement"] == "%"
|
||||
assert updated_sensor.attributes["unit_of_measurement"] == UNIT_PERCENTAGE
|
||||
|
||||
|
||||
async def test_race_condition(hass, monkeypatch):
|
||||
|
||||
@@ -4,7 +4,7 @@ import unittest
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import rfxtrx as rfxtrx_core
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_component
|
||||
@@ -137,7 +137,7 @@ class TestSensorRfxtrx(unittest.TestCase):
|
||||
assert len(rfxtrx_core.RFX_DEVICES[id]) == 2
|
||||
_entity_temp = rfxtrx_core.RFX_DEVICES[id]["Temperature"]
|
||||
_entity_hum = rfxtrx_core.RFX_DEVICES[id]["Humidity"]
|
||||
assert "%" == _entity_hum.unit_of_measurement
|
||||
assert UNIT_PERCENTAGE == _entity_hum.unit_of_measurement
|
||||
assert "Bath" == _entity_hum.__str__()
|
||||
assert _entity_hum.state is None
|
||||
assert TEMP_CELSIUS == _entity_temp.unit_of_measurement
|
||||
@@ -271,7 +271,7 @@ class TestSensorRfxtrx(unittest.TestCase):
|
||||
assert len(rfxtrx_core.RFX_DEVICES[id]) == 2
|
||||
_entity_temp = rfxtrx_core.RFX_DEVICES[id]["Temperature"]
|
||||
_entity_hum = rfxtrx_core.RFX_DEVICES[id]["Humidity"]
|
||||
assert "%" == _entity_hum.unit_of_measurement
|
||||
assert UNIT_PERCENTAGE == _entity_hum.unit_of_measurement
|
||||
assert "Bath" == _entity_hum.__str__()
|
||||
assert _entity_temp.state is None
|
||||
assert TEMP_CELSIUS == _entity_temp.unit_of_measurement
|
||||
@@ -303,7 +303,7 @@ class TestSensorRfxtrx(unittest.TestCase):
|
||||
assert len(rfxtrx_core.RFX_DEVICES[id]) == 2
|
||||
_entity_temp = rfxtrx_core.RFX_DEVICES[id]["Temperature"]
|
||||
_entity_hum = rfxtrx_core.RFX_DEVICES[id]["Humidity"]
|
||||
assert "%" == _entity_hum.unit_of_measurement
|
||||
assert UNIT_PERCENTAGE == _entity_hum.unit_of_measurement
|
||||
assert 15 == _entity_hum.state
|
||||
assert {
|
||||
"Battery numeric": 9,
|
||||
|
||||
@@ -4,7 +4,7 @@ import pytest
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.components.sensor.device_condition import ENTITY_CONDITIONS
|
||||
from homeassistant.const import CONF_PLATFORM, STATE_UNKNOWN
|
||||
from homeassistant.const import CONF_PLATFORM, STATE_UNKNOWN, UNIT_PERCENTAGE
|
||||
from homeassistant.helpers import device_registry
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@@ -97,13 +97,13 @@ async def test_get_condition_capabilities(hass, device_reg, entity_reg):
|
||||
expected_capabilities = {
|
||||
"extra_fields": [
|
||||
{
|
||||
"description": {"suffix": "%"},
|
||||
"description": {"suffix": UNIT_PERCENTAGE},
|
||||
"name": "above",
|
||||
"optional": True,
|
||||
"type": "float",
|
||||
},
|
||||
{
|
||||
"description": {"suffix": "%"},
|
||||
"description": {"suffix": UNIT_PERCENTAGE},
|
||||
"name": "below",
|
||||
"optional": True,
|
||||
"type": "float",
|
||||
|
||||
@@ -6,7 +6,7 @@ import pytest
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.components.sensor.device_trigger import ENTITY_TRIGGERS
|
||||
from homeassistant.const import CONF_PLATFORM, STATE_UNKNOWN
|
||||
from homeassistant.const import CONF_PLATFORM, STATE_UNKNOWN, UNIT_PERCENTAGE
|
||||
from homeassistant.helpers import device_registry
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
@@ -102,13 +102,13 @@ async def test_get_trigger_capabilities(hass, device_reg, entity_reg):
|
||||
expected_capabilities = {
|
||||
"extra_fields": [
|
||||
{
|
||||
"description": {"suffix": "%"},
|
||||
"description": {"suffix": UNIT_PERCENTAGE},
|
||||
"name": "above",
|
||||
"optional": True,
|
||||
"type": "float",
|
||||
},
|
||||
{
|
||||
"description": {"suffix": "%"},
|
||||
"description": {"suffix": UNIT_PERCENTAGE},
|
||||
"name": "below",
|
||||
"optional": True,
|
||||
"type": "float",
|
||||
|
||||
@@ -13,6 +13,7 @@ from homeassistant.const import (
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
STATE_UNKNOWN,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
@@ -37,7 +38,7 @@ async def test_entity_state(hass, device_factory):
|
||||
await setup_platform(hass, SENSOR_DOMAIN, devices=[device])
|
||||
state = hass.states.get("sensor.sensor_1_battery")
|
||||
assert state.state == "100"
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "%"
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UNIT_PERCENTAGE
|
||||
assert state.attributes[ATTR_FRIENDLY_NAME] == device.label + " Battery"
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import unittest
|
||||
import pytest
|
||||
|
||||
import homeassistant.components.sonarr.sensor as sonarr
|
||||
from homeassistant.const import DATA_GIGABYTES
|
||||
from homeassistant.const import DATA_GIGABYTES, UNIT_PERCENTAGE
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
@@ -569,7 +569,10 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
assert "mdi:download" == device.icon
|
||||
assert "Episodes" == device.unit_of_measurement
|
||||
assert "Sonarr Queue" == device.name
|
||||
assert "100.00%" == device.device_state_attributes["Game of Thrones S03E08"]
|
||||
assert (
|
||||
f"100.00{UNIT_PERCENTAGE}"
|
||||
== device.device_state_attributes["Game of Thrones S03E08"]
|
||||
)
|
||||
|
||||
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
|
||||
def test_series(self, req_mock):
|
||||
|
||||
@@ -5,6 +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.setup import async_setup_component
|
||||
|
||||
from tests.common import mock_coro
|
||||
@@ -62,7 +63,9 @@ SENSOR_OUTPUT = {
|
||||
{"location": "Home", "name": "temp1", "unit": "°C", "value": "25"},
|
||||
{"location": "Home", "name": "temp2", "unit": "°C", "value": "23"},
|
||||
],
|
||||
"humidity": [{"location": "Home", "name": "hum1", "unit": "%", "value": "88"}],
|
||||
"humidity": [
|
||||
{"location": "Home", "name": "hum1", "unit": UNIT_PERCENTAGE, "value": "88"}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +77,9 @@ def mock_client(hass, hass_client):
|
||||
|
||||
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.hum1", 88, attributes={"unit_of_measurement": "%"})
|
||||
hass.states.async_set(
|
||||
"test.hum1", 88, attributes={"unit_of_measurement": UNIT_PERCENTAGE}
|
||||
)
|
||||
|
||||
return hass.loop.run_until_complete(hass_client())
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for the Start.ca sensor platform."""
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.startca.sensor import StartcaData
|
||||
from homeassistant.const import DATA_GIGABYTES
|
||||
from homeassistant.const import DATA_GIGABYTES, UNIT_PERCENTAGE
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ async def test_capped_setup(hass, aioclient_mock):
|
||||
await async_setup_component(hass, "sensor", {"sensor": config})
|
||||
|
||||
state = hass.states.get("sensor.start_ca_usage_ratio")
|
||||
assert state.attributes.get("unit_of_measurement") == "%"
|
||||
assert state.attributes.get("unit_of_measurement") == UNIT_PERCENTAGE
|
||||
assert state.state == "76.24"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_usage")
|
||||
@@ -147,7 +147,7 @@ async def test_unlimited_setup(hass, aioclient_mock):
|
||||
await async_setup_component(hass, "sensor", {"sensor": config})
|
||||
|
||||
state = hass.states.get("sensor.start_ca_usage_ratio")
|
||||
assert state.attributes.get("unit_of_measurement") == "%"
|
||||
assert state.attributes.get("unit_of_measurement") == UNIT_PERCENTAGE
|
||||
assert state.state == "0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_usage")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for the TekSavvy sensor platform."""
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.teksavvy.sensor import TekSavvyData
|
||||
from homeassistant.const import DATA_GIGABYTES
|
||||
from homeassistant.const import DATA_GIGABYTES, UNIT_PERCENTAGE
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ async def test_capped_setup(hass, aioclient_mock):
|
||||
assert state.state == "235.57"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_usage_ratio")
|
||||
assert state.attributes.get("unit_of_measurement") == "%"
|
||||
assert state.attributes.get("unit_of_measurement") == UNIT_PERCENTAGE
|
||||
assert state.state == "56.69"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_usage")
|
||||
@@ -159,7 +159,7 @@ async def test_unlimited_setup(hass, aioclient_mock):
|
||||
assert state.state == "226.75"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_usage_ratio")
|
||||
assert state.attributes.get("unit_of_measurement") == "%"
|
||||
assert state.attributes.get("unit_of_measurement") == UNIT_PERCENTAGE
|
||||
assert state.state == "0"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_remaining")
|
||||
|
||||
@@ -13,6 +13,7 @@ from pyvera import (
|
||||
VeraSensor,
|
||||
)
|
||||
|
||||
from homeassistant.const import UNIT_PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import ComponentFactory
|
||||
@@ -64,7 +65,7 @@ async def test_temperature_sensor_f(
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_TEMPERATURE_SENSOR,
|
||||
class_property="temperature",
|
||||
assert_states=(("33", "1"), ("44", "7"),),
|
||||
assert_states=(("33", "1"), ("44", "7")),
|
||||
setup_callback=setup_callback,
|
||||
)
|
||||
|
||||
@@ -78,7 +79,7 @@ async def test_temperature_sensor_c(
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_TEMPERATURE_SENSOR,
|
||||
class_property="temperature",
|
||||
assert_states=(("33", "33"), ("44", "44"),),
|
||||
assert_states=(("33", "33"), ("44", "44")),
|
||||
)
|
||||
|
||||
|
||||
@@ -91,7 +92,7 @@ async def test_light_sensor(
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_LIGHT_SENSOR,
|
||||
class_property="light",
|
||||
assert_states=(("12", "12"), ("13", "13"),),
|
||||
assert_states=(("12", "12"), ("13", "13")),
|
||||
assert_unit_of_measurement="lx",
|
||||
)
|
||||
|
||||
@@ -105,7 +106,7 @@ async def test_uv_sensor(
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_UV_SENSOR,
|
||||
class_property="light",
|
||||
assert_states=(("12", "12"), ("13", "13"),),
|
||||
assert_states=(("12", "12"), ("13", "13")),
|
||||
assert_unit_of_measurement="level",
|
||||
)
|
||||
|
||||
@@ -119,8 +120,8 @@ async def test_humidity_sensor(
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_HUMIDITY_SENSOR,
|
||||
class_property="humidity",
|
||||
assert_states=(("12", "12"), ("13", "13"),),
|
||||
assert_unit_of_measurement="%",
|
||||
assert_states=(("12", "12"), ("13", "13")),
|
||||
assert_unit_of_measurement=UNIT_PERCENTAGE,
|
||||
)
|
||||
|
||||
|
||||
@@ -133,7 +134,7 @@ async def test_power_meter_sensor(
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=CATEGORY_POWER_METER,
|
||||
class_property="power",
|
||||
assert_states=(("12", "12"), ("13", "13"),),
|
||||
assert_states=(("12", "12"), ("13", "13")),
|
||||
assert_unit_of_measurement="watts",
|
||||
)
|
||||
|
||||
@@ -151,7 +152,7 @@ async def test_trippable_sensor(
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=999,
|
||||
class_property="is_tripped",
|
||||
assert_states=((True, "Tripped"), (False, "Not Tripped"), (True, "Tripped"),),
|
||||
assert_states=((True, "Tripped"), (False, "Not Tripped"), (True, "Tripped")),
|
||||
setup_callback=setup_callback,
|
||||
)
|
||||
|
||||
@@ -169,7 +170,7 @@ async def test_unknown_sensor(
|
||||
vera_component_factory=vera_component_factory,
|
||||
category=999,
|
||||
class_property="is_tripped",
|
||||
assert_states=((True, "Unknown"), (False, "Unknown"), (True, "Unknown"),),
|
||||
assert_states=((True, "Unknown"), (False, "Unknown"), (True, "Unknown")),
|
||||
setup_callback=setup_callback,
|
||||
)
|
||||
|
||||
@@ -187,7 +188,7 @@ async def test_scene_controller_sensor(
|
||||
entity_id = "sensor.dev1_1"
|
||||
|
||||
component_data = await vera_component_factory.configure_component(
|
||||
hass=hass, devices=(vera_device,),
|
||||
hass=hass, devices=(vera_device,)
|
||||
)
|
||||
controller = component_data.controller
|
||||
update_callback = controller.register.call_args_list[0][0][1]
|
||||
|
||||
@@ -3,7 +3,7 @@ from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.const import SPEED_METERS_PER_SECOND
|
||||
from homeassistant.const import SPEED_METERS_PER_SECOND, UNIT_PERCENTAGE
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import assert_setup_component, load_fixture
|
||||
@@ -63,11 +63,11 @@ async def test_custom_setup(hass, aioclient_mock):
|
||||
assert state.state == "103.6"
|
||||
|
||||
state = hass.states.get("sensor.yr_humidity")
|
||||
assert state.attributes.get("unit_of_measurement") == "%"
|
||||
assert state.attributes.get("unit_of_measurement") == UNIT_PERCENTAGE
|
||||
assert state.state == "55.5"
|
||||
|
||||
state = hass.states.get("sensor.yr_fog")
|
||||
assert state.attributes.get("unit_of_measurement") == "%"
|
||||
assert state.attributes.get("unit_of_measurement") == UNIT_PERCENTAGE
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.yr_wind_speed")
|
||||
@@ -109,11 +109,11 @@ async def test_forecast_setup(hass, aioclient_mock):
|
||||
assert state.state == "148.9"
|
||||
|
||||
state = hass.states.get("sensor.yr_humidity")
|
||||
assert state.attributes.get("unit_of_measurement") == "%"
|
||||
assert state.attributes.get("unit_of_measurement") == UNIT_PERCENTAGE
|
||||
assert state.state == "77.4"
|
||||
|
||||
state = hass.states.get("sensor.yr_fog")
|
||||
assert state.attributes.get("unit_of_measurement") == "%"
|
||||
assert state.attributes.get("unit_of_measurement") == UNIT_PERCENTAGE
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.yr_wind_speed")
|
||||
|
||||
@@ -19,6 +19,7 @@ from homeassistant.const import (
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
from homeassistant.helpers import restore_state
|
||||
from homeassistant.util import dt as dt_util
|
||||
@@ -35,7 +36,7 @@ from .common import (
|
||||
async def async_test_humidity(hass, cluster, entity_id):
|
||||
"""Test humidity sensor."""
|
||||
await send_attribute_report(hass, cluster, 0, 1000)
|
||||
assert_state(hass, entity_id, "10.0", "%")
|
||||
assert_state(hass, entity_id, "10.0", UNIT_PERCENTAGE)
|
||||
|
||||
|
||||
async def async_test_temperature(hass, cluster, entity_id):
|
||||
|
||||
@@ -151,12 +151,12 @@ def test_alarm_sensor_value_changed(mock_openzwave):
|
||||
node = MockNode(
|
||||
command_classes=[const.COMMAND_CLASS_ALARM, const.COMMAND_CLASS_SENSOR_ALARM]
|
||||
)
|
||||
value = MockValue(data=12.34, node=node, units="%")
|
||||
value = MockValue(data=12.34, node=node, units=homeassistant.const.UNIT_PERCENTAGE)
|
||||
values = MockEntityValues(primary=value)
|
||||
|
||||
device = sensor.get_device(node=node, values=values, node_config={})
|
||||
assert device.state == 12.34
|
||||
assert device.unit_of_measurement == "%"
|
||||
assert device.unit_of_measurement == homeassistant.const.UNIT_PERCENTAGE
|
||||
value.data = 45.67
|
||||
value_changed(value)
|
||||
assert device.state == 45.67
|
||||
Reference in new issue
Block a user