Add vicare config flow (#56691)

* Configuration via UI

Config flow / YAML deprecation
- Support discovery via MAC address
- Support import of YAML config
- Switch to ConfigEntry, get rid of platform setup

* Fix review comments

* More tests for vicare yaml import
This commit is contained in:
Hans Oischinger 2021-11-22 15:06:42 +01:00 committed by GitHub
parent a7382c8092
commit 38b976e6d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 564 additions and 95 deletions

View file

@ -22,7 +22,12 @@ from homeassistant.components.climate.const import (
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
from homeassistant.const import (
ATTR_TEMPERATURE,
CONF_NAME,
PRECISION_WHOLE,
TEMP_CELSIUS,
)
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
@ -32,7 +37,6 @@ from .const import (
VICARE_API,
VICARE_CIRCUITS,
VICARE_DEVICE_CONFIG,
VICARE_NAME,
)
_LOGGER = logging.getLogger(__name__)
@ -99,33 +103,26 @@ def _build_entity(name, vicare_api, circuit, device_config, heating_type):
return ViCareClimate(name, vicare_api, device_config, circuit, heating_type)
async def async_setup_platform(
hass, hass_config, async_add_entities, discovery_info=None
):
"""Create the ViCare climate devices."""
# Legacy setup. Remove after configuration.yaml deprecation end
if discovery_info is None:
return
async def async_setup_entry(hass, config_entry, async_add_devices):
"""Set up the ViCare climate platform."""
name = config_entry.data[CONF_NAME]
name = hass.data[DOMAIN][VICARE_NAME]
all_devices = []
for circuit in hass.data[DOMAIN][VICARE_CIRCUITS]:
for circuit in hass.data[DOMAIN][config_entry.entry_id][VICARE_CIRCUITS]:
suffix = ""
if len(hass.data[DOMAIN][VICARE_CIRCUITS]) > 1:
if len(hass.data[DOMAIN][config_entry.entry_id][VICARE_CIRCUITS]) > 1:
suffix = f" {circuit.id}"
entity = _build_entity(
f"{name} Heating{suffix}",
hass.data[DOMAIN][VICARE_API],
hass.data[DOMAIN][VICARE_DEVICE_CONFIG],
hass.data[DOMAIN][config_entry.entry_id][VICARE_API],
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
circuit,
hass.data[DOMAIN][CONF_HEATING_TYPE],
config_entry.data[CONF_HEATING_TYPE],
)
if entity is not None:
all_devices.append(entity)
async_add_entities(all_devices)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
@ -134,6 +131,8 @@ async def async_setup_platform(
"set_vicare_mode",
)
async_add_devices(all_devices)
class ViCareClimate(ClimateEntity):
"""Representation of the ViCare heating climate device."""