From 9de694e251e7927411d1100d6c9ad6bf69c4b22b Mon Sep 17 00:00:00 2001 From: Hans Oischinger Date: Sat, 12 Aug 2023 10:55:51 +0200 Subject: [PATCH] Update PyViCare to 2.28.1 --- custom_components/vicare/binary_sensor.py | 15 ++++++++---- custom_components/vicare/climate.py | 21 +++++++--------- custom_components/vicare/helpers.py | 29 +++++++++++++++++++++++ custom_components/vicare/manifest.json | 2 +- custom_components/vicare/sensor.py | 15 ++++++++---- custom_components/vicare/water_heater.py | 13 ++-------- requirements_dev.txt | 2 +- 7 files changed, 64 insertions(+), 33 deletions(-) diff --git a/custom_components/vicare/binary_sensor.py b/custom_components/vicare/binary_sensor.py index ee30980..ddcf1cf 100644 --- a/custom_components/vicare/binary_sensor.py +++ b/custom_components/vicare/binary_sensor.py @@ -25,7 +25,14 @@ from . import ViCareRequiredKeysMixin from .const import DOMAIN, VICARE_DEVICE_CONFIG, VICARE_NAME -from .helpers import get_device_name, get_unique_device_id, get_unique_id +from .helpers import ( + get_burners, + get_circuits, + get_compressors, + get_device_name, + get_unique_device_id, + get_unique_id, +) _LOGGER = logging.getLogger(__name__) @@ -172,7 +179,7 @@ def create_all_entities(hass: HomeAssistant, config_entry: ConfigEntry): name, entities, CIRCUIT_SENSORS, - api.circuits, + get_circuits(api), config_entry, device, ) @@ -181,7 +188,7 @@ def create_all_entities(hass: HomeAssistant, config_entry: ConfigEntry): try: _entities_from_descriptions( - hass, name, entities, BURNER_SENSORS, api.burners, config_entry, device + hass, name, entities, BURNER_SENSORS, get_burners(api), config_entry, device ) except PyViCareNotSupportedFeatureError: _LOGGER.info("No burners found") @@ -192,7 +199,7 @@ def create_all_entities(hass: HomeAssistant, config_entry: ConfigEntry): name, entities, COMPRESSOR_SENSORS, - api.compressors, + get_compressors(api), config_entry, device, ) diff --git a/custom_components/vicare/climate.py b/custom_components/vicare/climate.py index fa7d28a..814348e 100644 --- a/custom_components/vicare/climate.py +++ b/custom_components/vicare/climate.py @@ -37,7 +37,13 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN, VICARE_DEVICE_CONFIG, VICARE_NAME -from .helpers import get_device_name, get_unique_device_id, get_unique_id +from .helpers import ( + get_burners, + get_circuits, + get_device_name, + get_unique_device_id, + get_unique_id, +) _LOGGER = logging.getLogger(__name__) @@ -101,15 +107,6 @@ } -def _get_circuits(vicare_api): - """Return the list of circuits.""" - try: - return vicare_api.circuits - except PyViCareNotSupportedFeatureError: - _LOGGER.info("No circuits found") - return [] - - async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, @@ -122,7 +119,7 @@ async def async_setup_entry( for device in hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG]: api = device.asAutoDetectDevice() - circuits = await hass.async_add_executor_job(_get_circuits, api) + circuits = await hass.async_add_executor_job(get_circuits, api) for circuit in circuits: suffix = "" if len(circuits) > 1: @@ -261,7 +258,7 @@ def update(self) -> None: self._current_action = False # Update the specific device attributes with suppress(PyViCareNotSupportedFeatureError): - for burner in self._api.burners: + for burner in get_burners(self._api): self._current_action = self._current_action or burner.getActive() with suppress(PyViCareNotSupportedFeatureError): diff --git a/custom_components/vicare/helpers.py b/custom_components/vicare/helpers.py index d553258..f322fa1 100644 --- a/custom_components/vicare/helpers.py +++ b/custom_components/vicare/helpers.py @@ -1,4 +1,6 @@ """Helpers for ViCare.""" +from PyViCare.PyViCareHeatingDevice import HeatingDevice +from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError def get_unique_id(api, device_config, entity_id) -> str: @@ -17,3 +19,30 @@ def get_unique_device_id(device_config) -> str: def get_device_name(device_config) -> str: """Return name for this device.""" return f"{device_config.getModel()}-{device_config.getConfig().id}-{device_config.getConfig().device_id}" + +def get_circuits(vicare_api): + """Return the list of circuits.""" + if not isinstance(vicare_api, HeatingDevice): + return [] + try: + return vicare_api.circuits + except PyViCareNotSupportedFeatureError: + return [] + +def get_burners(vicare_api): + """Return the list of burners.""" + if not isinstance(vicare_api, HeatingDevice): + return [] + try: + return vicare_api.burners + except PyViCareNotSupportedFeatureError: + return [] + +def get_compressors(vicare_api): + """Return the list of compressors.""" + if not isinstance(vicare_api, HeatingDevice): + return [] + try: + return vicare_api.compressors + except PyViCareNotSupportedFeatureError: + return [] \ No newline at end of file diff --git a/custom_components/vicare/manifest.json b/custom_components/vicare/manifest.json index 58dee17..d55d2a7 100644 --- a/custom_components/vicare/manifest.json +++ b/custom_components/vicare/manifest.json @@ -11,6 +11,6 @@ "documentation": "https://www.home-assistant.io/integrations/vicare", "iot_class": "cloud_polling", "loggers": ["PyViCare"], - "requirements": ["PyViCare==2.25.0"], + "requirements": ["PyViCare==2.28.1"], "version": "2.0.0" } diff --git a/custom_components/vicare/sensor.py b/custom_components/vicare/sensor.py index b20865c..6e177a1 100644 --- a/custom_components/vicare/sensor.py +++ b/custom_components/vicare/sensor.py @@ -43,7 +43,14 @@ VICARE_NAME, VICARE_UNIT_TO_UNIT_OF_MEASUREMENT, ) -from .helpers import get_device_name, get_unique_device_id, get_unique_id +from .helpers import ( + get_burners, + get_circuits, + get_compressors, + get_device_name, + get_unique_device_id, + get_unique_id, +) _LOGGER = logging.getLogger(__name__) @@ -666,7 +673,7 @@ def create_all_entities(hass: HomeAssistant, config_entry: ConfigEntry): name, entities, CIRCUIT_SENSORS, - api.circuits, + get_circuits(api), config_entry, device, ) @@ -675,7 +682,7 @@ def create_all_entities(hass: HomeAssistant, config_entry: ConfigEntry): try: _entities_from_descriptions( - hass, name, entities, BURNER_SENSORS, api.burners, config_entry, device + hass, name, entities, BURNER_SENSORS, get_burners(api), config_entry, device ) except PyViCareNotSupportedFeatureError: _LOGGER.info("No burners found") @@ -686,7 +693,7 @@ def create_all_entities(hass: HomeAssistant, config_entry: ConfigEntry): name, entities, COMPRESSOR_SENSORS, - api.compressors, + get_compressors(api), config_entry, device, ) diff --git a/custom_components/vicare/water_heater.py b/custom_components/vicare/water_heater.py index ee20fc9..49169f1 100644 --- a/custom_components/vicare/water_heater.py +++ b/custom_components/vicare/water_heater.py @@ -26,7 +26,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN, VICARE_DEVICE_CONFIG, VICARE_NAME -from .helpers import get_device_name, get_unique_device_id, get_unique_id +from .helpers import get_circuits, get_device_name, get_unique_device_id, get_unique_id _LOGGER = logging.getLogger(__name__) @@ -60,15 +60,6 @@ } -def _get_circuits(vicare_api): - """Return the list of circuits.""" - try: - return vicare_api.circuits - except PyViCareNotSupportedFeatureError: - _LOGGER.info("No circuits found") - return [] - - async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, @@ -81,7 +72,7 @@ async def async_setup_entry( for device in hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG]: api = device.asAutoDetectDevice() - circuits = await hass.async_add_executor_job(_get_circuits, api) + circuits = await hass.async_add_executor_job(get_circuits, api) for circuit in circuits: suffix = "" if len(circuits) > 1: diff --git a/requirements_dev.txt b/requirements_dev.txt index 3b7e579..cd0d353 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,2 +1,2 @@ -PyViCare == 2.25.0 +PyViCare >= 2.28.1 homeassistant >= 2023.4.1