Use UNIT_PERCENTAGE constant (#34054)

This commit is contained in:
springstan 2020-04-11 22:53:48 +02:00 committed by GitHub
parent 4f50b858d0
commit 9f713dac7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 19 deletions

View File

@ -311,8 +311,8 @@ GARMIN_ENTITY_LIST = {
], ],
"weight": ["Weight", "kg", "mdi:weight-kilogram", None, False], "weight": ["Weight", "kg", "mdi:weight-kilogram", None, False],
"bmi": ["BMI", "", "mdi:food", None, False], "bmi": ["BMI", "", "mdi:food", None, False],
"bodyFat": ["Body Fat", "%", "mdi:food", None, False], "bodyFat": ["Body Fat", UNIT_PERCENTAGE, "mdi:food", None, False],
"bodyWater": ["Body Water", "%", "mdi:water-percent", None, False], "bodyWater": ["Body Water", UNIT_PERCENTAGE, "mdi:water-percent", None, False],
"bodyMass": ["Body Mass", "kg", "mdi:food", None, False], "bodyMass": ["Body Mass", "kg", "mdi:food", None, False],
"muscleMass": ["Muscle Mass", "kg", "mdi:dumbbell", None, False], "muscleMass": ["Muscle Mass", "kg", "mdi:dumbbell", None, False],
"physiqueRating": ["Physique Rating", "", "mdi:numeric", None, False], "physiqueRating": ["Physique Rating", "", "mdi:numeric", None, False],

View File

@ -7,6 +7,7 @@ from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT, ATTR_UNIT_OF_MEASUREMENT,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
TEMP_CELSIUS, TEMP_CELSIUS,
UNIT_PERCENTAGE,
) )
from .common import setup_platform from .common import setup_platform
@ -31,7 +32,7 @@ async def test_attributes(hass):
assert not state.attributes.get("battery_low") assert not state.attributes.get("battery_low")
assert not state.attributes.get("no_response") assert not state.attributes.get("no_response")
assert state.attributes.get("device_type") == "LM" assert state.attributes.get("device_type") == "LM"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "%" assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PERCENTAGE
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Environment Sensor Humidity" assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Environment Sensor Humidity"
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_HUMIDITY assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_HUMIDITY

View File

@ -1,6 +1,6 @@
"""The sensor tests for the august platform.""" """The sensor tests for the august platform."""
from homeassistant.const import STATE_UNAVAILABLE from homeassistant.const import STATE_UNAVAILABLE, UNIT_PERCENTAGE
from tests.components.august.mocks import ( from tests.components.august.mocks import (
_create_august_with_devices, _create_august_with_devices,
@ -20,7 +20,10 @@ async def test_create_doorbell(hass):
"sensor.k98gidt45gul_name_battery" "sensor.k98gidt45gul_name_battery"
) )
assert sensor_k98gidt45gul_name_battery.state == "96" assert sensor_k98gidt45gul_name_battery.state == "96"
assert sensor_k98gidt45gul_name_battery.attributes["unit_of_measurement"] == "%" assert (
sensor_k98gidt45gul_name_battery.attributes["unit_of_measurement"]
== UNIT_PERCENTAGE
)
async def test_create_doorbell_offline(hass): async def test_create_doorbell_offline(hass):
@ -31,7 +34,9 @@ async def test_create_doorbell_offline(hass):
sensor_tmt100_name_battery = hass.states.get("sensor.tmt100_name_battery") sensor_tmt100_name_battery = hass.states.get("sensor.tmt100_name_battery")
assert sensor_tmt100_name_battery.state == "81" assert sensor_tmt100_name_battery.state == "81"
assert sensor_tmt100_name_battery.attributes["unit_of_measurement"] == "%" assert (
sensor_tmt100_name_battery.attributes["unit_of_measurement"] == UNIT_PERCENTAGE
)
entry = entity_registry.async_get("sensor.tmt100_name_battery") entry = entity_registry.async_get("sensor.tmt100_name_battery")
assert entry assert entry
@ -63,7 +68,7 @@ async def test_create_lock_with_linked_keypad(hass):
sensor_a6697750d607098bae8d6baa11ef8063_name_battery.attributes[ sensor_a6697750d607098bae8d6baa11ef8063_name_battery.attributes[
"unit_of_measurement" "unit_of_measurement"
] ]
== "%" == UNIT_PERCENTAGE
) )
entry = entity_registry.async_get( entry = entity_registry.async_get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery" "sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
@ -73,7 +78,7 @@ async def test_create_lock_with_linked_keypad(hass):
state = hass.states.get("sensor.front_door_lock_keypad_battery") state = hass.states.get("sensor.front_door_lock_keypad_battery")
assert state.state == "60" assert state.state == "60"
assert state.attributes["unit_of_measurement"] == "%" assert state.attributes["unit_of_measurement"] == UNIT_PERCENTAGE
entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery") entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery")
assert entry assert entry
assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery" assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery"
@ -93,7 +98,7 @@ async def test_create_lock_with_low_battery_linked_keypad(hass):
sensor_a6697750d607098bae8d6baa11ef8063_name_battery.attributes[ sensor_a6697750d607098bae8d6baa11ef8063_name_battery.attributes[
"unit_of_measurement" "unit_of_measurement"
] ]
== "%" == UNIT_PERCENTAGE
) )
entry = entity_registry.async_get( entry = entity_registry.async_get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery" "sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
@ -103,7 +108,7 @@ async def test_create_lock_with_low_battery_linked_keypad(hass):
state = hass.states.get("sensor.front_door_lock_keypad_battery") state = hass.states.get("sensor.front_door_lock_keypad_battery")
assert state.state == "10" assert state.state == "10"
assert state.attributes["unit_of_measurement"] == "%" assert state.attributes["unit_of_measurement"] == UNIT_PERCENTAGE
entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery") entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery")
assert entry assert entry
assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery" assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery"

