Add and use percentage constant (#32094)
* Add and use percentage constant * Fix pylint error and broken test
This commit is contained in:
parent
c7f128f286
commit
f1a0ca7cd3
155 changed files with 735 additions and 459 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue