From f4b0393acebdf460f99aa6ce59c764fa31f7b781 Mon Sep 17 00:00:00 2001 From: roleo Date: Sat, 26 Aug 2023 15:38:31 +0200 Subject: [PATCH] Fix yi-hack-v5 compatibility --- custom_components/yi_hack/__init__.py | 2 +- custom_components/yi_hack/binary_sensor.py | 9 ++++++++- custom_components/yi_hack/select.py | 12 ++++++------ custom_components/yi_hack/switch.py | 13 ++++++++++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/custom_components/yi_hack/__init__.py b/custom_components/yi_hack/__init__.py index a09912c..b50e741 100644 --- a/custom_components/yi_hack/__init__.py +++ b/custom_components/yi_hack/__init__.py @@ -24,7 +24,7 @@ PLATFORMS = ["camera", "binary_sensor", "media_player", "select", "switch"] PLATFORMS_SO = ["camera", "binary_sensor", "select", "switch"] -PLATFORMS_V5 = ["camera", "binary_sensor", "switch"] +PLATFORMS_V5 = ["camera", "binary_sensor", "select", "switch"] _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/yi_hack/binary_sensor.py b/custom_components/yi_hack/binary_sensor.py index d211de3..41b573b 100644 --- a/custom_components/yi_hack/binary_sensor.py +++ b/custom_components/yi_hack/binary_sensor.py @@ -34,7 +34,14 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_ YiMQTTBinarySensor(config, "motion_detection"), YiMQTTBinarySensor(config, "baby_crying"), ] - elif (config.data[CONF_HACK_NAME] == ALLWINNER) or (config.data[CONF_HACK_NAME] == V5): + elif (config.data[CONF_HACK_NAME] == V5): + entities = [ + YiMQTTBinarySensor(config, "status"), + YiMQTTBinarySensor(config, "motion_detection"), + YiMQTTBinarySensor(config, "sound_detection"), + YiMQTTBinarySensor(config, "baby_crying"), + ] + elif (config.data[CONF_HACK_NAME] == ALLWINNER): entities = [ YiMQTTBinarySensor(config, "status"), YiMQTTBinarySensor(config, "motion_detection"), diff --git a/custom_components/yi_hack/select.py b/custom_components/yi_hack/select.py index e0bcb92..fb5f86a 100644 --- a/custom_components/yi_hack/select.py +++ b/custom_components/yi_hack/select.py @@ -10,7 +10,7 @@ from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from .const import (CONF_HACK_NAME, CONF_MQTT_PREFIX, DEFAULT_BRAND, DOMAIN, - SONOFF) + SONOFF, V5) async def async_setup_entry(hass, config_entry, async_add_entities): """Set up platform.""" @@ -20,6 +20,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities): YiHackSelect(hass, config_entry, "sensitivity", [ "low", "medium", "high" ]), YiHackSelect(hass, config_entry, "ir", [ "auto", "on", "off" ]), ] + elif config_entry.data[CONF_HACK_NAME] == V5: + entities = [ + YiHackSelect(hass, config_entry, "sensitivity", [ "low", "medium", "high" ]), + YiHackSelect(hass, config_entry, "sound_sensitivity", [ "30", "35", "40", "45", "50", "60", "70", "80", "90" ]), + ] else: entities = [ YiHackSelect(hass, config_entry, "sensitivity", [ "low", "medium", "high" ]), @@ -33,13 +38,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class YiHackSelect(SelectEntity): """Select entity.""" -# _attr_entity_category = EntityCategory.CONFIG - -# def __init__(self, coordinator: Coordinator, coil: Coil) -> None: def __init__(self, hass, config, select_type, select_options): """Initialize entity.""" -# assert coil.mappings -# super().__init__(coordinator, coil, ENTITY_ID_FORMAT) self._device_name = config.data[CONF_NAME] self._mac = config.data[CONF_MAC] self._name = self._device_name + "_select_" + select_type diff --git a/custom_components/yi_hack/switch.py b/custom_components/yi_hack/switch.py index 1695c13..0e86537 100644 --- a/custom_components/yi_hack/switch.py +++ b/custom_components/yi_hack/switch.py @@ -26,7 +26,18 @@ async def async_setup_entry(hass, config_entry, async_add_entities): YiHackSwitch(hass, config_entry, "ir"), YiHackSwitch(hass, config_entry, "rotate"), ] - elif (config_entry.data[CONF_HACK_NAME] == ALLWINNER) or (config_entry.data[CONF_HACK_NAME] == V5): + elif (config_entry.data[CONF_HACK_NAME] == V5): + entities = [ + YiHackSwitch(hass, config_entry, "switch_on"), +# YiHackSwitch(hass, config_entry, "detect_motion"), + YiHackSwitch(hass, config_entry, "save_video_on_motion"), + YiHackSwitch(hass, config_entry, "sound_detection"), + YiHackSwitch(hass, config_entry, "baby_crying_detect"), + YiHackSwitch(hass, config_entry, "led"), + YiHackSwitch(hass, config_entry, "ir"), + YiHackSwitch(hass, config_entry, "rotate"), + ] + elif (config_entry.data[CONF_HACK_NAME] == ALLWINNER): entities = [ YiHackSwitch(hass, config_entry, "switch_on"), YiHackSwitch(hass, config_entry, "motion_detection"),