Skip to content

Commit

Permalink
feat: support TERNCY-CM07
Browse files Browse the repository at this point in the history
- add disabled_attrs to entity description, if an service has any of the
  disabled_attrs, no entity will be created for this service
- add cover entity with tilt property
  • Loading branch information
rxwen committed May 25, 2024
1 parent ced0d15 commit 226f544
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions custom_components/terncy/core/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions custom_components/terncy/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,4 @@ async def async_stop_cover_tilt(self, **kwargs) -> None:


TerncyEntity.NEW["cover"] = TerncyCover
TerncyEntity.NEW[f"cover.key.tilt"] = TerncyTiltCover
11 changes: 11 additions & 0 deletions custom_components/terncy/hass/entity_descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class TerncyEntityDescription(EntityDescription):
required_attrs: list[str] | None = None
"""需要的属性,如果没有这些属性,就不创建实体"""

disabled_attrs: list[str] | None = None
"""不应存在的属性,如果有任一属性,就不创建实体"""


# region Binary Sensor

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions custom_components/terncy/profiles/before_2023_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
KEY_DISABLE_RELAY,
KEY_WALL_SWITCH,
)
from ..cover import (
ATTR_TILT_POSITION,
)

PROFILES: dict[int, list[TerncyEntityDescription]] = {
PROFILE_PIR: [
Expand Down Expand Up @@ -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: [
Expand Down
9 changes: 9 additions & 0 deletions custom_components/terncy/profiles/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
KEY_DISABLE_RELAY,
KEY_WALL_SWITCH,
)
from ..cover import (
ATTR_TILT_POSITION,
)

PROFILES: dict[int, list[TerncyEntityDescription]] = {
PROFILE_PIR: [
Expand Down Expand Up @@ -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: [
Expand Down

0 comments on commit 226f544

Please sign in to comment.