2023-10-19 08:55:30 +00:00
|
|
|
"""ViCare helpers functions."""
|
|
|
|
import logging
|
|
|
|
|
2023-11-25 14:47:45 +00:00
|
|
|
from PyViCare.PyViCareDevice import Device as PyViCareDevice
|
|
|
|
from PyViCare.PyViCareHeatingDevice import (
|
|
|
|
HeatingDeviceWithComponent as PyViCareHeatingDeviceComponent,
|
|
|
|
)
|
2023-10-19 08:55:30 +00:00
|
|
|
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)
|
2023-12-28 08:35:39 +00:00
|
|
|
return True
|
2023-10-19 08:55:30 +00:00
|
|
|
except PyViCareNotSupportedFeatureError:
|
2023-12-28 08:35:39 +00:00
|
|
|
_LOGGER.debug("Feature not supported %s", name)
|
2023-10-19 08:55:30 +00:00
|
|
|
except AttributeError as error:
|
2023-12-28 08:35:39 +00:00
|
|
|
_LOGGER.debug("Feature not supported %s: %s", name, error)
|
|
|
|
return False
|
2023-11-25 14:47:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_burners(device: PyViCareDevice) -> list[PyViCareHeatingDeviceComponent]:
|
|
|
|
"""Return the list of burners."""
|
|
|
|
try:
|
|
|
|
return device.burners
|
|
|
|
except PyViCareNotSupportedFeatureError:
|
|
|
|
_LOGGER.debug("No burners found")
|
2023-12-28 08:35:39 +00:00
|
|
|
except AttributeError as error:
|
|
|
|
_LOGGER.debug("No burners found: %s", error)
|
2023-11-25 14:47:45 +00:00
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
def get_circuits(device: PyViCareDevice) -> list[PyViCareHeatingDeviceComponent]:
|
|
|
|
"""Return the list of circuits."""
|
|
|
|
try:
|
|
|
|
return device.circuits
|
|
|
|
except PyViCareNotSupportedFeatureError:
|
|
|
|
_LOGGER.debug("No circuits found")
|
2023-12-28 08:35:39 +00:00
|
|
|
except AttributeError as error:
|
|
|
|
_LOGGER.debug("No circuits found: %s", error)
|
2023-11-25 14:47:45 +00:00
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
def get_compressors(device: PyViCareDevice) -> list[PyViCareHeatingDeviceComponent]:
|
|
|
|
"""Return the list of compressors."""
|
|
|
|
try:
|
|
|
|
return device.compressors
|
|
|
|
except PyViCareNotSupportedFeatureError:
|
|
|
|
_LOGGER.debug("No compressors found")
|
2023-12-28 08:35:39 +00:00
|
|
|
except AttributeError as error:
|
|
|
|
_LOGGER.debug("No compressors found: %s", error)
|
2023-11-25 14:47:45 +00:00
|
|
|
return []
|