Skip to content

Commit 75615bd

Browse files
authored
Merge pull request home-assistant#44982 from home-assistant/rc
2021.1.1
2 parents bb1ebae + 9524766 commit 75615bd

File tree

11 files changed

+97
-27
lines changed

11 files changed

+97
-27
lines changed

homeassistant/components/hassio/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def post(self, request, data):
8282
data[ATTR_USERNAME], data[ATTR_PASSWORD]
8383
)
8484
except auth_ha.InvalidAuth:
85-
raise HTTPUnauthorized() from None
85+
raise HTTPNotFound() from None
8686

8787
return web.Response(status=HTTP_OK)
8888

homeassistant/components/knx/cover.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def current_cover_position(self):
7979
@property
8080
def is_closed(self):
8181
"""Return if the cover is closed."""
82+
# state shall be "unknown" when xknx travelcalculator is not initialized
83+
if self._device.current_position() is None:
84+
return None
8285
return self._device.is_closed()
8386

8487
@property

homeassistant/components/light/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ async def async_handle_light_on_service(light, call):
232232
async def async_handle_toggle_service(light, call):
233233
"""Handle toggling a light."""
234234
if light.is_on:
235-
off_params = filter_turn_off_params(call.data)
235+
off_params = filter_turn_off_params(call.data["params"])
236236
await light.async_turn_off(**off_params)
237237
else:
238238
await async_handle_light_on_service(light, call)

