Beispiel #1
0
class SolarTest(unittest.TestCase):
    def setUp(self):
        self.service = ViCareServiceMock('response/Solar.json')
        self.device = Device(self.service)

    def test_getSolarStorageTemperature(self):
        self.assertEqual(self.device.getSolarStorageTemperature(), 63.5)

    def test_getSolarPowerProduction(self):
        self.assertEqual(
            self.device.getSolarPowerProduction(),
            [16.604, 19.78, 19.323, 20.592, 19.444, 14.517, 17.929, 20.534])
Beispiel #2
0
class GenericDevice(unittest.TestCase):
    def setUp(self):
        self.service = ViCareServiceMock(None,
                                         {'data': [MockCircuitsData([0])]})
        self.device = Device(self.service)

    def test_activateComfort(self):
        self.device.circuits[0].activateComfort()
        self.assertEqual(len(self.service.setPropertyData), 1)
        self.assertEqual(self.service.setPropertyData[0]['action'], 'activate')
        self.assertEqual(self.service.setPropertyData[0]['property_name'],
                         'heating.circuits.0.operating.programs.comfort')

    def test_deactivateComfort(self):
        self.device.circuits[0].deactivateComfort()
        self.assertEqual(len(self.service.setPropertyData), 1)
        self.assertEqual(self.service.setPropertyData[0]['action'],
                         'deactivate')
        self.assertEqual(self.service.setPropertyData[0]['property_name'],
                         'heating.circuits.0.operating.programs.comfort')

    def test_setDomesticHotWaterTemperature(self):
        self.device.setDomesticHotWaterTemperature(50)
        self.assertEqual(len(self.service.setPropertyData), 1)
        self.assertEqual(self.service.setPropertyData[0]['property_name'],
                         'heating.dhw.temperature.main')
        self.assertEqual(self.service.setPropertyData[0]['action'],
                         'setTargetTemperature')
        self.assertEqual(self.service.setPropertyData[0]['data'],
                         {'temperature': 50})

    def test_setMode(self):
        self.device.circuits[0].setMode('dhw')
        self.assertEqual(len(self.service.setPropertyData), 1)
        self.assertEqual(self.service.setPropertyData[0]['property_name'],
                         'heating.circuits.0.operating.modes.active')
        self.assertEqual(self.service.setPropertyData[0]['action'], 'setMode')
        self.assertEqual(self.service.setPropertyData[0]['data'],
                         {'mode': 'dhw'})

    def test_setHeatingCurve(self):
        self.device.circuits[0].setHeatingCurve(-2, 0.9)
        self.assertEqual(len(self.service.setPropertyData), 1)
        self.assertEqual(self.service.setPropertyData[0]['property_name'],
                         'heating.circuits.0.heating.curve')
        self.assertEqual(self.service.setPropertyData[0]['action'], 'setCurve')
        self.assertEqual(self.service.setPropertyData[0]['data'], {
            'shift': -2,
            'slope': 0.9
        })
class GenericDevice(unittest.TestCase):
    def setUp(self):
        self.service = ViCareServiceForTesting(None, 0, {})
        self.device = Device(None, None, None, 0, 0, self.service)
        
    def test_activateComfort(self):
        self.device.activateComfort()
        self.assertEqual(len(self.service.setPropertyData), 1)
        self.assertEqual(self.service.setPropertyData[0]['action'], 'activate')
        self.assertEqual(self.service.setPropertyData[0]['property_name'], 'heating.circuits.0.operating.programs.comfort')

    def test_deactivateComfort(self):
        self.device.deactivateComfort()
        self.assertEqual(len(self.service.setPropertyData), 1)
        self.assertEqual(self.service.setPropertyData[0]['action'], 'deactivate')
        self.assertEqual(self.service.setPropertyData[0]['property_name'], 'heating.circuits.0.operating.programs.comfort')

    def test_setDomesticHotWaterTemperature(self):
        self.device.setDomesticHotWaterTemperature(50)
        self.assertEqual(len(self.service.setPropertyData), 1)
        self.assertEqual(self.service.setPropertyData[0]['property_name'], 'heating.dhw.temperature')
        self.assertEqual(self.service.setPropertyData[0]['action'], 'setTargetTemperature')
        self.assertEqual(self.service.setPropertyData[0]['data'], '{"temperature":50}')

    def test_setMode(self):
        self.device.setMode('dhw')
        self.assertEqual(len(self.service.setPropertyData), 1)
        self.assertEqual(self.service.setPropertyData[0]['property_name'], 'heating.circuits.0.operating.modes.active')
        self.assertEqual(self.service.setPropertyData[0]['action'], 'setMode')
        self.assertEqual(self.service.setPropertyData[0]['data'], '{"mode":"dhw"}')
Beispiel #4
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
Beispiel #5
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
Beispiel #6
0
 def setUp(self):
     self.service = ViCareServiceMock(None,
                                      {'data': [MockCircuitsData([0])]})
     self.device = Device(self.service)
 def setUp(self):
     self.service = ViCareServiceMock(None, 0, {})
     self.device = Device(None, None, None, 0, 0, self.service)
 def setUp(self):
     self.service = ViCareServiceForTesting(None, 0, {})
     self.device = Device(None, None, None, 0, 0, self.service)
Beispiel #9
0
 def asGeneric(self):
     return Device(self.service)
Beispiel #10
0
 def setUp(self):
     self.service = ViCareServiceMock('response/Solar.json')
     self.device = Device(self.service)
Beispiel #11
0
class SolarTest(unittest.TestCase):
    def setUp(self):
        self.service = ViCareServiceMock('response/Solar.json')
        self.device = Device(self.service)

    def test_getSolarStorageTemperature(self):
        self.assertEqual(self.device.getSolarStorageTemperature(), 41.5)

    def test_getSolarPowerProduction(self):
        self.assertEqual(
            self.device.getSolarPowerProduction(),
            [19.773, 20.642, 18.831, 22.672, 18.755, 14.513, 15.406, 13.115])
        self.assertEqual(
            self.device.getSolarPowerProductionDays(),
            [19.773, 20.642, 18.831, 22.672, 18.755, 14.513, 15.406, 13.115])
        self.assertEqual(self.device.getSolarPowerProductionToday(), 19.773)
        self.assertEqual(
            self.device.getSolarPowerProductionWeeks(),
            [19.773, 20.642, 18.831, 22.672, 18.755, 14.513, 15.406, 13.115])
        self.assertEqual(self.device.getSolarPowerProductionThisWeek(), 19.773)
        self.assertEqual(
            self.device.getSolarPowerProductionMonths(),
            [19.773, 20.642, 18.831, 22.672, 18.755, 14.513, 15.406, 13.115])
        self.assertEqual(self.device.getSolarPowerProductionThisMonth(),
                         19.773)
        self.assertEqual(
            self.device.getSolarPowerProductionYears(),
            [19.773, 20.642, 18.831, 22.672, 18.755, 14.513, 15.406, 13.115])
        self.assertEqual(self.device.getSolarPowerProductionThisYear(), 19.773)

    def test_getSolarCollectorTemperature(self):
        self.assertEqual(self.device.getSolarCollectorTemperature(), 21.9)

    def test_getSolarPumpActive(self):
        self.assertEqual(self.device.getSolarPumpActive(), False)