From df20a0686da05eea8353aee9ec4a869fe5318803 Mon Sep 17 00:00:00 2001 From: Brian Berg Date: Sun, 12 Jul 2020 02:40:39 +0000 Subject: [PATCH] refactor: replace requests_async w/ httpx --- custom_components/nicehash/manifest.json | 2 +- custom_components/nicehash/nicehash.py | 16 ++++++++-------- hacs.json | 3 +-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/custom_components/nicehash/manifest.json b/custom_components/nicehash/manifest.json index 3d4a331..4ce0131 100644 --- a/custom_components/nicehash/manifest.json +++ b/custom_components/nicehash/manifest.json @@ -8,6 +8,6 @@ "@brianberg" ], "requirements": [ - "requests_async" + "httpx" ] } \ No newline at end of file diff --git a/custom_components/nicehash/nicehash.py b/custom_components/nicehash/nicehash.py index 387d78f..f4393ab 100644 --- a/custom_components/nicehash/nicehash.py +++ b/custom_components/nicehash/nicehash.py @@ -8,8 +8,8 @@ References: from datetime import datetime from hashlib import sha256 import hmac +import httpx import json -import requests_async as requests import sys from time import mktime import uuid @@ -75,12 +75,12 @@ class NiceHashPublicClient: if query is not None: url += f"?{query}" - async with requests.Session() as session: + async with httpx.AsyncClient() as client: if body: data = json.dumps(body) - response = await session.request(method, url, data=data) + response = await client.request(method, url, data=data) else: - response = await session.request(method, url) + response = await client.request(method, url) if response.status_code == 200: return response.json() @@ -134,8 +134,8 @@ class NiceHashPrivateClient: "X-Request-Id": str(uuid.uuid4()), } - async with requests.Session() as session: - session.headers = headers + async with httpx.AsyncClient() as client: + client.headers = headers url = NICEHASH_API_URL + path if query: @@ -145,9 +145,9 @@ class NiceHashPrivateClient: print(method, url) if data: - response = await session.request(method, url, data=data) + response = await client.request(method, url, data=data) else: - response = await session.request(method, url) + response = await client.request(method, url) if response.status_code == 200: return response.json() diff --git a/hacs.json b/hacs.json index f47862b..0cbdab3 100644 --- a/hacs.json +++ b/hacs.json @@ -3,6 +3,5 @@ "domains": [ "sensor" ], - "iot_class": "Cloud Polling", - "homeassistant": "0.108.0" + "iot_class": "Cloud Polling" } \ No newline at end of file