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)
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())
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()
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
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
def create_client(): client_id = os.getenv('PYVICARE_CLIENT_ID', '') vicare = PyViCare() vicare.initWithBrowserOAuth(client_id, TOKEN_FILE) return vicare