Skip to content

Commit

Permalink
Fix yi-hack-v5 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
roleoroleo committed Aug 26, 2023
1 parent 2723243 commit f4b0393
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion custom_components/yi_hack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
9 changes: 8 additions & 1 deletion custom_components/yi_hack/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
12 changes: 6 additions & 6 deletions custom_components/yi_hack/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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" ]),
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion custom_components/yi_hack/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit f4b0393

Please sign in to comment.