mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix redefined-argument-from-local pylint warning in tests (#119475)
This commit is contained in:
parent
44901bdcd1
commit
0f0c2f0553
@ -129,8 +129,8 @@ async def test_return_default_get_file_path(
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.mqtt.util.TEMP_DIR_NAME",
|
"homeassistant.components.mqtt.util.TEMP_DIR_NAME",
|
||||||
f"home-assistant-mqtt-other-{getrandbits(10):03x}",
|
f"home-assistant-mqtt-other-{getrandbits(10):03x}",
|
||||||
) as mock_temp_dir:
|
) as temp_dir_name:
|
||||||
tempdir = Path(tempfile.gettempdir()) / mock_temp_dir
|
tempdir = Path(tempfile.gettempdir()) / temp_dir_name
|
||||||
assert await hass.async_add_executor_job(_get_file_path, tempdir)
|
assert await hass.async_add_executor_job(_get_file_path, tempdir)
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ async def test_setup_component(
|
|||||||
assert hass.config_entries.async_entries(DOMAIN)
|
assert hass.config_entries.async_entries(DOMAIN)
|
||||||
assert len(hass.states.async_all()) > 0
|
assert len(hass.states.async_all()) > 0
|
||||||
|
|
||||||
for config_entry in hass.config_entries.async_entries("netatmo"):
|
for entry in hass.config_entries.async_entries("netatmo"):
|
||||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
await hass.config_entries.async_remove(entry.entry_id)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
@ -160,8 +160,8 @@ async def test_setup_component_with_webhook(
|
|||||||
await simulate_webhook(hass, webhook_id, FAKE_WEBHOOK)
|
await simulate_webhook(hass, webhook_id, FAKE_WEBHOOK)
|
||||||
assert hass.states.get(climate_entity_livingroom).state == "heat"
|
assert hass.states.get(climate_entity_livingroom).state == "heat"
|
||||||
|
|
||||||
for config_entry in hass.config_entries.async_entries("netatmo"):
|
for entry in hass.config_entries.async_entries("netatmo"):
|
||||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
await hass.config_entries.async_remove(entry.entry_id)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
@ -246,8 +246,8 @@ async def test_setup_with_cloud(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.config_entries.async_entries(DOMAIN)
|
assert hass.config_entries.async_entries(DOMAIN)
|
||||||
|
|
||||||
for config_entry in hass.config_entries.async_entries("netatmo"):
|
for entry in hass.config_entries.async_entries("netatmo"):
|
||||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
await hass.config_entries.async_remove(entry.entry_id)
|
||||||
fake_delete_cloudhook.assert_called_once()
|
fake_delete_cloudhook.assert_called_once()
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -479,8 +479,8 @@ async def test_setup_component_invalid_token(
|
|||||||
notifications = async_get_persistent_notifications(hass)
|
notifications = async_get_persistent_notifications(hass)
|
||||||
assert len(notifications) > 0
|
assert len(notifications) > 0
|
||||||
|
|
||||||
for config_entry in hass.config_entries.async_entries("netatmo"):
|
for entry in hass.config_entries.async_entries("netatmo"):
|
||||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
await hass.config_entries.async_remove(entry.entry_id)
|
||||||
|
|
||||||
|
|
||||||
async def test_devices(
|
async def test_devices(
|
||||||
|
@ -694,7 +694,7 @@ async def test_saving_event_exclude_event_type(
|
|||||||
|
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
|
|
||||||
def _get_events(hass: HomeAssistant, event_types: list[str]) -> list[Event]:
|
def _get_events(hass: HomeAssistant, event_type_list: list[str]) -> list[Event]:
|
||||||
with session_scope(hass=hass, read_only=True) as session:
|
with session_scope(hass=hass, read_only=True) as session:
|
||||||
events = []
|
events = []
|
||||||
for event, event_data, event_types in (
|
for event, event_data, event_types in (
|
||||||
@ -703,7 +703,7 @@ async def test_saving_event_exclude_event_type(
|
|||||||
EventTypes, (Events.event_type_id == EventTypes.event_type_id)
|
EventTypes, (Events.event_type_id == EventTypes.event_type_id)
|
||||||
)
|
)
|
||||||
.outerjoin(EventData, Events.data_id == EventData.data_id)
|
.outerjoin(EventData, Events.data_id == EventData.data_id)
|
||||||
.where(EventTypes.event_type.in_(event_types))
|
.where(EventTypes.event_type.in_(event_type_list))
|
||||||
):
|
):
|
||||||
event = cast(Events, event)
|
event = cast(Events, event)
|
||||||
event_data = cast(EventData, event_data)
|
event_data = cast(EventData, event_data)
|
||||||
|
@ -3742,69 +3742,62 @@ async def test_compile_statistics_hourly_daily_monthly_summary(
|
|||||||
"sensor.test4": None,
|
"sensor.test4": None,
|
||||||
}
|
}
|
||||||
start = zero
|
start = zero
|
||||||
with freeze_time(start) as freezer:
|
for i in range(24):
|
||||||
for i in range(24):
|
seq = [-10, 15, 30]
|
||||||
seq = [-10, 15, 30]
|
# test1 has same value in every period
|
||||||
# test1 has same value in every period
|
four, _states = await async_record_states(
|
||||||
four, _states = await async_record_states(
|
hass, freezer, start, "sensor.test1", attributes, seq
|
||||||
hass, freezer, start, "sensor.test1", attributes, seq
|
)
|
||||||
|
states["sensor.test1"] += _states["sensor.test1"]
|
||||||
|
last_state = last_states["sensor.test1"]
|
||||||
|
expected_minima["sensor.test1"].append(_min(seq, last_state))
|
||||||
|
expected_maxima["sensor.test1"].append(_max(seq, last_state))
|
||||||
|
expected_averages["sensor.test1"].append(_weighted_average(seq, i, last_state))
|
||||||
|
last_states["sensor.test1"] = seq[-1]
|
||||||
|
# test2 values change: min/max at the last state
|
||||||
|
seq = [-10 * (i + 1), 15 * (i + 1), 30 * (i + 1)]
|
||||||
|
four, _states = await async_record_states(
|
||||||
|
hass, freezer, start, "sensor.test2", attributes, seq
|
||||||
|
)
|
||||||
|
states["sensor.test2"] += _states["sensor.test2"]
|
||||||
|
last_state = last_states["sensor.test2"]
|
||||||
|
expected_minima["sensor.test2"].append(_min(seq, last_state))
|
||||||
|
expected_maxima["sensor.test2"].append(_max(seq, last_state))
|
||||||
|
expected_averages["sensor.test2"].append(_weighted_average(seq, i, last_state))
|
||||||
|
last_states["sensor.test2"] = seq[-1]
|
||||||
|
# test3 values change: min/max at the first state
|
||||||
|
seq = [-10 * (23 - i + 1), 15 * (23 - i + 1), 30 * (23 - i + 1)]
|
||||||
|
four, _states = await async_record_states(
|
||||||
|
hass, freezer, start, "sensor.test3", attributes, seq
|
||||||
|
)
|
||||||
|
states["sensor.test3"] += _states["sensor.test3"]
|
||||||
|
last_state = last_states["sensor.test3"]
|
||||||
|
expected_minima["sensor.test3"].append(_min(seq, last_state))
|
||||||
|
expected_maxima["sensor.test3"].append(_max(seq, last_state))
|
||||||
|
expected_averages["sensor.test3"].append(_weighted_average(seq, i, last_state))
|
||||||
|
last_states["sensor.test3"] = seq[-1]
|
||||||
|
# test4 values grow
|
||||||
|
seq = [i, i + 0.5, i + 0.75]
|
||||||
|
start_meter = start
|
||||||
|
for j in range(len(seq)):
|
||||||
|
_states = await async_record_meter_state(
|
||||||
|
hass,
|
||||||
|
freezer,
|
||||||
|
start_meter,
|
||||||
|
"sensor.test4",
|
||||||
|
sum_attributes,
|
||||||
|
seq[j : j + 1],
|
||||||
)
|
)
|
||||||
states["sensor.test1"] += _states["sensor.test1"]
|
start_meter += timedelta(minutes=1)
|
||||||
last_state = last_states["sensor.test1"]
|
states["sensor.test4"] += _states["sensor.test4"]
|
||||||
expected_minima["sensor.test1"].append(_min(seq, last_state))
|
last_state = last_states["sensor.test4"]
|
||||||
expected_maxima["sensor.test1"].append(_max(seq, last_state))
|
expected_states["sensor.test4"].append(seq[-1])
|
||||||
expected_averages["sensor.test1"].append(
|
expected_sums["sensor.test4"].append(
|
||||||
_weighted_average(seq, i, last_state)
|
_sum(seq, last_state, expected_sums["sensor.test4"])
|
||||||
)
|
)
|
||||||
last_states["sensor.test1"] = seq[-1]
|
last_states["sensor.test4"] = seq[-1]
|
||||||
# test2 values change: min/max at the last state
|
|
||||||
seq = [-10 * (i + 1), 15 * (i + 1), 30 * (i + 1)]
|
|
||||||
four, _states = await async_record_states(
|
|
||||||
hass, freezer, start, "sensor.test2", attributes, seq
|
|
||||||
)
|
|
||||||
states["sensor.test2"] += _states["sensor.test2"]
|
|
||||||
last_state = last_states["sensor.test2"]
|
|
||||||
expected_minima["sensor.test2"].append(_min(seq, last_state))
|
|
||||||
expected_maxima["sensor.test2"].append(_max(seq, last_state))
|
|
||||||
expected_averages["sensor.test2"].append(
|
|
||||||
_weighted_average(seq, i, last_state)
|
|
||||||
)
|
|
||||||
last_states["sensor.test2"] = seq[-1]
|
|
||||||
# test3 values change: min/max at the first state
|
|
||||||
seq = [-10 * (23 - i + 1), 15 * (23 - i + 1), 30 * (23 - i + 1)]
|
|
||||||
four, _states = await async_record_states(
|
|
||||||
hass, freezer, start, "sensor.test3", attributes, seq
|
|
||||||
)
|
|
||||||
states["sensor.test3"] += _states["sensor.test3"]
|
|
||||||
last_state = last_states["sensor.test3"]
|
|
||||||
expected_minima["sensor.test3"].append(_min(seq, last_state))
|
|
||||||
expected_maxima["sensor.test3"].append(_max(seq, last_state))
|
|
||||||
expected_averages["sensor.test3"].append(
|
|
||||||
_weighted_average(seq, i, last_state)
|
|
||||||
)
|
|
||||||
last_states["sensor.test3"] = seq[-1]
|
|
||||||
# test4 values grow
|
|
||||||
seq = [i, i + 0.5, i + 0.75]
|
|
||||||
start_meter = start
|
|
||||||
for j in range(len(seq)):
|
|
||||||
_states = await async_record_meter_state(
|
|
||||||
hass,
|
|
||||||
freezer,
|
|
||||||
start_meter,
|
|
||||||
"sensor.test4",
|
|
||||||
sum_attributes,
|
|
||||||
seq[j : j + 1],
|
|
||||||
)
|
|
||||||
start_meter += timedelta(minutes=1)
|
|
||||||
states["sensor.test4"] += _states["sensor.test4"]
|
|
||||||
last_state = last_states["sensor.test4"]
|
|
||||||
expected_states["sensor.test4"].append(seq[-1])
|
|
||||||
expected_sums["sensor.test4"].append(
|
|
||||||
_sum(seq, last_state, expected_sums["sensor.test4"])
|
|
||||||
)
|
|
||||||
last_states["sensor.test4"] = seq[-1]
|
|
||||||
|
|
||||||
start += timedelta(minutes=5)
|
start += timedelta(minutes=5)
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
hist = history.get_significant_states(
|
hist = history.get_significant_states(
|
||||||
hass,
|
hass,
|
||||||
|
@ -81,7 +81,7 @@ async def test_user_create_entry(
|
|||||||
with patch(
|
with patch(
|
||||||
f"{MODULE}.config_flow.vicare_login",
|
f"{MODULE}.config_flow.vicare_login",
|
||||||
return_value=None,
|
return_value=None,
|
||||||
) as mock_setup_entry:
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
VALID_CONFIG,
|
VALID_CONFIG,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user