mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add support for rangeValueDeltaDefault in Alexa AdjustRangeValue directive (#31258)
* Update tests with rangeValue and rangeValueDelta to use int. * Add support for rangeValueDeltaDefault for covers. * Update tests for range changes. * Test for AdjustRangeValue with rangeValueDeltaDefault True. * Update tilt error.
This commit is contained in:
parent
7116c7404a
commit
83dff16e1e
@ -1195,6 +1195,7 @@ async def async_api_adjust_range(hass, config, directive, context):
|
||||
service = None
|
||||
data = {ATTR_ENTITY_ID: entity.entity_id}
|
||||
range_delta = directive.payload["rangeValueDelta"]
|
||||
range_delta_default = bool(directive.payload["rangeValueDeltaDefault"])
|
||||
response_value = 0
|
||||
|
||||
# Fan Speed
|
||||
@ -1220,9 +1221,12 @@ async def async_api_adjust_range(hass, config, directive, context):
|
||||
|
||||
# Cover Position
|
||||
elif instance == f"{cover.DOMAIN}.{cover.ATTR_POSITION}":
|
||||
range_delta = int(range_delta)
|
||||
range_delta = int(range_delta * 20) if range_delta_default else int(range_delta)
|
||||
service = SERVICE_SET_COVER_POSITION
|
||||
current = entity.attributes.get(cover.ATTR_POSITION)
|
||||
if not current:
|
||||
msg = "Unable to determine {} current position".format(entity.entity_id)
|
||||
raise AlexaInvalidValueError(msg)
|
||||
position = response_value = min(100, max(0, range_delta + current))
|
||||
if position == 100:
|
||||
service = cover.SERVICE_OPEN_COVER
|
||||
@ -1233,9 +1237,14 @@ async def async_api_adjust_range(hass, config, directive, context):
|
||||
|
||||
# Cover Tilt
|
||||
elif instance == f"{cover.DOMAIN}.tilt":
|
||||
range_delta = int(range_delta)
|
||||
range_delta = int(range_delta * 20) if range_delta_default else int(range_delta)
|
||||
service = SERVICE_SET_COVER_TILT_POSITION
|
||||
current = entity.attributes.get(cover.ATTR_TILT_POSITION)
|
||||
if not current:
|
||||
msg = "Unable to determine {} current tilt position".format(
|
||||
entity.entity_id
|
||||
)
|
||||
raise AlexaInvalidValueError(msg)
|
||||
tilt_position = response_value = min(100, max(0, range_delta + current))
|
||||
if tilt_position == 100:
|
||||
service = cover.SERVICE_OPEN_COVER_TILT
|
||||
|
@ -753,7 +753,7 @@ async def test_fan_range(hass):
|
||||
"fan#test_5",
|
||||
"fan.set_speed",
|
||||
hass,
|
||||
payload={"rangeValue": "1"},
|
||||
payload={"rangeValue": 1},
|
||||
instance="fan.speed",
|
||||
)
|
||||
assert call.data["speed"] == "low"
|
||||
@ -764,18 +764,22 @@ async def test_fan_range(hass):
|
||||
"fan#test_5",
|
||||
"fan.set_speed",
|
||||
hass,
|
||||
payload={"rangeValue": "5"},
|
||||
payload={"rangeValue": 5},
|
||||
instance="fan.speed",
|
||||
)
|
||||
assert call.data["speed"] == "warp_speed"
|
||||
|
||||
await assert_range_changes(
|
||||
hass,
|
||||
[("low", "-1"), ("high", "1"), ("medium", "0"), ("warp_speed", "99")],
|
||||
[
|
||||
("low", -1, False),
|
||||
("high", 1, False),
|
||||
("medium", 0, False),
|
||||
("warp_speed", 99, False),
|
||||
],
|
||||
"Alexa.RangeController",
|
||||
"AdjustRangeValue",
|
||||
"fan#test_5",
|
||||
False,
|
||||
"fan.set_speed",
|
||||
"speed",
|
||||
instance="fan.speed",
|
||||
@ -802,18 +806,17 @@ async def test_fan_range_off(hass):
|
||||
"fan#test_6",
|
||||
"fan.turn_off",
|
||||
hass,
|
||||
payload={"rangeValue": "0"},
|
||||
payload={"rangeValue": 0},
|
||||
instance="fan.speed",
|
||||
)
|
||||
assert call.data["speed"] == "off"
|
||||
|
||||
await assert_range_changes(
|
||||
hass,
|
||||
[("off", "-3"), ("off", "-99")],
|
||||
[("off", -3, False), ("off", -99, False)],
|
||||
"Alexa.RangeController",
|
||||
"AdjustRangeValue",
|
||||
"fan#test_6",
|
||||
False,
|
||||
"fan.turn_off",
|
||||
"speed",
|
||||
instance="fan.speed",
|
||||
@ -1524,7 +1527,7 @@ async def test_cover_position_range(hass):
|
||||
"cover#test_range",
|
||||
"cover.set_cover_position",
|
||||
hass,
|
||||
payload={"rangeValue": "50"},
|
||||
payload={"rangeValue": 50},
|
||||
instance="cover.position",
|
||||
)
|
||||
assert call.data["position"] == 50
|
||||
@ -1535,7 +1538,7 @@ async def test_cover_position_range(hass):
|
||||
"cover#test_range",
|
||||
"cover.close_cover",
|
||||
hass,
|
||||
payload={"rangeValue": "0"},
|
||||
payload={"rangeValue": 0},
|
||||
instance="cover.position",
|
||||
)
|
||||
properties = msg["context"]["properties"][0]
|
||||
@ -1549,7 +1552,7 @@ async def test_cover_position_range(hass):
|
||||
"cover#test_range",
|
||||
"cover.open_cover",
|
||||
hass,
|
||||
payload={"rangeValue": "100"},
|
||||
payload={"rangeValue": 100},
|
||||
instance="cover.position",
|
||||
)
|
||||
properties = msg["context"]["properties"][0]
|
||||
@ -1563,7 +1566,7 @@ async def test_cover_position_range(hass):
|
||||
"cover#test_range",
|
||||
"cover.open_cover",
|
||||
hass,
|
||||
payload={"rangeValueDelta": "99"},
|
||||
payload={"rangeValueDelta": 99, "rangeValueDeltaDefault": False},
|
||||
instance="cover.position",
|
||||
)
|
||||
properties = msg["context"]["properties"][0]
|
||||
@ -1577,7 +1580,7 @@ async def test_cover_position_range(hass):
|
||||
"cover#test_range",
|
||||
"cover.close_cover",
|
||||
hass,
|
||||
payload={"rangeValueDelta": "-99"},
|
||||
payload={"rangeValueDelta": -99, "rangeValueDeltaDefault": False},
|
||||
instance="cover.position",
|
||||
)
|
||||
properties = msg["context"]["properties"][0]
|
||||
@ -1587,11 +1590,10 @@ async def test_cover_position_range(hass):
|
||||
|
||||
await assert_range_changes(
|
||||
hass,
|
||||
[(25, "-5"), (35, "5")],
|
||||
[(25, -5, False), (35, 5, False), (50, 1, True), (10, -1, True)],
|
||||
"Alexa.RangeController",
|
||||
"AdjustRangeValue",
|
||||
"cover#test_range",
|
||||
False,
|
||||
"cover.set_cover_position",
|
||||
"position",
|
||||
instance="cover.position",
|
||||
@ -1618,21 +1620,13 @@ async def assert_percentage_changes(
|
||||
|
||||
|
||||
async def assert_range_changes(
|
||||
hass,
|
||||
adjustments,
|
||||
namespace,
|
||||
name,
|
||||
endpoint,
|
||||
delta_default,
|
||||
service,
|
||||
changed_parameter,
|
||||
instance,
|
||||
hass, adjustments, namespace, name, endpoint, service, changed_parameter, instance
|
||||
):
|
||||
"""Assert an API request making range changes works.
|
||||
|
||||
AdjustRangeValue are examples of such requests.
|
||||
"""
|
||||
for result_range, adjustment in adjustments:
|
||||
for result_range, adjustment, delta_default in adjustments:
|
||||
payload = {
|
||||
"rangeValueDelta": adjustment,
|
||||
"rangeValueDeltaDefault": delta_default,
|
||||
@ -2488,7 +2482,7 @@ async def test_range_unsupported_domain(hass):
|
||||
|
||||
context = Context()
|
||||
request = get_new_request("Alexa.RangeController", "SetRangeValue", "switch#test")
|
||||
request["directive"]["payload"] = {"rangeValue": "1"}
|
||||
request["directive"]["payload"] = {"rangeValue": 1}
|
||||
request["directive"]["header"]["instance"] = "switch.speed"
|
||||
|
||||
msg = await smart_home.async_handle_message(hass, DEFAULT_CONFIG, request, context)
|
||||
@ -2855,7 +2849,7 @@ async def test_cover_tilt_position_range(hass):
|
||||
"cover#test_tilt_range",
|
||||
"cover.open_cover_tilt",
|
||||
hass,
|
||||
payload={"rangeValueDelta": 99},
|
||||
payload={"rangeValueDelta": 99, "rangeValueDeltaDefault": False},
|
||||
instance="cover.tilt",
|
||||
)
|
||||
properties = msg["context"]["properties"][0]
|
||||
@ -2869,7 +2863,7 @@ async def test_cover_tilt_position_range(hass):
|
||||
"cover#test_tilt_range",
|
||||
"cover.close_cover_tilt",
|
||||
hass,
|
||||
payload={"rangeValueDelta": -99},
|
||||
payload={"rangeValueDelta": -99, "rangeValueDeltaDefault": False},
|
||||
instance="cover.tilt",
|
||||
)
|
||||
properties = msg["context"]["properties"][0]
|
||||
@ -2879,11 +2873,10 @@ async def test_cover_tilt_position_range(hass):
|
||||
|
||||
await assert_range_changes(
|
||||
hass,
|
||||
[(25, "-5"), (35, "5")],
|
||||
[(25, -5, False), (35, 5, False), (50, 1, True), (10, -1, True)],
|
||||
"Alexa.RangeController",
|
||||
"AdjustRangeValue",
|
||||
"cover#test_tilt_range",
|
||||
False,
|
||||
"cover.set_cover_tilt_position",
|
||||
"tilt_position",
|
||||
instance="cover.tilt",
|
||||
@ -3038,18 +3031,17 @@ async def test_input_number(hass):
|
||||
"input_number#test_slider",
|
||||
"input_number.set_value",
|
||||
hass,
|
||||
payload={"rangeValue": "10"},
|
||||
payload={"rangeValue": 10},
|
||||
instance="input_number.value",
|
||||
)
|
||||
assert call.data["value"] == 10
|
||||
|
||||
await assert_range_changes(
|
||||
hass,
|
||||
[(25, "-5"), (35, "5"), (-20, "-100"), (35, "100")],
|
||||
[(25, -5, False), (35, 5, False), (-20, -100, False), (35, 100, False)],
|
||||
"Alexa.RangeController",
|
||||
"AdjustRangeValue",
|
||||
"input_number#test_slider",
|
||||
False,
|
||||
"input_number.set_value",
|
||||
"value",
|
||||
instance="input_number.value",
|
||||
@ -3124,18 +3116,23 @@ async def test_input_number_float(hass):
|
||||
"input_number#test_slider_float",
|
||||
"input_number.set_value",
|
||||
hass,
|
||||
payload={"rangeValue": "0.333"},
|
||||
payload={"rangeValue": 0.333},
|
||||
instance="input_number.value",
|
||||
)
|
||||
assert call.data["value"] == 0.333
|
||||
|
||||
await assert_range_changes(
|
||||
hass,
|
||||
[(0.4, "-0.1"), (0.6, "0.1"), (0, "-100"), (1, "100"), (0.51, "0.01")],
|
||||
[
|
||||
(0.4, -0.1, False),
|
||||
(0.6, 0.1, False),
|
||||
(0, -100, False),
|
||||
(1, 100, False),
|
||||
(0.51, 0.01, False),
|
||||
],
|
||||
"Alexa.RangeController",
|
||||
"AdjustRangeValue",
|
||||
"input_number#test_slider_float",
|
||||
False,
|
||||
"input_number.set_value",
|
||||
"value",
|
||||
instance="input_number.value",
|
||||
@ -3432,7 +3429,7 @@ async def test_vacuum_fan_speed(hass):
|
||||
"vacuum#test_2",
|
||||
"vacuum.set_fan_speed",
|
||||
hass,
|
||||
payload={"rangeValue": "1"},
|
||||
payload={"rangeValue": 1},
|
||||
instance="vacuum.fan_speed",
|
||||
)
|
||||
assert call.data["fan_speed"] == "low"
|
||||
@ -3443,18 +3440,22 @@ async def test_vacuum_fan_speed(hass):
|
||||
"vacuum#test_2",
|
||||
"vacuum.set_fan_speed",
|
||||
hass,
|
||||
payload={"rangeValue": "5"},
|
||||
payload={"rangeValue": 5},
|
||||
instance="vacuum.fan_speed",
|
||||
)
|
||||
assert call.data["fan_speed"] == "super_sucker"
|
||||
|
||||
await assert_range_changes(
|
||||
hass,
|
||||
[("low", "-1"), ("high", "1"), ("medium", "0"), ("super_sucker", "99")],
|
||||
[
|
||||
("low", -1, False),
|
||||
("high", 1, False),
|
||||
("medium", 0, False),
|
||||
("super_sucker", 99, False),
|
||||
],
|
||||
"Alexa.RangeController",
|
||||
"AdjustRangeValue",
|
||||
"vacuum#test_2",
|
||||
False,
|
||||
"vacuum.set_fan_speed",
|
||||
"fan_speed",
|
||||
instance="vacuum.fan_speed",
|
||||
|
Loading…
x
Reference in New Issue
Block a user