예제 #1
0
    def test_BrowserBasedLogin(self):
        with enablePrintStatementsForTest(self):
            client_id = os.getenv('PYVICARE_CLIENT_ID', '')
            token_file = "browser.save"

            vicare = PyViCare()
            vicare.initWithBrowserOAuth(client_id, token_file)

            self.assertGreaterEqual(len(vicare.devices), 1)
예제 #2
0
    def test_Dump(self):
        email = os.getenv('PYVICARE_EMAIL', '')
        password = os.getenv('PYVICARE_PASSWORD', '')
        client_id = os.getenv('PYVICARE_CLIENT_ID', '')

        with enablePrintStatementsForTest(self):
            vicare = PyViCare()
            vicare.initWithCredentials(email, password, client_id, TOKEN_FILE)

            with open("dump.json", mode='w') as output:
                output.write(vicare.devices[0].dump_secure())
예제 #3
0
    def test_PyViCare(self):
        email = os.getenv('PYVICARE_EMAIL', '')
        password = os.getenv('PYVICARE_PASSWORD', '')
        client_id = os.getenv('PYVICARE_CLIENT_ID', '')
        # name of the device class. e.g. GazBoiler, HeatPump
        expected_device_type = os.getenv('PYVICARE_DEVICE_TYPE', '')

        with enablePrintStatementsForTest(self):
            print()

            vicare = PyViCare()
            vicare.initWithCredentials(email, password, client_id, TOKEN_FILE)

            print("Found %s devices" % len(vicare.devices))

            for deviceConfig in vicare.devices:
                print()
                print(f"{'model':<45}{deviceConfig.getModel()}")
                print(f"{'isOnline':<45}{deviceConfig.isOnline()}")

                device = deviceConfig.asAutoDetectDevice()
                auto_type_name = type(device).__name__
                print(f"{'detected type':<45}{auto_type_name}")

                if expected_device_type != '':
                    self.assertEqual(auto_type_name, expected_device_type)

                dumpResults(device)
                print()

                for circuit in device.circuits:
                    print(f"{'Use circuit':<45}{circuit.id}")
                    dumpResults(circuit)
                    print()

            print()
예제 #4
0
def vicare_login(hass, entry_data):
    """Login via PyVicare API."""
    vicare_api = PyViCare()
    vicare_api.setCacheDuration(DEFAULT_SCAN_INTERVAL)
    vicare_api.initWithCredentials(
        entry_data[CONF_USERNAME],
        entry_data[CONF_PASSWORD],
        entry_data[CONF_CLIENT_ID],
        hass.config.path(STORAGE_DIR, "vicare_token.save"),
    )
    return vicare_api
예제 #5
0
def setup_vicare_api(hass, conf, entity_data):
    """Set up PyVicare API."""
    vicare_api = PyViCare()
    vicare_api.setCacheDuration(conf[CONF_SCAN_INTERVAL])
    vicare_api.initWithCredentials(
        conf[CONF_USERNAME],
        conf[CONF_PASSWORD],
        conf[CONF_CLIENT_ID],
        hass.config.path(STORAGE_DIR, "vicare_token.save"),
    )

    device = vicare_api.devices[0]
    for device in vicare_api.devices:
        _LOGGER.info("Found device: %s (online: %s)", device.getModel(),
                     str(device.isOnline()))
    entity_data[VICARE_DEVICE_CONFIG] = device
    entity_data[VICARE_API] = getattr(
        device, HEATING_TYPE_TO_CREATOR_METHOD[conf[CONF_HEATING_TYPE]])()
    entity_data[VICARE_CIRCUITS] = entity_data[VICARE_API].circuits
예제 #6
0
def create_client():
    client_id = os.getenv('PYVICARE_CLIENT_ID', '')

    vicare = PyViCare()
    vicare.initWithBrowserOAuth(client_id, TOKEN_FILE)
    return vicare