1 """ViCare helpers functions."""
5 from PyViCare.PyViCareDevice
import Device
as PyViCareDevice
6 from PyViCare.PyViCareDeviceConfig
import PyViCareDeviceConfig
7 from PyViCare.PyViCareHeatingDevice
import (
8 HeatingDeviceWithComponent
as PyViCareHeatingDeviceComponent,
10 from PyViCare.PyViCareUtils
import (
11 PyViCareInvalidDataError,
12 PyViCareNotSupportedFeatureError,
13 PyViCareRateLimitError,
19 from .const
import CONF_HEATING_TYPE, HEATING_TYPE_TO_CREATOR_METHOD, HeatingType
20 from .types
import ViCareRequiredKeysMixin
22 _LOGGER = logging.getLogger(__name__)
26 entry: ConfigEntry, device_config: PyViCareDeviceConfig
28 """Get device for device config."""
31 HEATING_TYPE_TO_CREATOR_METHOD[
HeatingType(entry.data[CONF_HEATING_TYPE])],
36 """Get device serial for device if supported."""
38 return device.getSerial()
39 except PyViCareNotSupportedFeatureError:
40 _LOGGER.debug(
"Device does not offer a 'device.serial' data point")
41 except PyViCareRateLimitError
as limit_exception:
42 _LOGGER.debug(
"Vicare API rate limit exceeded: %s", limit_exception)
43 except PyViCareInvalidDataError
as invalid_data_exception:
44 _LOGGER.debug(
"Invalid data from Vicare server: %s", invalid_data_exception)
45 except requests.exceptions.ConnectionError:
46 _LOGGER.debug(
"Unable to retrieve data from ViCare server")
48 _LOGGER.debug(
"Unable to decode data from ViCare server")
54 entity_description: ViCareRequiredKeysMixin,
57 """Check if the PyViCare device supports the requested sensor."""
59 entity_description.value_getter(vicare_device)
60 except PyViCareNotSupportedFeatureError:
61 _LOGGER.debug(
"Feature not supported %s", name)
63 except AttributeError
as error:
64 _LOGGER.debug(
"Feature not supported %s: %s", name, error)
66 _LOGGER.debug(
"Found entity %s", name)
70 def get_burners(device: PyViCareDevice) -> list[PyViCareHeatingDeviceComponent]:
71 """Return the list of burners."""
74 except PyViCareNotSupportedFeatureError:
75 _LOGGER.debug(
"No burners found")
76 except AttributeError
as error:
77 _LOGGER.debug(
"No burners found: %s", error)
81 def get_circuits(device: PyViCareDevice) -> list[PyViCareHeatingDeviceComponent]:
82 """Return the list of circuits."""
84 return device.circuits
85 except PyViCareNotSupportedFeatureError:
86 _LOGGER.debug(
"No circuits found")
87 except AttributeError
as error:
88 _LOGGER.debug(
"No circuits found: %s", error)
92 def get_compressors(device: PyViCareDevice) -> list[PyViCareHeatingDeviceComponent]:
93 """Return the list of compressors."""
95 return device.compressors
96 except PyViCareNotSupportedFeatureError:
97 _LOGGER.debug(
"No compressors found")
98 except AttributeError
as error:
99 _LOGGER.debug(
"No compressors found: %s", error)
str|None get_device_serial(PyViCareDevice device)
list[PyViCareHeatingDeviceComponent] get_compressors(PyViCareDevice device)
PyViCareDevice get_device(ConfigEntry entry, PyViCareDeviceConfig device_config)
bool is_supported(str name, ViCareRequiredKeysMixin entity_description, vicare_device)
list[PyViCareHeatingDeviceComponent] get_circuits(PyViCareDevice device)
list[PyViCareHeatingDeviceComponent] get_burners(PyViCareDevice device)