Fix handling package detection for latest UniFi Protect beta (#71821)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Christopher Bailey 2022-05-13 18:42:33 -04:00 committed by GitHub
parent f6600bbc20
commit 3e386064cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 9 deletions

View File

@ -143,7 +143,9 @@ class ProtectFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
user_input[CONF_VERIFY_SSL] = False user_input[CONF_VERIFY_SSL] = False
nvr_data, errors = await self._async_get_nvr_data(user_input) nvr_data, errors = await self._async_get_nvr_data(user_input)
if nvr_data and not errors: if nvr_data and not errors:
return self._async_create_entry(nvr_data.name, user_input) return self._async_create_entry(
nvr_data.name or nvr_data.type, user_input
)
placeholders = { placeholders = {
"name": discovery_info["hostname"] "name": discovery_info["hostname"]
@ -289,7 +291,9 @@ class ProtectFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
await self.async_set_unique_id(nvr_data.mac) await self.async_set_unique_id(nvr_data.mac)
self._abort_if_unique_id_configured() self._abort_if_unique_id_configured()
return self._async_create_entry(nvr_data.name, user_input) return self._async_create_entry(
nvr_data.name or nvr_data.type, user_input
)
user_input = user_input or {} user_input = user_input or {}
return self.async_show_form( return self.async_show_form(

View File

@ -3,7 +3,7 @@
"name": "UniFi Protect", "name": "UniFi Protect",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/unifiprotect", "documentation": "https://www.home-assistant.io/integrations/unifiprotect",
"requirements": ["pyunifiprotect==3.4.1", "unifi-discovery==1.1.2"], "requirements": ["pyunifiprotect==3.5.1", "unifi-discovery==1.1.2"],
"dependencies": ["http"], "dependencies": ["http"],
"codeowners": ["@briis", "@AngellusMortis", "@bdraco"], "codeowners": ["@briis", "@AngellusMortis", "@bdraco"],
"quality_scale": "platinum", "quality_scale": "platinum",

View File

@ -140,7 +140,7 @@ def _get_doorbell_options(api: ProtectApiClient) -> list[dict[str, Any]]:
def _get_paired_camera_options(api: ProtectApiClient) -> list[dict[str, Any]]: def _get_paired_camera_options(api: ProtectApiClient) -> list[dict[str, Any]]:
options = [{"id": TYPE_EMPTY_VALUE, "name": "Not Paired"}] options = [{"id": TYPE_EMPTY_VALUE, "name": "Not Paired"}]
for camera in api.bootstrap.cameras.values(): for camera in api.bootstrap.cameras.values():
options.append({"id": camera.id, "name": camera.name}) options.append({"id": camera.id, "name": camera.name or camera.type})
return options return options

View File

@ -159,6 +159,15 @@ CAMERA_SWITCHES: tuple[ProtectSwitchEntityDescription, ...] = (
ufp_value="is_face_detection_on", ufp_value="is_face_detection_on",
ufp_set_method="set_face_detection", ufp_set_method="set_face_detection",
), ),
ProtectSwitchEntityDescription(
key="smart_package",
name="Detections: Package",
icon="mdi:package-variant-closed",
entity_category=EntityCategory.CONFIG,
ufp_required_field="can_detect_package",
ufp_value="is_package_detection_on",
ufp_set_method="set_package_detection",
),
) )
SENSE_SWITCHES: tuple[ProtectSwitchEntityDescription, ...] = ( SENSE_SWITCHES: tuple[ProtectSwitchEntityDescription, ...] = (

View File

@ -1981,7 +1981,7 @@ pytrafikverket==0.2.0.1
pyudev==0.22.0 pyudev==0.22.0
# homeassistant.components.unifiprotect # homeassistant.components.unifiprotect
pyunifiprotect==3.4.1 pyunifiprotect==3.5.1
# homeassistant.components.uptimerobot # homeassistant.components.uptimerobot
pyuptimerobot==22.2.0 pyuptimerobot==22.2.0

View File

@ -1310,7 +1310,7 @@ pytrafikverket==0.2.0.1
pyudev==0.22.0 pyudev==0.22.0
# homeassistant.components.unifiprotect # homeassistant.components.unifiprotect
pyunifiprotect==3.4.1 pyunifiprotect==3.5.1
# homeassistant.components.uptimerobot # homeassistant.components.uptimerobot
pyuptimerobot==22.2.0 pyuptimerobot==22.2.0

View File

@ -26,9 +26,13 @@ from .conftest import (
ids_from_device_description, ids_from_device_description,
) )
CAMERA_SWITCHES_NO_FACE = [d for d in CAMERA_SWITCHES if d.name != "Detections: Face"] CAMERA_SWITCHES_BASIC = [
d
for d in CAMERA_SWITCHES
if d.name != "Detections: Face" and d.name != "Detections: Package"
]
CAMERA_SWITCHES_NO_EXTRA = [ CAMERA_SWITCHES_NO_EXTRA = [
d for d in CAMERA_SWITCHES_NO_FACE if d.name not in ("High FPS", "Privacy Mode") d for d in CAMERA_SWITCHES_BASIC if d.name not in ("High FPS", "Privacy Mode")
] ]
@ -253,7 +257,7 @@ async def test_switch_setup_camera_all(
entity_registry = er.async_get(hass) entity_registry = er.async_get(hass)
for description in CAMERA_SWITCHES_NO_FACE: for description in CAMERA_SWITCHES_BASIC:
unique_id, entity_id = ids_from_device_description( unique_id, entity_id = ids_from_device_description(
Platform.SWITCH, camera, description Platform.SWITCH, camera, description
) )