Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating binary sensor for unsupported attributes #144

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion zha/application/platforms/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from dataclasses import dataclass
import functools
import logging
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any, Self

from zhaquirks.quirk_ids import DANFOSS_ALLY_THERMOSTAT
from zigpy.quirks.v2 import BinarySensorMetadata

from zha.application import Platform
from zha.application.const import ENTITY_METADATA
from zha.application.platforms import BaseEntityInfo, EntityCategory, PlatformEntity
from zha.application.platforms.binary_sensor.const import (
IAS_ZONE_CLASS_MAPPING,
Expand Down Expand Up @@ -61,6 +62,33 @@
_attribute_name: str
PLATFORM: Platform = Platform.BINARY_SENSOR

@classmethod
def create_platform_entity(
cls: type[Self],
unique_id: str,
cluster_handlers: list[ClusterHandler],
endpoint: Endpoint,
device: Device,
**kwargs: Any,
) -> Self | None:
"""Entity Factory.

Return entity if it is a supported configuration, otherwise return None
"""
cluster = cluster_handlers[0].cluster
if ENTITY_METADATA not in kwargs and (
Copy link
Contributor Author

@elupus elupus Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea why this is here, it was in one of the other handler like this.

cls._attribute_name in cluster.unsupported_attributes
or cls._attribute_name not in cluster.attributes_by_name
):
_LOGGER.debug(

Check warning on line 83 in zha/application/platforms/binary_sensor/__init__.py

View check run for this annotation

Codecov / codecov/patch

zha/application/platforms/binary_sensor/__init__.py#L83

Added line #L83 was not covered by tests
"%s is not supported - skipping %s entity creation",
cls._attribute_name,
cls.__name__,
)
return None

Check warning on line 88 in zha/application/platforms/binary_sensor/__init__.py

View check run for this annotation

Codecov / codecov/patch

zha/application/platforms/binary_sensor/__init__.py#L88

Added line #L88 was not covered by tests

return cls(unique_id, cluster_handlers, endpoint, device, **kwargs)

def __init__(
self,
unique_id: str,
Expand Down
Loading