Handle clamped fan maxValue in homekit_controller (#51088)

This commit is contained in:
J. Nick Koston 2021-05-25 16:06:17 -05:00 committed by GitHub
parent 3a6a1a4d6b
commit deb9135707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 307 additions and 1 deletions

View File

@ -84,7 +84,8 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity):
def speed_count(self):
"""Speed count for the fan."""
return round(
100 / max(1, self.service[CharacteristicsTypes.ROTATION_SPEED].minStep or 0)
min(self.service[CharacteristicsTypes.ROTATION_SPEED].maxValue or 100, 100)
/ max(1, self.service[CharacteristicsTypes.ROTATION_SPEED].minStep or 0)
)
async def async_set_direction(self, direction):

View File

@ -0,0 +1,48 @@
"""Make sure that a H.A.A. fan can be setup."""
from homeassistant.helpers import device_registry as dr, entity_registry as er
from tests.components.homekit_controller.common import (
Helper,
setup_accessories_from_file,
setup_test_accessories,
)
async def test_haa_fan_setup(hass):
"""Test that a H.A.A. fan can be correctly setup in HA."""
accessories = await setup_accessories_from_file(hass, "haa_fan.json")
config_entry, pairing = await setup_test_accessories(hass, accessories)
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
# Check that the switch entity is handled correctly
entry = entity_registry.async_get("switch.haa_c718b3")
assert entry.unique_id == "homekit-C718B3-2-8"
helper = Helper(hass, "switch.haa_c718b3", pairing, accessories[0], config_entry)
state = await helper.poll_and_get_state()
assert state.attributes["friendly_name"] == "HAA-C718B3"
device = device_registry.async_get(entry.device_id)
assert device.manufacturer == "José A. Jiménez Campos"
assert device.name == "HAA-C718B3"
assert device.sw_version == "5.0.18"
assert device.via_device_id is not None
# Assert the fan is detected
entry = entity_registry.async_get("fan.haa_c718b3")
assert entry.unique_id == "homekit-C718B3-1-8"
helper = Helper(
hass,
"fan.haa_c718b3",
pairing,
accessories[0],
config_entry,
)
state = await helper.poll_and_get_state()
assert state.attributes["friendly_name"] == "HAA-C718B3"
assert round(state.attributes["percentage_step"], 2) == 33.33

View File

@ -0,0 +1,257 @@
[
{
"aid": 1,
"services": [
{
"iid": 1,
"type": "0000003E-0000-1000-8000-0026BB765291",
"primary": false,
"hidden": false,
"characteristics": [
{
"aid": 2,
"iid": 2,
"type": "00000023-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "HAA-C718B3"
},
{
"aid": 2,
"iid": 3,
"type": "00000020-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "Jos\u00e9 A. Jim\u00e9nez Campos"
},
{
"aid": 1,
"iid": 4,
"type": "00000030-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "C718B3-1"
},
{
"aid": 2,
"iid": 5,
"type": "00000021-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "RavenSystem HAA"
},
{
"aid": 2,
"iid": 6,
"type": "00000052-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "5.0.18"
},
{
"aid": 2,
"iid": 7,
"type": "00000014-0000-1000-8000-0026BB765291",
"perms": [
"pw"
],
"format": "bool"
}
]
},
{
"iid": 8,
"type": "00000040-0000-1000-8000-0026BB765291",
"primary": true,
"hidden": false,
"characteristics": [
{
"aid": 1,
"iid": 9,
"type": "00000025-0000-1000-8000-0026BB765291",
"perms": [
"pr",
"pw",
"ev"
],
"ev": true,
"format": "bool",
"value": false
},
{
"aid": 1,
"iid": 10,
"type": "00000029-0000-1000-8000-0026BB765291",
"perms": [
"pr",
"pw",
"ev"
],
"ev": true,
"format": "float",
"unit": "percentage",
"minValue": 0,
"maxValue": 3,
"minStep": 1,
"value": 3
}
]
},
{
"iid": 1000,
"type": "000000A2-0000-1000-8000-0026BB765291",
"primary": false,
"hidden": true,
"characteristics": [
{
"aid": 1,
"iid": 1001,
"type": "00000037-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "1.1.0"
}
]
},
{
"iid": 1010,
"type": "F0000100-0218-2017-81BF-AF2B7C833922",
"primary": false,
"hidden": true,
"characteristics": [
{
"aid": 1,
"iid": 1011,
"type": "F0000101-0218-2017-81BF-AF2B7C833922",
"perms": [
"pr",
"pw",
"hd"
],
"description": "Update",
"format": "string",
"value": ""
},
{
"aid": 1,
"iid": 1012,
"type": "F0000102-0218-2017-81BF-AF2B7C833922",
"perms": [
"pr",
"pw",
"hd"
],
"description": "Setup",
"format": "string",
"value": ""
}
]
}
]
},
{
"aid": 2,
"services": [
{
"iid": 1,
"type": "0000003E-0000-1000-8000-0026BB765291",
"primary": false,
"hidden": false,
"characteristics": [
{
"aid": 2,
"iid": 2,
"type": "00000023-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "HAA-C718B3"
},
{
"aid": 2,
"iid": 3,
"type": "00000020-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "Jos\u00e9 A. Jim\u00e9nez Campos"
},
{
"aid": 2,
"iid": 4,
"type": "00000030-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "C718B3-2"
},
{
"aid": 2,
"iid": 5,
"type": "00000021-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "RavenSystem HAA"
},
{
"aid": 2,
"iid": 6,
"type": "00000052-0000-1000-8000-0026BB765291",
"perms": [
"pr"
],
"format": "string",
"value": "5.0.18"
},
{
"aid": 2,
"iid": 7,
"type": "00000014-0000-1000-8000-0026BB765291",
"perms": [
"pw"
],
"format": "bool"
}
]
},
{
"iid": 8,
"type": "00000049-0000-1000-8000-0026BB765291",
"primary": true,
"hidden": false,
"characteristics": [
{
"aid": 2,
"iid": 9,
"type": "00000025-0000-1000-8000-0026BB765291",
"perms": [
"pr",
"pw",
"ev"
],
"ev": true,
"format": "bool",
"value": false
}
]
}
]
}
]