homeassistant/components/myq/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"domain": "myq",
33
"name": "MyQ",
44
"documentation": "https://www.home-assistant.io/integrations/myq",
5-
"requirements": ["pymyq==2.0.12"],
5+
"requirements": ["pymyq==2.0.13"],
66
"codeowners": ["@bdraco"],
77
"config_flow": true,
88
"homekit": {

homeassistant/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Constants used by Home Assistant components."""
22
MAJOR_VERSION = 2021
33
MINOR_VERSION = 1
4-
PATCH_VERSION = "0"
4+
PATCH_VERSION = "1"
55
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
66
__version__ = f"{__short_version__}.{PATCH_VERSION}"
77
REQUIRED_PYTHON_VER = (3, 7, 1)

homeassistant/helpers/script.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@
6262
callback,
6363
)
6464
from homeassistant.helpers import condition, config_validation as cv, service, template
65-
from homeassistant.helpers.event import (
66-
TrackTemplate,
67-
async_call_later,
68-
async_track_template_result,
69-
)
65+
from homeassistant.helpers.event import async_call_later, async_track_template
7066
from homeassistant.helpers.script_variables import ScriptVariables
7167
from homeassistant.helpers.trigger import (
7268
async_initialize_triggers,
@@ -359,7 +355,7 @@ async def _async_wait_template_step(self):
359355
return
360356

361357
@callback
362-
def _async_script_wait(event, updates):
358+
def async_script_wait(entity_id, from_s, to_s):
363359
"""Handle script after template condition is true."""
364360
self._variables["wait"] = {
365361
"remaining": to_context.remaining if to_context else delay,
@@ -368,12 +364,9 @@ def _async_script_wait(event, updates):
368364
done.set()
369365

370366
to_context = None
371-
info = async_track_template_result(
372-
self._hass,
373-
[TrackTemplate(wait_template, self._variables)],
374-
_async_script_wait,
367+
unsub = async_track_template(
368+
self._hass, wait_template, async_script_wait, self._variables
375369
)
376-
unsub = info.async_remove
377370

378371
self._changed()
379372
done = asyncio.Event()

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ pymsteams==0.1.12
15361536
pymusiccast==0.1.6
15371537

15381538
# homeassistant.components.myq
1539-
pymyq==2.0.12
1539+
pymyq==2.0.13
15401540

15411541
# homeassistant.components.mysensors
15421542
pymysensors==0.18.0

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ pymodbus==2.3.0
779779
pymonoprice==0.3
780780

781781
# homeassistant.components.myq
782-
pymyq==2.0.12
782+
pymyq==2.0.13
783783

784784
# homeassistant.components.nut
785785
pynut2==2.1.2

tests/components/hassio/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def test_login_error(hass, hassio_client_supervisor):
6666
)
6767

6868
# Check we got right response
69-
assert resp.status == 401
69+
assert resp.status == 404
7070
mock_login.assert_called_with("test", "123456")
7171

7272

tests/components/light/test_init.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,21 @@ async def test_services(hass, mock_light_profiles):
336336
light.ATTR_TRANSITION: prof_t,
337337
}
338338

339+
await hass.services.async_call(
340+
light.DOMAIN,
341+
SERVICE_TOGGLE,
342+
{
343+
ATTR_ENTITY_ID: ent3.entity_id,
344+
light.ATTR_TRANSITION: 4,
345+
},
346+
blocking=True,
347+
)
348+
349+
_, data = ent3.last_call("turn_off")
350+
assert data == {
351+
light.ATTR_TRANSITION: 4,
352+
}
353+
339354
# Test bad data
340355
await hass.services.async_call(
341356
light.DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_MATCH_ALL}, blocking=True

tests/helpers/test_script.py

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from types import MappingProxyType
88
from unittest import mock
99

10+
from async_timeout import timeout
1011
import pytest
1112
import voluptuous as vol
1213

@@ -544,6 +545,41 @@ async def test_wait_basic(hass, action_type):
544545
assert script_obj.last_action is None
545546

546547

548+
@pytest.mark.parametrize("action_type", ["template", "trigger"])
549+
async def test_wait_basic_times_out(hass, action_type):
550+
"""Test wait actions times out when the action does not happen."""
551+
wait_alias = "wait step"
552+
action = {"alias": wait_alias}
553+
if action_type == "template":
554+
action["wait_template"] = "{{ states.switch.test.state == 'off' }}"
555+
else:
556+
action["wait_for_trigger"] = {
557+
"platform": "state",
558+
"entity_id": "switch.test",
559+
"to": "off",
560+
}
561+
sequence = cv.SCRIPT_SCHEMA(action)
562+
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
563+
wait_started_flag = async_watch_for_action(script_obj, wait_alias)
564+
timed_out = False
565+
566+
try:
567+
hass.states.async_set("switch.test", "on")
568+
hass.async_create_task(script_obj.async_run(context=Context()))
569+
await asyncio.wait_for(wait_started_flag.wait(), 1)
570+
assert script_obj.is_running
571+
assert script_obj.last_action == wait_alias
572+
hass.states.async_set("switch.test", "not_on")
573+
574+
with timeout(0.1):
575+
await hass.async_block_till_done()
576+
except asyncio.TimeoutError:
577+
timed_out = True
578+
await script_obj.async_stop()
579+
580+
assert timed_out
581+
582+
547583
@pytest.mark.parametrize("action_type", ["template", "trigger"])
548584
async def test_multiple_runs_wait(hass, action_type):
549585
"""Test multiple runs with wait in script."""
@@ -782,30 +818,53 @@ async def test_wait_template_variables_in(hass):
782818

783819
async def test_wait_template_with_utcnow(hass):
784820
"""Test the wait template with utcnow."""
785-
sequence = cv.SCRIPT_SCHEMA({"wait_template": "{{ utcnow().hours == 12 }}"})
821+
sequence = cv.SCRIPT_SCHEMA({"wait_template": "{{ utcnow().hour == 12 }}"})
786822
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
787823
wait_started_flag = async_watch_for_action(script_obj, "wait")
788-
start_time = dt_util.utcnow() + timedelta(hours=24)
824+
start_time = dt_util.utcnow().replace(minute=1) + timedelta(hours=48)
789825

790826
try:
791827
hass.async_create_task(script_obj.async_run(context=Context()))
792-
async_fire_time_changed(hass, start_time.replace(hour=5))
793-
assert not script_obj.is_running
794-
async_fire_time_changed(hass, start_time.replace(hour=12))
795-
796828
await asyncio.wait_for(wait_started_flag.wait(), 1)
797-
798829
assert script_obj.is_running
830+
831+
match_time = start_time.replace(hour=12)
832+
with patch("homeassistant.util.dt.utcnow", return_value=match_time):
833+
async_fire_time_changed(hass, match_time)
799834
except (AssertionError, asyncio.TimeoutError):
800835
await script_obj.async_stop()
801836
raise
802837
else:
803-
async_fire_time_changed(hass, start_time.replace(hour=3))
804838
await hass.async_block_till_done()
805-
806839
assert not script_obj.is_running
807840

808841

842+
async def test_wait_template_with_utcnow_no_match(hass):
843+
"""Test the wait template with utcnow that does not match."""
844+
sequence = cv.SCRIPT_SCHEMA({"wait_template": "{{ utcnow().hour == 12 }}"})
845+
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
846+
wait_started_flag = async_watch_for_action(script_obj, "wait")
847+
start_time = dt_util.utcnow().replace(minute=1) + timedelta(hours=48)
848+
timed_out = False
849+
850+
try:
851+
hass.async_create_task(script_obj.async_run(context=Context()))
852+
await asyncio.wait_for(wait_started_flag.wait(), 1)
853+
assert script_obj.is_running
854+
855+
non_maching_time = start_time.replace(hour=3)
856+
with patch("homeassistant.util.dt.utcnow", return_value=non_maching_time):
857+
async_fire_time_changed(hass, non_maching_time)
858+
859+
with timeout(0.1):
860+
await hass.async_block_till_done()
861+
except asyncio.TimeoutError:
862+
timed_out = True
863+
await script_obj.async_stop()
864+
865+
assert timed_out
866+
867+
809868
@pytest.mark.parametrize("mode", ["no_timeout", "timeout_finish", "timeout_not_finish"])
810869
@pytest.mark.parametrize("action_type", ["template", "trigger"])
811870
async def test_wait_variables_out(hass, mode, action_type):

0 commit comments

Comments
 (0)