mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Handle capitalized HomeKit property names (#21382)
The Velux ACTIVE gateway uses `C#` rather than `c#` as the name of the property that holds the count of accessories. Apple's HomeKit docs suggest that properties should be case-insensitive, so update the code to not assume the property names are lower case.
This commit is contained in:
parent
6e0186fd56
commit
3e9376c418
@ -343,9 +343,17 @@ def setup(hass, config):
|
|||||||
# model, id
|
# model, id
|
||||||
host = discovery_info['host']
|
host = discovery_info['host']
|
||||||
port = discovery_info['port']
|
port = discovery_info['port']
|
||||||
model = discovery_info['properties']['md']
|
|
||||||
hkid = discovery_info['properties']['id']
|
# Fold property keys to lower case, making them effectively
|
||||||
config_num = int(discovery_info['properties']['c#'])
|
# case-insensitive. Some HomeKit devices capitalize them.
|
||||||
|
properties = {
|
||||||
|
key.lower(): value
|
||||||
|
for (key, value) in discovery_info['properties'].items()
|
||||||
|
}
|
||||||
|
|
||||||
|
model = properties['md']
|
||||||
|
hkid = properties['id']
|
||||||
|
config_num = int(properties['c#'])
|
||||||
|
|
||||||
if model in HOMEKIT_IGNORE:
|
if model in HOMEKIT_IGNORE:
|
||||||
return
|
return
|
||||||
|
@ -134,8 +134,11 @@ class FakeService(AbstractService):
|
|||||||
return char
|
return char
|
||||||
|
|
||||||
|
|
||||||
async def setup_test_component(hass, services):
|
async def setup_test_component(hass, services, capitalize=False):
|
||||||
"""Load a fake homekit accessory based on a homekit accessory model."""
|
"""Load a fake homekit accessory based on a homekit accessory model.
|
||||||
|
|
||||||
|
If capitalize is True, property names will be in upper case.
|
||||||
|
"""
|
||||||
domain = None
|
domain = None
|
||||||
for service in services:
|
for service in services:
|
||||||
service_name = ServicesTypes.get_short(service.type)
|
service_name = ServicesTypes.get_short(service.type)
|
||||||
@ -162,9 +165,9 @@ async def setup_test_component(hass, services):
|
|||||||
'host': '127.0.0.1',
|
'host': '127.0.0.1',
|
||||||
'port': 8080,
|
'port': 8080,
|
||||||
'properties': {
|
'properties': {
|
||||||
'md': 'TestDevice',
|
('MD' if capitalize else 'md'): 'TestDevice',
|
||||||
'id': '00:00:00:00:00:00',
|
('ID' if capitalize else 'id'): '00:00:00:00:00:00',
|
||||||
'c#': 1,
|
('C#' if capitalize else 'c#'): 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,20 @@ def create_window_covering_service_with_v_tilt():
|
|||||||
return service
|
return service
|
||||||
|
|
||||||
|
|
||||||
|
async def test_accept_capitalized_property_names(hass, utcnow):
|
||||||
|
"""Test that we can handle a device with capitalized property names."""
|
||||||
|
window_cover = create_window_covering_service()
|
||||||
|
helper = await setup_test_component(hass, [window_cover], capitalize=True)
|
||||||
|
|
||||||
|
# The specific interaction we do here doesn't matter; we just need
|
||||||
|
# to do *something* to ensure that discovery properly dealt with the
|
||||||
|
# capitalized property names.
|
||||||
|
await hass.services.async_call('cover', 'open_cover', {
|
||||||
|
'entity_id': helper.entity_id,
|
||||||
|
}, blocking=True)
|
||||||
|
assert helper.characteristics[POSITION_TARGET].value == 100
|
||||||
|
|
||||||
|
|
||||||
async def test_change_window_cover_state(hass, utcnow):
|
async def test_change_window_cover_state(hass, utcnow):
|
||||||
"""Test that we can turn a HomeKit alarm on and off again."""
|
"""Test that we can turn a HomeKit alarm on and off again."""
|
||||||
window_cover = create_window_covering_service()
|
window_cover = create_window_covering_service()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user