View File

@ -1,6 +1,6 @@
"""The sensor tests for the nexia platform.""" """The sensor tests for the nexia platform."""
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE
from .util import async_init_integration from .util import async_init_integration
@ -69,7 +69,7 @@ async def test_create_sensors(hass):
expected_attributes = { expected_attributes = {
"attribution": "Data provided by mynexia.com", "attribution": "Data provided by mynexia.com",
"friendly_name": "Master Suite Current Compressor Speed", "friendly_name": "Master Suite Current Compressor Speed",
"unit_of_measurement": "%", "unit_of_measurement": UNIT_PERCENTAGE,
} }
# Only test for a subset of attributes in case # Only test for a subset of attributes in case
# HA changes the implementation and a new one appears # HA changes the implementation and a new one appears
@ -99,7 +99,7 @@ async def test_create_sensors(hass):
"attribution": "Data provided by mynexia.com", "attribution": "Data provided by mynexia.com",
"device_class": "humidity", "device_class": "humidity",
"friendly_name": "Master Suite Relative Humidity", "friendly_name": "Master Suite Relative Humidity",
"unit_of_measurement": "%", "unit_of_measurement": UNIT_PERCENTAGE,
} }
# Only test for a subset of attributes in case # Only test for a subset of attributes in case
# HA changes the implementation and a new one appears # HA changes the implementation and a new one appears
@ -113,7 +113,7 @@ async def test_create_sensors(hass):
expected_attributes = { expected_attributes = {
"attribution": "Data provided by mynexia.com", "attribution": "Data provided by mynexia.com",
"friendly_name": "Master Suite Requested Compressor Speed", "friendly_name": "Master Suite Requested Compressor Speed",
"unit_of_measurement": "%", "unit_of_measurement": UNIT_PERCENTAGE,
} }
# Only test for a subset of attributes in case # Only test for a subset of attributes in case
# HA changes the implementation and a new one appears # HA changes the implementation and a new one appears

View File

@ -1,5 +1,6 @@
"""The sensor tests for the nut platform.""" """The sensor tests for the nut platform."""
from homeassistant.const import UNIT_PERCENTAGE
from .util import async_init_integration from .util import async_init_integration
@ -16,7 +17,7 @@ async def test_pr3000rt2u(hass):
"device_class": "battery", "device_class": "battery",
"friendly_name": "Ups1 Battery Charge", "friendly_name": "Ups1 Battery Charge",
"state": "Online", "state": "Online",
"unit_of_measurement": "%", "unit_of_measurement": UNIT_PERCENTAGE,
} }
# Only test for a subset of attributes in case # Only test for a subset of attributes in case
# HA changes the implementation and a new one appears # HA changes the implementation and a new one appears
@ -37,7 +38,7 @@ async def test_cp1350c(hass):
"device_class": "battery", "device_class": "battery",
"friendly_name": "Ups1 Battery Charge", "friendly_name": "Ups1 Battery Charge",
"state": "Online", "state": "Online",
"unit_of_measurement": "%", "unit_of_measurement": UNIT_PERCENTAGE,
} }
# Only test for a subset of attributes in case # Only test for a subset of attributes in case
# HA changes the implementation and a new one appears # HA changes the implementation and a new one appears
@ -58,7 +59,7 @@ async def test_5e850i(hass):
"device_class": "battery", "device_class": "battery",
"friendly_name": "Ups1 Battery Charge", "friendly_name": "Ups1 Battery Charge",
"state": "Online", "state": "Online",
"unit_of_measurement": "%", "unit_of_measurement": UNIT_PERCENTAGE,
} }
# Only test for a subset of attributes in case # Only test for a subset of attributes in case
# HA changes the implementation and a new one appears # HA changes the implementation and a new one appears

View File

@ -3,6 +3,7 @@
from asynctest import patch from asynctest import patch
from homeassistant.components.powerwall.const import DOMAIN from homeassistant.components.powerwall.const import DOMAIN
from homeassistant.const import UNIT_PERCENTAGE
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .mocks import _mock_get_config, _mock_powerwall_with_fixtures from .mocks import _mock_get_config, _mock_powerwall_with_fixtures
@ -17,7 +18,7 @@ async def test_sensors(hass):
"homeassistant.components.powerwall.config_flow.PowerWall", "homeassistant.components.powerwall.config_flow.PowerWall",
return_value=mock_powerwall, return_value=mock_powerwall,
), patch( ), patch(
"homeassistant.components.powerwall.PowerWall", return_value=mock_powerwall, "homeassistant.components.powerwall.PowerWall", return_value=mock_powerwall
): ):
assert await async_setup_component(hass, DOMAIN, _mock_get_config()) assert await async_setup_component(hass, DOMAIN, _mock_get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
@ -99,7 +100,7 @@ async def test_sensors(hass):
state = hass.states.get("sensor.powerwall_charge") state = hass.states.get("sensor.powerwall_charge")
assert state.state == "47.32" assert state.state == "47.32"
expected_attributes = { expected_attributes = {
"unit_of_measurement": "%", "unit_of_measurement": UNIT_PERCENTAGE,
"friendly_name": "Powerwall Charge", "friendly_name": "Powerwall Charge",
"device_class": "battery", "device_class": "battery",
} }