Use more state attribute name constants (#40428)

This commit is contained in:
Ville Skyttä 2020-09-22 00:03:39 +03:00 committed by GitHub
parent f78391ce2a
commit 5e90a4d000
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 231 additions and 156 deletions

View file

@ -5,6 +5,7 @@ import aiohttp
import pytest
from homeassistant import config_entries
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@ -250,7 +251,7 @@ async def test_reading_is_sampled(hass, mock_get_station):
state = hass.states.get("sensor.my_station_water_level_stage")
assert state.state == "5"
assert state.attributes["unit_of_measurement"] == "m"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "m"
async def test_multiple_readings_are_sampled(hass, mock_get_station):
@ -287,11 +288,11 @@ async def test_multiple_readings_are_sampled(hass, mock_get_station):
state = hass.states.get("sensor.my_station_water_level_stage")
assert state.state == "5"
assert state.attributes["unit_of_measurement"] == "m"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "m"
state = hass.states.get("sensor.my_station_water_level_second_stage")
assert state.state == "4"
assert state.attributes["unit_of_measurement"] == "m"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "m"
async def test_ignore_no_latest_reading(hass, mock_get_station):
@ -327,7 +328,7 @@ async def test_ignore_no_latest_reading(hass, mock_get_station):
state = hass.states.get("sensor.my_station_water_level_stage")
assert state.state == "5"
assert state.attributes["unit_of_measurement"] == "m"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "m"
state = hass.states.get("sensor.my_station_water_level_second_stage")
assert state is None
@ -357,7 +358,7 @@ async def test_mark_existing_as_unavailable_if_no_latest(hass, mock_get_station)
state = hass.states.get("sensor.my_station_water_level_stage")
assert state.state == "5"
assert state.attributes["unit_of_measurement"] == "m"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "m"
await poll(
{