Easier identification of devices with homekit_controller (#64804)

This commit is contained in:
Jc2k 2022-01-24 02:49:40 +00:00 committed by GitHub
parent dfa567b6e3
commit 32099ea38a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 93 additions and 8 deletions

View File

@ -45,8 +45,23 @@ BUTTON_ENTITIES: dict[str, HomeKitButtonEntityDescription] = {
entity_category=EntityCategory.CONFIG,
write_value="#HAA@trcmd",
),
CharacteristicsTypes.IDENTIFY: HomeKitButtonEntityDescription(
key=CharacteristicsTypes.IDENTIFY,
name="Identify",
entity_category=EntityCategory.DIAGNOSTIC,
write_value=True,
),
}
# For legacy reasons, "built-in" characteristic types are in their short form
# And vendor types don't have a short form
# This means long and short forms get mixed up in this dict, and comparisons
# don't work!
# We call get_uuid on *every* type to normalise them to the long form
# Eventually aiohomekit will use the long form exclusively amd this can be removed.
for k, v in list(BUTTON_ENTITIES.items()):
BUTTON_ENTITIES[CharacteristicsTypes.get_uuid(k)] = BUTTON_ENTITIES.pop(k)
async def async_setup_entry(
hass: HomeAssistant,
@ -92,7 +107,7 @@ class HomeKitButton(CharacteristicEntity, ButtonEntity):
def name(self) -> str:
"""Return the name of the device if any."""
if name := super().name:
return f"{name} - {self.entity_description.name}"
return f"{name} {self.entity_description.name}"
return f"{self.entity_description.name}"
async def async_press(self) -> None:

View File

@ -74,6 +74,7 @@ CHARACTERISTIC_PLATFORMS = {
CharacteristicsTypes.DENSITY_NO2: "sensor",
CharacteristicsTypes.DENSITY_SO2: "sensor",
CharacteristicsTypes.DENSITY_VOC: "sensor",
CharacteristicsTypes.IDENTIFY: "button",
}
# For legacy reasons, "built-in" characteristic types are in their short form

View File

@ -64,14 +64,14 @@ async def test_haa_fan_setup(hass):
),
EntityTestInfo(
entity_id="button.haa_c718b3_setup",
friendly_name="HAA-C718B3 - Setup",
friendly_name="HAA-C718B3 Setup",
unique_id="homekit-C718B3-1-aid:1-sid:1010-cid:1012",
entity_category=EntityCategory.CONFIG,
state="unknown",
),
EntityTestInfo(
entity_id="button.haa_c718b3_update",
friendly_name="HAA-C718B3 - Update",
friendly_name="HAA-C718B3 Update",
unique_id="homekit-C718B3-1-aid:1-sid:1010-cid:1011",
entity_category=EntityCategory.CONFIG,
state="unknown",

View File

@ -8,6 +8,7 @@ from aiohomekit.testing import FakePairing
import pytest
from homeassistant.components.light import SUPPORT_BRIGHTNESS, SUPPORT_COLOR
from homeassistant.helpers.entity import EntityCategory
import homeassistant.util.dt as dt_util
from tests.common import async_fire_time_changed
@ -49,6 +50,13 @@ async def test_koogeek_ls1_setup(hass):
capabilities={"supported_color_modes": ["hs"]},
state="off",
),
EntityTestInfo(
entity_id="button.koogeek_ls1_20833f_identify",
friendly_name="Koogeek-LS1-20833F Identify",
unique_id="homekit-AAAA011111111111-aid:1-sid:1-cid:6",
entity_category=EntityCategory.DIAGNOSTIC,
state="unknown",
),
],
),
)

View File

@ -97,7 +97,14 @@ async def test_enumerate_remote(hass, utcnow):
"entity_id": "sensor.testdevice_battery",
"platform": "device",
"type": "battery_level",
}
},
{
"device_id": device.id,
"domain": "button",
"entity_id": "button.testdevice_identify",
"platform": "device",
"type": "pressed",
},
]
for button in ("button1", "button2", "button3", "button4"):
@ -135,7 +142,14 @@ async def test_enumerate_button(hass, utcnow):
"entity_id": "sensor.testdevice_battery",
"platform": "device",
"type": "battery_level",
}
},
{
"device_id": device.id,
"domain": "button",
"entity_id": "button.testdevice_identify",
"platform": "device",
"type": "pressed",
},
]
for subtype in ("single_press", "double_press", "long_press"):
@ -172,7 +186,14 @@ async def test_enumerate_doorbell(hass, utcnow):
"entity_id": "sensor.testdevice_battery",
"platform": "device",
"type": "battery_level",
}
},
{
"device_id": device.id,
"domain": "button",
"entity_id": "button.testdevice_identify",
"platform": "device",
"type": "pressed",
},
]
for subtype in ("single_press", "double_press", "long_press"):

View File

@ -234,6 +234,26 @@ async def test_config_entry(hass: HomeAssistant, hass_client: ClientSession, utc
"sw_version": "2.2.15",
"hw_version": "",
"entities": [
{
"device_class": None,
"disabled": False,
"disabled_by": None,
"entity_category": "diagnostic",
"icon": None,
"original_device_class": None,
"original_icon": None,
"original_name": "Koogeek-LS1-20833F Identify",
"state": {
"attributes": {
"friendly_name": "Koogeek-LS1-20833F Identify"
},
"entity_id": "button.koogeek_ls1_20833f_identify",
"last_changed": "2023-01-01T00:00:00+00:00",
"last_updated": "2023-01-01T00:00:00+00:00",
"state": "unknown",
},
"unit_of_measurement": None,
},
{
"original_name": "Koogeek-LS1-20833F",
"disabled": False,
@ -255,7 +275,7 @@ async def test_config_entry(hass: HomeAssistant, hass_client: ClientSession, utc
"last_changed": "2023-01-01T00:00:00+00:00",
"last_updated": "2023-01-01T00:00:00+00:00",
},
}
},
],
}
],
@ -484,6 +504,24 @@ async def test_device(hass: HomeAssistant, hass_client: ClientSession, utcnow):
"sw_version": "2.2.15",
"hw_version": "",
"entities": [
{
"device_class": None,
"disabled": False,
"disabled_by": None,
"entity_category": "diagnostic",
"icon": None,
"original_device_class": None,
"original_icon": None,
"original_name": "Koogeek-LS1-20833F Identify",
"state": {
"attributes": {"friendly_name": "Koogeek-LS1-20833F Identify"},
"entity_id": "button.koogeek_ls1_20833f_identify",
"last_changed": "2023-01-01T00:00:00+00:00",
"last_updated": "2023-01-01T00:00:00+00:00",
"state": "unknown",
},
"unit_of_measurement": None,
},
{
"original_name": "Koogeek-LS1-20833F",
"disabled": False,
@ -505,7 +543,7 @@ async def test_device(hass: HomeAssistant, hass_client: ClientSession, utcnow):
"last_changed": "2023-01-01T00:00:00+00:00",
"last_updated": "2023-01-01T00:00:00+00:00",
},
}
},
],
},
}

View File

@ -89,6 +89,8 @@ async def test_temperature_sensor_not_added_twice(hass, utcnow):
)
for state in hass.states.async_all():
if state.entity_id.startswith("button"):
continue
assert state.entity_id == helper.entity_id