mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Handle vicare I/O in executor (#65105)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
c470733feb
commit
a9cc35d6b6
@ -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)
|
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(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
@ -108,25 +117,23 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the ViCare climate platform."""
|
"""Set up the ViCare climate platform."""
|
||||||
name = VICARE_NAME
|
name = VICARE_NAME
|
||||||
|
|
||||||
entities = []
|
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 circuits:
|
||||||
for circuit in hass.data[DOMAIN][config_entry.entry_id][VICARE_API].circuits:
|
|
||||||
suffix = ""
|
suffix = ""
|
||||||
if len(hass.data[DOMAIN][config_entry.entry_id][VICARE_API].circuits) > 1:
|
if len(circuits) > 1:
|
||||||
suffix = f" {circuit.id}"
|
suffix = f" {circuit.id}"
|
||||||
|
|
||||||
entity = _build_entity(
|
entity = _build_entity(
|
||||||
f"{name} Heating{suffix}",
|
f"{name} Heating{suffix}",
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_API],
|
api,
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||||
circuit,
|
circuit,
|
||||||
config_entry.data[CONF_HEATING_TYPE],
|
config_entry.data[CONF_HEATING_TYPE],
|
||||||
)
|
)
|
||||||
if entity is not None:
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
except PyViCareNotSupportedFeatureError:
|
|
||||||
_LOGGER.info("No circuits found")
|
|
||||||
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
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(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
@ -75,24 +84,23 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the ViCare climate platform."""
|
"""Set up the ViCare climate platform."""
|
||||||
name = VICARE_NAME
|
name = VICARE_NAME
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
try:
|
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
||||||
for circuit in hass.data[DOMAIN][config_entry.entry_id][VICARE_API].circuits:
|
circuits = await hass.async_add_executor_job(_get_circuits, api)
|
||||||
|
|
||||||
|
for circuit in circuits:
|
||||||
suffix = ""
|
suffix = ""
|
||||||
if len(hass.data[DOMAIN][config_entry.entry_id][VICARE_API].circuits) > 1:
|
if len(circuits) > 1:
|
||||||
suffix = f" {circuit.id}"
|
suffix = f" {circuit.id}"
|
||||||
|
|
||||||
entity = _build_entity(
|
entity = _build_entity(
|
||||||
f"{name} Water{suffix}",
|
f"{name} Water{suffix}",
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_API],
|
api,
|
||||||
circuit,
|
circuit,
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||||
config_entry.data[CONF_HEATING_TYPE],
|
config_entry.data[CONF_HEATING_TYPE],
|
||||||
)
|
)
|
||||||
if entity is not None:
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
except PyViCareNotSupportedFeatureError:
|
|
||||||
_LOGGER.info("No circuits found")
|
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user