2019-09-06 20:09:03 +00:00
|
|
|
"""The ViCare integration."""
|
2019-11-04 19:12:43 +00:00
|
|
|
import enum
|
2019-09-06 20:09:03 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from PyViCare.PyViCareDevice import Device
|
2019-11-04 19:12:43 +00:00
|
|
|
from PyViCare.PyViCareGazBoiler import GazBoiler
|
|
|
|
from PyViCare.PyViCareHeatPump import HeatPump
|
2019-12-09 12:13:33 +00:00
|
|
|
import voluptuous as vol
|
2019-09-06 20:09:03 +00:00
|
|
|
|
2019-12-09 12:13:33 +00:00
|
|
|
from homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
2019-09-06 20:09:03 +00:00
|
|
|
from homeassistant.helpers import discovery
|
2019-12-09 12:13:33 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2019-09-06 20:09:03 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
VICARE_PLATFORMS = ["climate", "water_heater"]
|
|
|
|
|
|
|
|
DOMAIN = "vicare"
|
|
|
|
VICARE_API = "api"
|
|
|
|
VICARE_NAME = "name"
|
2019-11-04 19:12:43 +00:00
|
|
|
VICARE_HEATING_TYPE = "heating_type"
|
2019-09-06 20:09:03 +00:00
|
|
|
|
|
|
|
CONF_CIRCUIT = "circuit"
|
2019-11-04 19:12:43 +00:00
|
|
|
CONF_HEATING_TYPE = "heating_type"
|
|
|
|
DEFAULT_HEATING_TYPE = "generic"
|
|
|
|
|
|
|
|
|
|
|
|
class HeatingType(enum.Enum):
|
|
|
|
"""Possible options for heating type."""
|
|
|
|
|
|
|
|
generic = "generic"
|
|
|
|
gas = "gas"
|
|
|
|
heatpump = "heatpump"
|
|
|
|
|
2019-09-06 20:09:03 +00:00
|
|
|
|
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
|
|
{
|
|
|
|
DOMAIN: vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_USERNAME): cv.string,
|
|
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
|
|
vol.Optional(CONF_CIRCUIT): int,
|
|
|
|
vol.Optional(CONF_NAME, default="ViCare"): cv.string,
|
2019-11-04 19:12:43 +00:00
|
|
|
vol.Optional(CONF_HEATING_TYPE, default=DEFAULT_HEATING_TYPE): cv.enum(
|
|
|
|
HeatingType
|
|
|
|
),
|
2019-09-06 20:09:03 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
extra=vol.ALLOW_EXTRA,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def setup(hass, config):
|
|
|
|
"""Create the ViCare component."""
|
|
|
|
conf = config[DOMAIN]
|
|
|
|
params = {"token_file": "/tmp/vicare_token.save"}
|
|
|
|
if conf.get(CONF_CIRCUIT) is not None:
|
|
|
|
params["circuit"] = conf[CONF_CIRCUIT]
|
|
|
|
|
2019-11-04 19:12:43 +00:00
|
|
|
heating_type = conf[CONF_HEATING_TYPE]
|
|
|
|
|
2019-09-06 20:09:03 +00:00
|
|
|
try:
|
2019-11-04 19:12:43 +00:00
|
|
|
if heating_type == HeatingType.gas:
|
|
|
|
vicare_api = GazBoiler(conf[CONF_USERNAME], conf[CONF_PASSWORD], **params)
|
|
|
|
elif heating_type == HeatingType.heatpump:
|
|
|
|
vicare_api = HeatPump(conf[CONF_USERNAME], conf[CONF_PASSWORD], **params)
|
|
|
|
else:
|
|
|
|
vicare_api = Device(conf[CONF_USERNAME], conf[CONF_PASSWORD], **params)
|
2019-09-06 20:09:03 +00:00
|
|
|
except AttributeError:
|
|
|
|
_LOGGER.error(
|
|
|
|
"Failed to create PyViCare API client. Please check your credentials."
|
|
|
|
)
|
|
|
|
return False
|
|
|
|
|
|
|
|
hass.data[DOMAIN] = {}
|
|
|
|
hass.data[DOMAIN][VICARE_API] = vicare_api
|
|
|
|
hass.data[DOMAIN][VICARE_NAME] = conf[CONF_NAME]
|
2019-11-04 19:12:43 +00:00
|
|
|
hass.data[DOMAIN][VICARE_HEATING_TYPE] = heating_type
|
2019-09-06 20:09:03 +00:00
|
|
|
|
|
|
|
for platform in VICARE_PLATFORMS:
|
|
|
|
discovery.load_platform(hass, platform, DOMAIN, {}, config)
|
|
|
|
|
|
|
|
return True
|