mirror of
https://github.com/home-assistant/core.git
synced 2026-11-26 15:47:16 -04:00
Cleanup HomeKit names to avoid unknown error when adding (#62831)
This commit is contained in:
@@ -167,3 +167,41 @@ async def test_activity_remote(hass, hk_driver, events, caplog):
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert call_reset_accessory[0].data[ATTR_ENTITY_ID] == entity_id
|
||||
|
||||
|
||||
async def test_activity_remote_bad_names(hass, hk_driver, events, caplog):
|
||||
"""Test if remote accessory with invalid names works as expected."""
|
||||
entity_id = "remote.harmony"
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
None,
|
||||
{
|
||||
ATTR_SUPPORTED_FEATURES: SUPPORT_ACTIVITY,
|
||||
ATTR_CURRENT_ACTIVITY: "Apple TV",
|
||||
ATTR_ACTIVITY_LIST: ["TV", "Apple TV", "[[[--Special--]]]", "Super"],
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = ActivityRemote(hass, hk_driver, "ActivityRemote", entity_id, 2, None)
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 31 # Television
|
||||
|
||||
assert acc.char_active.value == 0
|
||||
assert acc.char_remote_key.value == 0
|
||||
assert acc.char_input_source.value == 1
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
{
|
||||
ATTR_SUPPORTED_FEATURES: SUPPORT_ACTIVITY,
|
||||
ATTR_CURRENT_ACTIVITY: "[[[--Special--]]]",
|
||||
ATTR_ACTIVITY_LIST: ["TV", "Apple TV", "[[[--Special--]]]", "Super"],
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_active.value == 1
|
||||
assert acc.char_input_source.value == 2
|
||||
|
||||
@@ -366,3 +366,37 @@ async def test_sensor_restore(hass, hk_driver, events):
|
||||
|
||||
acc = get_accessory(hass, hk_driver, hass.states.get("sensor.humidity"), 2, {})
|
||||
assert acc.category == 10
|
||||
|
||||
|
||||
async def test_bad_name(hass, hk_driver):
|
||||
"""Test an entity with a bad name."""
|
||||
entity_id = "sensor.humidity"
|
||||
|
||||
hass.states.async_set(entity_id, "20")
|
||||
await hass.async_block_till_done()
|
||||
acc = HumiditySensor(hass, hk_driver, "[[Humid]]", entity_id, 2, None)
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
|
||||
assert acc.char_humidity.value == 20
|
||||
assert acc.display_name == "--Humid--"
|
||||
|
||||
|
||||
async def test_empty_name(hass, hk_driver):
|
||||
"""Test an entity with a empty name."""
|
||||
entity_id = "sensor.humidity"
|
||||
|
||||
hass.states.async_set(entity_id, "20")
|
||||
await hass.async_block_till_done()
|
||||
acc = HumiditySensor(hass, hk_driver, None, entity_id, 2, None)
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
|
||||
assert acc.char_humidity.value == 20
|
||||
assert acc.display_name is None
|
||||
|
||||
Reference in New Issue
Block a user