Update YoLink FlexFob Automation (#123631)

* Change FlexFob Trigger

* Update device trigger tests
pull/124595/head
Matrix 2024-08-27 19:17:14 +08:00 committed by GitHub
parent 9119884e53
commit a45ba51f89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 7 deletions

View File

@ -23,6 +23,10 @@ DEV_MODEL_TH_SENSOR_YS8014_UC = "YS8014-UC"
DEV_MODEL_TH_SENSOR_YS8014_EC = "YS8014-EC"
DEV_MODEL_TH_SENSOR_YS8017_UC = "YS8017-UC"
DEV_MODEL_TH_SENSOR_YS8017_EC = "YS8017-EC"
DEV_MODEL_FLEX_FOB_YS3604_UC = "YS3604-UC"
DEV_MODEL_FLEX_FOB_YS3604_EC = "YS3604-EC"
DEV_MODEL_FLEX_FOB_YS3614_UC = "YS3614-UC"
DEV_MODEL_FLEX_FOB_YS3614_EC = "YS3614-EC"
DEV_MODEL_PLUG_YS6602_UC = "YS6602-UC"
DEV_MODEL_PLUG_YS6602_EC = "YS6602-EC"
DEV_MODEL_PLUG_YS6803_UC = "YS6803-UC"

View File

@ -16,6 +16,12 @@ from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
from . import DOMAIN, YOLINK_EVENT
from .const import (
DEV_MODEL_FLEX_FOB_YS3604_EC,
DEV_MODEL_FLEX_FOB_YS3604_UC,
DEV_MODEL_FLEX_FOB_YS3614_EC,
DEV_MODEL_FLEX_FOB_YS3614_UC,
)
CONF_BUTTON_1 = "button_1"
CONF_BUTTON_2 = "button_2"
@ -24,7 +30,7 @@ CONF_BUTTON_4 = "button_4"
CONF_SHORT_PRESS = "short_press"
CONF_LONG_PRESS = "long_press"
REMOTE_TRIGGER_TYPES = {
FLEX_FOB_4_BUTTONS = {
f"{CONF_BUTTON_1}_{CONF_SHORT_PRESS}",
f"{CONF_BUTTON_1}_{CONF_LONG_PRESS}",
f"{CONF_BUTTON_2}_{CONF_SHORT_PRESS}",
@ -35,14 +41,24 @@ REMOTE_TRIGGER_TYPES = {
f"{CONF_BUTTON_4}_{CONF_LONG_PRESS}",
}
FLEX_FOB_2_BUTTONS = {
f"{CONF_BUTTON_1}_{CONF_SHORT_PRESS}",
f"{CONF_BUTTON_1}_{CONF_LONG_PRESS}",
f"{CONF_BUTTON_2}_{CONF_SHORT_PRESS}",
f"{CONF_BUTTON_2}_{CONF_LONG_PRESS}",
}
TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
{vol.Required(CONF_TYPE): vol.In(REMOTE_TRIGGER_TYPES)}
{vol.Required(CONF_TYPE): vol.In(FLEX_FOB_4_BUTTONS)}
)
# YoLink Remotes YS3604/YS3605/YS3606/YS3607
DEVICE_TRIGGER_TYPES: dict[str, set[str]] = {
ATTR_DEVICE_SMART_REMOTER: REMOTE_TRIGGER_TYPES,
# YoLink Remotes YS3604/YS3614
FLEX_FOB_TRIGGER_TYPES: dict[str, set[str]] = {
DEV_MODEL_FLEX_FOB_YS3604_EC: FLEX_FOB_4_BUTTONS,
DEV_MODEL_FLEX_FOB_YS3604_UC: FLEX_FOB_4_BUTTONS,
DEV_MODEL_FLEX_FOB_YS3614_UC: FLEX_FOB_2_BUTTONS,
DEV_MODEL_FLEX_FOB_YS3614_EC: FLEX_FOB_2_BUTTONS,
}
@ -54,7 +70,8 @@ async def async_get_triggers(
registry_device = device_registry.async_get(device_id)
if not registry_device or registry_device.model != ATTR_DEVICE_SMART_REMOTER:
return []
if registry_device.model_id not in list(FLEX_FOB_TRIGGER_TYPES.keys()):
return []
return [
{
CONF_DEVICE_ID: device_id,
@ -62,7 +79,7 @@ async def async_get_triggers(
CONF_PLATFORM: "device",
CONF_TYPE: trigger,
}
for trigger in DEVICE_TRIGGER_TYPES[ATTR_DEVICE_SMART_REMOTER]
for trigger in FLEX_FOB_TRIGGER_TYPES[registry_device.model_id]
]

View File

@ -55,6 +55,7 @@ class YoLinkEntity(CoordinatorEntity[YoLinkCoordinator]):
identifiers={(DOMAIN, self.coordinator.device.device_id)},
manufacturer=MANUFACTURER,
model=self.coordinator.device.device_type,
model_id=self.coordinator.device.device_model_name,
name=self.coordinator.device.device_name,
)

View File

@ -6,6 +6,7 @@ from yolink.const import ATTR_DEVICE_DIMMER, ATTR_DEVICE_SMART_REMOTER
from homeassistant.components import automation
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.yolink import DOMAIN, YOLINK_EVENT
from homeassistant.components.yolink.const import DEV_MODEL_FLEX_FOB_YS3604_UC
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component
@ -23,6 +24,7 @@ async def test_get_triggers(
config_entry_id=config_entry.entry_id,
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
model=ATTR_DEVICE_SMART_REMOTER,
model_id=DEV_MODEL_FLEX_FOB_YS3604_UC,
)
expected_triggers = [
@ -99,6 +101,7 @@ async def test_get_triggers_exception(
config_entry_id=config_entry.entry_id,
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
model=ATTR_DEVICE_DIMMER,
model_id=None,
)
expected_triggers = []
@ -123,6 +126,7 @@ async def test_if_fires_on_event(
connections={connection},
identifiers={(DOMAIN, mac_address)},
model=ATTR_DEVICE_SMART_REMOTER,
model_id=DEV_MODEL_FLEX_FOB_YS3604_UC,
)
assert await async_setup_component(