Add support for input_number entities in Alexa integration (#30139)
* Add support for input_number entities * Update homeassistant/components/alexa/capabilities.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * Removed get methods to directly access required attributes dicts. Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
1 parent
7f2921b0e6
commit
a2678b2aff
5 files changed
+256
-8
No files matched your search
@@ -2740,3 +2740,175 @@ async def test_cover_semantics(hass):
|
||||
"states": ["Alexa.States.Open"],
|
||||
"range": {"minimumValue": 1, "maximumValue": 100},
|
||||
} in state_mappings
|
||||
|
||||
|
||||
async def test_input_number(hass):
|
||||
"""Test input_number discovery."""
|
||||
device = (
|
||||
"input_number.test_slider",
|
||||
30,
|
||||
{
|
||||
"initial": 30,
|
||||
"min": -20,
|
||||
"max": 35,
|
||||
"step": 1,
|
||||
"mode": "slider",
|
||||
"friendly_name": "Test Slider",
|
||||
},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert appliance["endpointId"] == "input_number#test_slider"
|
||||
assert appliance["displayCategories"][0] == "OTHER"
|
||||
assert appliance["friendlyName"] == "Test Slider"
|
||||
|
||||
capabilities = assert_endpoint_capabilities(
|
||||
appliance, "Alexa.RangeController", "Alexa.EndpointHealth", "Alexa"
|
||||
)
|
||||
|
||||
range_capability = get_capability(
|
||||
capabilities, "Alexa.RangeController", "input_number.value"
|
||||
)
|
||||
|
||||
capability_resources = range_capability["capabilityResources"]
|
||||
assert capability_resources is not None
|
||||
assert {
|
||||
"@type": "text",
|
||||
"value": {"text": "Value", "locale": "en-US"},
|
||||
} in capability_resources["friendlyNames"]
|
||||
|
||||
configuration = range_capability["configuration"]
|
||||
assert configuration is not None
|
||||
|
||||
supported_range = configuration["supportedRange"]
|
||||
assert supported_range["minimumValue"] == -20
|
||||
assert supported_range["maximumValue"] == 35
|
||||
assert supported_range["precision"] == 1
|
||||
|
||||
presets = configuration["presets"]
|
||||
assert {
|
||||
"rangeValue": 35,
|
||||
"presetResources": {
|
||||
"friendlyNames": [
|
||||
{"@type": "asset", "value": {"assetId": "Alexa.Value.Maximum"}}
|
||||
]
|
||||
},
|
||||
} in presets
|
||||
|
||||
assert {
|
||||
"rangeValue": -20,
|
||||
"presetResources": {
|
||||
"friendlyNames": [
|
||||
{"@type": "asset", "value": {"assetId": "Alexa.Value.Minimum"}}
|
||||
]
|
||||
},
|
||||
} in presets
|
||||
|
||||
call, _ = await assert_request_calls_service(
|
||||
"Alexa.RangeController",
|
||||
"SetRangeValue",
|
||||
"input_number#test_slider",
|
||||
"input_number.set_value",
|
||||
hass,
|
||||
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")],
|
||||
"Alexa.RangeController",
|
||||
"AdjustRangeValue",
|
||||
"input_number#test_slider",
|
||||
False,
|
||||
"input_number.set_value",
|
||||
"value",
|
||||
instance="input_number.value",
|
||||
)
|
||||
|
||||
|
||||
async def test_input_number_float(hass):
|
||||
"""Test input_number discovery."""
|
||||
device = (
|
||||
"input_number.test_slider_float",
|
||||
0.5,
|
||||
{
|
||||
"initial": 0.5,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.01,
|
||||
"mode": "slider",
|
||||
"friendly_name": "Test Slider Float",
|
||||
},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert appliance["endpointId"] == "input_number#test_slider_float"
|
||||
assert appliance["displayCategories"][0] == "OTHER"
|
||||
assert appliance["friendlyName"] == "Test Slider Float"
|
||||
|
||||
capabilities = assert_endpoint_capabilities(
|
||||
appliance, "Alexa.RangeController", "Alexa.EndpointHealth", "Alexa"
|
||||
)
|
||||
|
||||
range_capability = get_capability(
|
||||
capabilities, "Alexa.RangeController", "input_number.value"
|
||||
)
|
||||
|
||||
capability_resources = range_capability["capabilityResources"]
|
||||
assert capability_resources is not None
|
||||
assert {
|
||||
"@type": "text",
|
||||
"value": {"text": "Value", "locale": "en-US"},
|
||||
} in capability_resources["friendlyNames"]
|
||||
|
||||
configuration = range_capability["configuration"]
|
||||
assert configuration is not None
|
||||
|
||||
supported_range = configuration["supportedRange"]
|
||||
assert supported_range["minimumValue"] == 0
|
||||
assert supported_range["maximumValue"] == 1
|
||||
assert supported_range["precision"] == 0.01
|
||||
|
||||
presets = configuration["presets"]
|
||||
assert {
|
||||
"rangeValue": 1,
|
||||
"presetResources": {
|
||||
"friendlyNames": [
|
||||
{"@type": "asset", "value": {"assetId": "Alexa.Value.Maximum"}}
|
||||
]
|
||||
},
|
||||
} in presets
|
||||
|
||||
assert {
|
||||
"rangeValue": 0,
|
||||
"presetResources": {
|
||||
"friendlyNames": [
|
||||
{"@type": "asset", "value": {"assetId": "Alexa.Value.Minimum"}}
|
||||
]
|
||||
},
|
||||
} in presets
|
||||
|
||||
call, _ = await assert_request_calls_service(
|
||||
"Alexa.RangeController",
|
||||
"SetRangeValue",
|
||||
"input_number#test_slider_float",
|
||||
"input_number.set_value",
|
||||
hass,
|
||||
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")],
|
||||
"Alexa.RangeController",
|
||||
"AdjustRangeValue",
|
||||
"input_number#test_slider_float",
|
||||
False,
|
||||
"input_number.set_value",
|
||||
"value",
|
||||
instance="input_number.value",
|
||||
)
|
||||
Reference in new issue
Block a user