Esempio n. 1
0
def setup(hass, config):
    """Create the ViCare component."""
    conf = config[DOMAIN]
    params = {"token_file": hass.config.path(STORAGE_DIR, "vicare_token.save")}
    if conf.get(CONF_CIRCUIT) is not None:
        params["circuit"] = conf[CONF_CIRCUIT]

    heating_type = conf[CONF_HEATING_TYPE]

    try:
        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)
    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]
    hass.data[DOMAIN][VICARE_HEATING_TYPE] = heating_type

    for platform in VICARE_PLATFORMS:
        discovery.load_platform(hass, platform, DOMAIN, {}, config)

    return True
Esempio n. 2
0
def setup(hass, config):
    """Create the ViCare component."""
    conf = config[DOMAIN]
    params = {"token_file": hass.config.path(STORAGE_DIR, "vicare_token.save")}
    if conf.get(CONF_CIRCUIT) is not None:
        params["circuit"] = conf[CONF_CIRCUIT]

    params["cacheDuration"] = conf.get(CONF_SCAN_INTERVAL)

    heating_type = conf[CONF_HEATING_TYPE]

    try:
        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)
    except AttributeError:
        _LOGGER.error(
            "Failed to create PyViCare API client. Please check your credentials"
        )
        return False

    hass.data[DOMAIN] = {}
    hass.data[DOMAIN]["entities"] = {}
    hass.data[DOMAIN]["entities"]["climate"] = []
    hass.data[DOMAIN][VICARE_API] = vicare_api
    hass.data[DOMAIN][VICARE_NAME] = conf[CONF_NAME]
    hass.data[DOMAIN][VICARE_HEATING_TYPE] = heating_type

    for platform in VICARE_PLATFORMS:
        discovery.load_platform(hass, platform, DOMAIN, {}, config)

    def service_vicare_mode(service):
        """Dispatch service calls to target entities."""
        cmd = service.data[ATTR_COMMAND]
        entity_id = service.data[ATTR_ENTITY_ID]
        target_devices = [
            dev for dev in hass.data[DOMAIN]["entities"]["climate"]
            if dev.entity_id in entity_id
        ]

        for target_device in target_devices:
            target_device.vicare_mode(cmd)

    hass.services.register(
        DOMAIN,
        SERVICE_VICARE_MODE,
        service_vicare_mode,
        schema=SERVICE_VICARE_MODE_SCHEMA,
    )
    return True
Esempio n. 3
0
 def setUp(self):
     self.service = ViCareServiceMock('response/Vitocal300G.json')
     self.device = HeatPump(self.service)
Esempio n. 4
0
 def setUp(self):
     self.service = ViCareServiceMock('response_Vitocal200.json', 0)
     self.heat = HeatPump(None, None, None, 0, 0, self.service)
     PyViCare.Feature.raise_exception_on_not_supported_device_feature = True
Esempio n. 5
0
 def asHeatPump(self):
     return HeatPump(self.service)