diff --git a/custom_components/terncy/core/gateway.py b/custom_components/terncy/core/gateway.py index 044934f..90eca6a 100644 --- a/custom_components/terncy/core/gateway.py +++ b/custom_components/terncy/core/gateway.py @@ -526,6 +526,15 @@ def setup_device(self, device_data: PhysicalDeviceData, svc_list: list[SvcData]) or set(description.required_attrs).issubset(attrs) ) ] + descriptions = [ + description + for description in descriptions + if ( + not description.disabled_attrs + or not set(description.disabled_attrs).issubset(attrs) + ) + ] + if len(descriptions) > 0: identifiers = {(DOMAIN, eid)} device_registry.async_get_or_create( diff --git a/custom_components/terncy/cover.py b/custom_components/terncy/cover.py index f53f384..69b9ba4 100644 --- a/custom_components/terncy/cover.py +++ b/custom_components/terncy/cover.py @@ -142,3 +142,4 @@ async def async_stop_cover_tilt(self, **kwargs) -> None: TerncyEntity.NEW["cover"] = TerncyCover +TerncyEntity.NEW[f"cover.key.tilt"] = TerncyTiltCover diff --git a/custom_components/terncy/hass/entity_descriptions.py b/custom_components/terncy/hass/entity_descriptions.py index 955f4c9..0dee352 100644 --- a/custom_components/terncy/hass/entity_descriptions.py +++ b/custom_components/terncy/hass/entity_descriptions.py @@ -53,6 +53,9 @@ class TerncyEntityDescription(EntityDescription): required_attrs: list[str] | None = None """需要的属性,如果没有这些属性,就不创建实体""" + disabled_attrs: list[str] | None = None + """不应存在的属性,如果有任一属性,就不创建实体""" + # region Binary Sensor @@ -93,6 +96,14 @@ class TerncyCoverDescription(TerncyEntityDescription, CoverEntityDescription): name: str | UndefinedType | None = None +@dataclass(frozen=FROZEN_ENTITY_DESCRIPTION, kw_only=True) +class TerncyTiltCoverDescription(TerncyEntityDescription, CoverEntityDescription): + key: str = "tilt" + PLATFORM: Platform = Platform.COVER + has_entity_name: bool = True + name: str | UndefinedType | None = None + + # endregion # region Event diff --git a/custom_components/terncy/profiles/before_2023_7.py b/custom_components/terncy/profiles/before_2023_7.py index 5317579..a0d11fb 100644 --- a/custom_components/terncy/profiles/before_2023_7.py +++ b/custom_components/terncy/profiles/before_2023_7.py @@ -64,6 +64,9 @@ KEY_DISABLE_RELAY, KEY_WALL_SWITCH, ) +from ..cover import ( + ATTR_TILT_POSITION, +) PROFILES: dict[int, list[TerncyEntityDescription]] = { PROFILE_PIR: [ @@ -152,6 +155,12 @@ TerncyCoverDescription( key="cover", device_class=CoverDeviceClass.CURTAIN, + disabled_attrs = [ATTR_TILT_POSITION], + ), + TerncyCoverDescription( + key="cover", + device_class=CoverDeviceClass.CURTAIN, + required_attrs = [ATTR_TILT_POSITION], ), ], PROFILE_YAN_BUTTON: [ diff --git a/custom_components/terncy/profiles/profiles.py b/custom_components/terncy/profiles/profiles.py index b6e5375..4fda286 100644 --- a/custom_components/terncy/profiles/profiles.py +++ b/custom_components/terncy/profiles/profiles.py @@ -57,6 +57,9 @@ KEY_DISABLE_RELAY, KEY_WALL_SWITCH, ) +from ..cover import ( + ATTR_TILT_POSITION, +) PROFILES: dict[int, list[TerncyEntityDescription]] = { PROFILE_PIR: [ @@ -147,6 +150,12 @@ TerncyCoverDescription( key="cover", device_class=CoverDeviceClass.CURTAIN, + disabled_attrs = [ATTR_TILT_POSITION], + ), + TerncyCoverDescription( + key="cover", + device_class=CoverDeviceClass.CURTAIN, + required_attrs = [ATTR_TILT_POSITION], ), ], PROFILE_YAN_BUTTON: [