Handle vicare I/O in executor (#65105)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
c470733feb
commit
a9cc35d6b6
2 changed files with 49 additions and 34 deletions
|
@ -101,6 +101,15 @@ def _build_entity(name, vicare_api, circuit, device_config, heating_type):
|
|||
return ViCareClimate(name, vicare_api, device_config, circuit, heating_type)
|
||||
|
||||
|
||||
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,
|
||||
|
@ -108,25 +117,23 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the ViCare climate platform."""
|
||||
name = VICARE_NAME
|
||||
|
||||
entities = []
|
||||
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
||||
circuits = await hass.async_add_executor_job(_get_circuits, api)
|
||||
|
||||
try:
|
||||
for circuit in hass.data[DOMAIN][config_entry.entry_id][VICARE_API].circuits:
|
||||
suffix = ""
|
||||
if len(hass.data[DOMAIN][config_entry.entry_id][VICARE_API].circuits) > 1:
|
||||
suffix = f" {circuit.id}"
|
||||
entity = _build_entity(
|
||||
f"{name} Heating{suffix}",
|
||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_API],
|
||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||
circuit,
|
||||
config_entry.data[CONF_HEATING_TYPE],
|
||||
)
|
||||
if entity is not None:
|
||||
entities.append(entity)
|
||||
except PyViCareNotSupportedFeatureError:
|
||||
_LOGGER.info("No circuits found")
|
||||
for circuit in circuits:
|
||||
suffix = ""
|
||||
if len(circuits) > 1:
|
||||
suffix = f" {circuit.id}"
|
||||
|
||||
entity = _build_entity(
|
||||
f"{name} Heating{suffix}",
|
||||
api,
|
||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||
circuit,
|
||||
config_entry.data[CONF_HEATING_TYPE],
|
||||
)
|
||||
entities.append(entity)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
|
|
|
@ -68,6 +68,15 @@ def _build_entity(name, vicare_api, circuit, device_config, heating_type):
|
|||
)
|
||||
|
||||
|
||||
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,
|
||||
|
@ -75,24 +84,23 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the ViCare climate platform."""
|
||||
name = VICARE_NAME
|
||||
|
||||
entities = []
|
||||
try:
|
||||
for circuit in hass.data[DOMAIN][config_entry.entry_id][VICARE_API].circuits:
|
||||
suffix = ""
|
||||
if len(hass.data[DOMAIN][config_entry.entry_id][VICARE_API].circuits) > 1:
|
||||
suffix = f" {circuit.id}"
|
||||
entity = _build_entity(
|
||||
f"{name} Water{suffix}",
|
||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_API],
|
||||
circuit,
|
||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||
config_entry.data[CONF_HEATING_TYPE],
|
||||
)
|
||||
if entity is not None:
|
||||
entities.append(entity)
|
||||
except PyViCareNotSupportedFeatureError:
|
||||
_LOGGER.info("No circuits found")
|
||||
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
||||
circuits = await hass.async_add_executor_job(_get_circuits, api)
|
||||
|
||||
for circuit in circuits:
|
||||
suffix = ""
|
||||
if len(circuits) > 1:
|
||||
suffix = f" {circuit.id}"
|
||||
|
||||
entity = _build_entity(
|
||||
f"{name} Water{suffix}",
|
||||
api,
|
||||
circuit,
|
||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||
config_entry.data[CONF_HEATING_TYPE],
|
||||
)
|
||||
entities.append(entity)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue