Fix async issue in ViCare integration (#104541)

* use async executor for get_circuits

* use async executor for get_burners and get_compressors
This commit is contained in:
Christopher Fenner 2023-11-26 15:28:58 +01:00 committed by GitHub
parent 14387cf94b
commit ad17acc6ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 13 deletions

View File

@ -159,16 +159,19 @@ async def async_setup_entry(
if entity is not None: if entity is not None:
entities.append(entity) entities.append(entity)
circuits = await hass.async_add_executor_job(get_circuits, api)
await _entities_from_descriptions( await _entities_from_descriptions(
hass, entities, CIRCUIT_SENSORS, get_circuits(api), config_entry hass, entities, CIRCUIT_SENSORS, circuits, config_entry
) )
burners = await hass.async_add_executor_job(get_burners, api)
await _entities_from_descriptions( await _entities_from_descriptions(
hass, entities, BURNER_SENSORS, get_burners(api), config_entry hass, entities, BURNER_SENSORS, burners, config_entry
) )
compressors = await hass.async_add_executor_job(get_compressors, api)
await _entities_from_descriptions( await _entities_from_descriptions(
hass, entities, COMPRESSOR_SENSORS, get_compressors(api), config_entry hass, entities, COMPRESSOR_SENSORS, compressors, config_entry
) )
async_add_entities(entities) async_add_entities(entities)

View File

@ -103,7 +103,7 @@ async def async_setup_entry(
entities = [] entities = []
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API] api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
device_config = hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG] device_config = hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG]
circuits = get_circuits(api) circuits = await hass.async_add_executor_job(get_circuits, api)
for circuit in circuits: for circuit in circuits:
entity = ViCareClimate( entity = ViCareClimate(
@ -154,7 +154,7 @@ class ViCareClimate(ViCareEntity, ClimateEntity):
self._current_program = None self._current_program = None
self._attr_translation_key = translation_key self._attr_translation_key = translation_key
def update(self) -> None: async def async_update(self) -> None:
"""Let HA know there has been an update from the ViCare API.""" """Let HA know there has been an update from the ViCare API."""
try: try:
_room_temperature = None _room_temperature = None
@ -205,11 +205,15 @@ class ViCareClimate(ViCareEntity, ClimateEntity):
self._current_action = False self._current_action = False
# Update the specific device attributes # Update the specific device attributes
with suppress(PyViCareNotSupportedFeatureError): with suppress(PyViCareNotSupportedFeatureError):
for burner in get_burners(self._api): burners = await self.hass.async_add_executor_job(get_burners, self._api)
for burner in burners:
self._current_action = self._current_action or burner.getActive() self._current_action = self._current_action or burner.getActive()
with suppress(PyViCareNotSupportedFeatureError): with suppress(PyViCareNotSupportedFeatureError):
for compressor in get_compressors(self._api): compressors = await self.hass.async_add_executor_job(
get_compressors, self._api
)
for compressor in compressors:
self._current_action = ( self._current_action = (
self._current_action or compressor.getActive() self._current_action or compressor.getActive()
) )

View File

@ -28,7 +28,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ViCareRequiredKeysMixin from . import ViCareRequiredKeysMixin
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG
from .entity import ViCareEntity from .entity import ViCareEntity
from .utils import is_supported from .utils import get_circuits, is_supported
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -93,10 +93,11 @@ async def async_setup_entry(
) -> None: ) -> None:
"""Create the ViCare number devices.""" """Create the ViCare number devices."""
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API] api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
circuits = await hass.async_add_executor_job(get_circuits, api)
entities: list[ViCareNumber] = [] entities: list[ViCareNumber] = []
try: try:
for circuit in api.circuits: for circuit in circuits:
for description in CIRCUIT_ENTITY_DESCRIPTIONS: for description in CIRCUIT_ENTITY_DESCRIPTIONS:
entity = await hass.async_add_executor_job( entity = await hass.async_add_executor_job(
_build_entity, _build_entity,

View File

@ -650,16 +650,19 @@ async def async_setup_entry(
if entity is not None: if entity is not None:
entities.append(entity) entities.append(entity)
circuits = await hass.async_add_executor_job(get_circuits, api)
await _entities_from_descriptions( await _entities_from_descriptions(
hass, entities, CIRCUIT_SENSORS, get_circuits(api), config_entry hass, entities, CIRCUIT_SENSORS, circuits, config_entry
) )
burners = await hass.async_add_executor_job(get_burners, api)
await _entities_from_descriptions( await _entities_from_descriptions(
hass, entities, BURNER_SENSORS, get_burners(api), config_entry hass, entities, BURNER_SENSORS, burners, config_entry
) )
compressors = await hass.async_add_executor_job(get_compressors, api)
await _entities_from_descriptions( await _entities_from_descriptions(
hass, entities, COMPRESSOR_SENSORS, get_compressors(api), config_entry hass, entities, COMPRESSOR_SENSORS, compressors, config_entry
) )
async_add_entities(entities) async_add_entities(entities)

View File

@ -67,7 +67,7 @@ async def async_setup_entry(
entities = [] entities = []
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API] api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
device_config = hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG] device_config = hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG]
circuits = get_circuits(api) circuits = await hass.async_add_executor_job(get_circuits, api)
for circuit in circuits: for circuit in circuits:
entity = ViCareWater( entity = ViCareWater(