Christopher Fenner ea61160fd8
Reuse function to check feature support on ViCare devices (#102211)
* check feature support in utils function

* rename parameters

* restore severity

* reorder parameters

* Update .coveragerc
2023-10-19 10:55:30 +02:00

27 lines
744 B
Python

"""ViCare helpers functions."""
import logging
from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError
from . import ViCareRequiredKeysMixin
_LOGGER = logging.getLogger(__name__)
def is_supported(
name: str,
entity_description: ViCareRequiredKeysMixin,
vicare_device,
) -> bool:
"""Check if the PyViCare device supports the requested sensor."""
try:
entity_description.value_getter(vicare_device)
_LOGGER.debug("Found entity %s", name)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("Feature not supported %s", name)
return False
except AttributeError as error:
_LOGGER.debug("Attribute Error %s: %s", name, error)
return False
return True