mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Fix consider-using-dict-items warnings in tests (#119497)
This commit is contained in:
parent
cb39d2d16b
commit
99b349fa2c
@ -3986,7 +3986,7 @@ async def test_sensorstate(
|
||||
),
|
||||
}
|
||||
|
||||
for sensor_type in sensor_types:
|
||||
for sensor_type, item in sensor_types.items():
|
||||
assert helpers.get_google_type(sensor.DOMAIN, None) is not None
|
||||
assert trait.SensorStateTrait.supported(sensor.DOMAIN, None, sensor_type, None)
|
||||
|
||||
@ -4002,8 +4002,8 @@ async def test_sensorstate(
|
||||
BASIC_CONFIG,
|
||||
)
|
||||
|
||||
name = sensor_types[sensor_type][0]
|
||||
unit = sensor_types[sensor_type][1]
|
||||
name = item[0]
|
||||
unit = item[1]
|
||||
|
||||
if sensor_type == sensor.SensorDeviceClass.AQI:
|
||||
assert trt.sync_attributes() == {
|
||||
|
@ -94,8 +94,8 @@ def setup_api(hass, data, requests_mock):
|
||||
"units": desc.native_unit_of_measurement,
|
||||
"icon": desc.icon,
|
||||
}
|
||||
for name in sensor_dict:
|
||||
sensor = sensor_dict[name]["sensor"]
|
||||
for value in sensor_dict.values():
|
||||
sensor = value["sensor"]
|
||||
sensor.hass = hass
|
||||
|
||||
return api, sensor_dict
|
||||
@ -111,9 +111,9 @@ def fake_delay(hass, ha_delay):
|
||||
def test_name(requests_mock: requests_mock.Mocker) -> None:
|
||||
"""Test the name."""
|
||||
api, sensor_dict = setup_api(None, MOCK_DATA, requests_mock)
|
||||
for name in sensor_dict:
|
||||
sensor = sensor_dict[name]["sensor"]
|
||||
test_name = sensor_dict[name]["name"]
|
||||
for value in sensor_dict.values():
|
||||
sensor = value["sensor"]
|
||||
test_name = value["name"]
|
||||
assert test_name == sensor.name
|
||||
|
||||
|
||||
@ -122,17 +122,17 @@ def test_unit_of_measurement(
|
||||
) -> None:
|
||||
"""Test the unit of measurement."""
|
||||
api, sensor_dict = setup_api(hass, MOCK_DATA, requests_mock)
|
||||
for name in sensor_dict:
|
||||
sensor = sensor_dict[name]["sensor"]
|
||||
assert sensor_dict[name]["units"] == sensor.unit_of_measurement
|
||||
for value in sensor_dict.values():
|
||||
sensor = value["sensor"]
|
||||
assert value["units"] == sensor.unit_of_measurement
|
||||
|
||||
|
||||
def test_icon(requests_mock: requests_mock.Mocker) -> None:
|
||||
"""Test the icon."""
|
||||
api, sensor_dict = setup_api(None, MOCK_DATA, requests_mock)
|
||||
for name in sensor_dict:
|
||||
sensor = sensor_dict[name]["sensor"]
|
||||
assert sensor_dict[name]["icon"] == sensor.icon
|
||||
for value in sensor_dict.values():
|
||||
sensor = value["sensor"]
|
||||
assert value["icon"] == sensor.icon
|
||||
|
||||
|
||||
def test_state(hass: HomeAssistant, requests_mock: requests_mock.Mocker) -> None:
|
||||
@ -140,8 +140,8 @@ def test_state(hass: HomeAssistant, requests_mock: requests_mock.Mocker) -> None
|
||||
api, sensor_dict = setup_api(hass, MOCK_DATA, requests_mock)
|
||||
now = datetime(1970, month=1, day=1)
|
||||
with patch("homeassistant.util.dt.now", return_value=now):
|
||||
for name in sensor_dict:
|
||||
sensor = sensor_dict[name]["sensor"]
|
||||
for name, value in sensor_dict.items():
|
||||
sensor = value["sensor"]
|
||||
fake_delay(hass, 2)
|
||||
sensor.update()
|
||||
if name == google_wifi.ATTR_LAST_RESTART:
|
||||
@ -159,8 +159,8 @@ def test_update_when_value_is_none(
|
||||
) -> None:
|
||||
"""Test state gets updated to unknown when sensor returns no data."""
|
||||
api, sensor_dict = setup_api(hass, None, requests_mock)
|
||||
for name in sensor_dict:
|
||||
sensor = sensor_dict[name]["sensor"]
|
||||
for value in sensor_dict.values():
|
||||
sensor = value["sensor"]
|
||||
fake_delay(hass, 2)
|
||||
sensor.update()
|
||||
assert sensor.state is None
|
||||
@ -173,8 +173,8 @@ def test_update_when_value_changed(
|
||||
api, sensor_dict = setup_api(hass, MOCK_DATA_NEXT, requests_mock)
|
||||
now = datetime(1970, month=1, day=1)
|
||||
with patch("homeassistant.util.dt.now", return_value=now):
|
||||
for name in sensor_dict:
|
||||
sensor = sensor_dict[name]["sensor"]
|
||||
for name, value in sensor_dict.items():
|
||||
sensor = value["sensor"]
|
||||
fake_delay(hass, 2)
|
||||
sensor.update()
|
||||
if name == google_wifi.ATTR_LAST_RESTART:
|
||||
@ -198,8 +198,8 @@ def test_when_api_data_missing(
|
||||
api, sensor_dict = setup_api(hass, MOCK_DATA_MISSING, requests_mock)
|
||||
now = datetime(1970, month=1, day=1)
|
||||
with patch("homeassistant.util.dt.now", return_value=now):
|
||||
for name in sensor_dict:
|
||||
sensor = sensor_dict[name]["sensor"]
|
||||
for value in sensor_dict.values():
|
||||
sensor = value["sensor"]
|
||||
fake_delay(hass, 2)
|
||||
sensor.update()
|
||||
assert sensor.state is None
|
||||
@ -214,8 +214,8 @@ def test_update_when_unavailable(
|
||||
"google_wifi.GoogleWifiAPI.update",
|
||||
side_effect=update_side_effect(hass, requests_mock),
|
||||
)
|
||||
for name in sensor_dict:
|
||||
sensor = sensor_dict[name]["sensor"]
|
||||
for value in sensor_dict.values():
|
||||
sensor = value["sensor"]
|
||||
sensor.update()
|
||||
assert sensor.state is None
|
||||
|
||||
|
@ -94,8 +94,8 @@ async def test_site_cannot_connect(
|
||||
|
||||
assert hass.states.get("weather.met_office_wavertree_3hourly") is None
|
||||
assert hass.states.get("weather.met_office_wavertree_daily") is None
|
||||
for sensor_id in WAVERTREE_SENSOR_RESULTS:
|
||||
sensor_name, _ = WAVERTREE_SENSOR_RESULTS[sensor_id]
|
||||
for sensor in WAVERTREE_SENSOR_RESULTS.values():
|
||||
sensor_name = sensor[0]
|
||||
sensor = hass.states.get(f"sensor.wavertree_{sensor_name}")
|
||||
assert sensor is None
|
||||
|
||||
|
@ -266,13 +266,11 @@ async def test_if_fires_on_event_legacy(
|
||||
("platform", "camera_type", "event_type", "sub_type"),
|
||||
[
|
||||
("climate", "Smart Valve", trigger, subtype)
|
||||
for trigger in SUBTYPES
|
||||
for subtype in SUBTYPES[trigger]
|
||||
for trigger, subtype in SUBTYPES.items()
|
||||
]
|
||||
+ [
|
||||
("climate", "Smart Thermostat", trigger, subtype)
|
||||
for trigger in SUBTYPES
|
||||
for subtype in SUBTYPES[trigger]
|
||||
for trigger, subtype in SUBTYPES.items()
|
||||
],
|
||||
)
|
||||
async def test_if_fires_on_event_with_subtype(
|
||||
|
@ -20,7 +20,7 @@ async def test_create_binary_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("binary_sensor.downstairs_east_wing_blower_active")
|
||||
@ -32,5 +32,5 @@ async def test_create_binary_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
@ -39,7 +39,7 @@ async def test_climate_zones(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("climate.kitchen")
|
||||
@ -72,5 +72,5 @@ async def test_climate_zones(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
@ -26,7 +26,7 @@ async def test_create_fan_speed_number_entities(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("number.downstairs_east_wing_fan_speed")
|
||||
@ -40,7 +40,7 @@ async def test_create_fan_speed_number_entities(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ async def test_automation_scenes(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("scene.power_outage")
|
||||
@ -55,7 +55,7 @@ async def test_automation_scenes(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("scene.power_restored")
|
||||
@ -73,5 +73,5 @@ async def test_automation_scenes(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
@ -23,7 +23,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.nick_office_zone_setpoint_status")
|
||||
@ -35,7 +35,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.nick_office_zone_status")
|
||||
@ -48,7 +48,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.master_suite_air_cleaner_mode")
|
||||
@ -61,7 +61,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.master_suite_current_compressor_speed")
|
||||
@ -75,7 +75,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.master_suite_outdoor_temperature")
|
||||
@ -90,7 +90,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.master_suite_humidity")
|
||||
@ -105,7 +105,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.master_suite_requested_compressor_speed")
|
||||
@ -119,7 +119,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.master_suite_system_status")
|
||||
@ -132,5 +132,5 @@ async def test_create_sensors(hass: HomeAssistant) -> None:
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
state.attributes[key] == value for key, value in expected_attributes.items()
|
||||
)
|
||||
|
@ -846,13 +846,10 @@ def test_device_classes_aligned() -> None:
|
||||
assert hasattr(NumberDeviceClass, device_class.name)
|
||||
assert getattr(NumberDeviceClass, device_class.name).value == device_class.value
|
||||
|
||||
for device_class in SENSOR_DEVICE_CLASS_UNITS:
|
||||
for device_class, unit in SENSOR_DEVICE_CLASS_UNITS.items():
|
||||
if device_class in NON_NUMERIC_DEVICE_CLASSES:
|
||||
continue
|
||||
assert (
|
||||
SENSOR_DEVICE_CLASS_UNITS[device_class]
|
||||
== NUMBER_DEVICE_CLASS_UNITS[device_class]
|
||||
)
|
||||
assert unit == NUMBER_DEVICE_CLASS_UNITS[device_class]
|
||||
|
||||
|
||||
class MockFlow(ConfigFlow):
|
||||
|
@ -782,8 +782,8 @@ async def test_import_expose_settings_1(
|
||||
expose_settings = exposed_entities.async_get_entity_settings(
|
||||
hass, entity_entry.entity_id
|
||||
)
|
||||
for assistant in EXPOSE_SETTINGS:
|
||||
assert expose_settings[assistant]["should_expose"] == EXPOSE_SETTINGS[assistant]
|
||||
for assistant, settings in EXPOSE_SETTINGS.items():
|
||||
assert expose_settings[assistant]["should_expose"] == settings
|
||||
|
||||
# Check the switch is no longer exposed
|
||||
expose_settings = exposed_entities.async_get_entity_settings(
|
||||
@ -856,18 +856,15 @@ async def test_import_expose_settings_2(
|
||||
expose_settings = exposed_entities.async_get_entity_settings(
|
||||
hass, entity_entry.entity_id
|
||||
)
|
||||
for assistant in EXPOSE_SETTINGS:
|
||||
assert (
|
||||
expose_settings[assistant]["should_expose"]
|
||||
is not EXPOSE_SETTINGS[assistant]
|
||||
)
|
||||
for assistant, settings in EXPOSE_SETTINGS.items():
|
||||
assert expose_settings[assistant]["should_expose"] is not settings
|
||||
|
||||
# Check the switch settings were not modified
|
||||
expose_settings = exposed_entities.async_get_entity_settings(
|
||||
hass, switch_entity_entry.entity_id
|
||||
)
|
||||
for assistant in EXPOSE_SETTINGS:
|
||||
assert expose_settings[assistant]["should_expose"] == EXPOSE_SETTINGS[assistant]
|
||||
for assistant, settings in EXPOSE_SETTINGS.items():
|
||||
assert expose_settings[assistant]["should_expose"] == settings
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST)
|
||||
@ -922,8 +919,8 @@ async def test_restore_expose_settings(
|
||||
expose_settings = exposed_entities.async_get_entity_settings(
|
||||
hass, switch_entity_entry.entity_id
|
||||
)
|
||||
for assistant in EXPOSE_SETTINGS:
|
||||
assert expose_settings[assistant]["should_expose"] == EXPOSE_SETTINGS[assistant]
|
||||
for assistant, settings in EXPOSE_SETTINGS.items():
|
||||
assert expose_settings[assistant]["should_expose"] == settings
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target_domain", PLATFORMS_TO_TEST)
|
||||
|
@ -1273,9 +1273,9 @@ async def test_trigger_entity_restore_state(
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.state == initial_state
|
||||
for attr in restored_attributes:
|
||||
for attr, value in restored_attributes.items():
|
||||
if attr in initial_attributes:
|
||||
assert state.attributes[attr] == restored_attributes[attr]
|
||||
assert state.attributes[attr] == value
|
||||
else:
|
||||
assert attr not in state.attributes
|
||||
assert "another" not in state.attributes
|
||||
|
@ -1828,9 +1828,9 @@ async def test_trigger_entity_restore_state(
|
||||
|
||||
state = hass.states.get("sensor.test")
|
||||
assert state.state == initial_state
|
||||
for attr in restored_attributes:
|
||||
for attr, value in restored_attributes.items():
|
||||
if attr in initial_attributes:
|
||||
assert state.attributes[attr] == restored_attributes[attr]
|
||||
assert state.attributes[attr] == value
|
||||
else:
|
||||
assert attr not in state.attributes
|
||||
assert "another" not in state.attributes
|
||||
|
Loading…
x
Reference in New Issue
Block a user