-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve error handling * Improve a bit readme * Fix checks
- Loading branch information
Showing
9 changed files
with
145 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"""Support for REST API calls.""" | ||
import logging | ||
|
||
import httpx | ||
|
||
from homeassistant.helpers.httpx_client import get_async_client | ||
|
||
DEFAULT_TIMEOUT = 30 | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class RestApiCall: | ||
"""Class for handling the data retrieval.""" | ||
|
||
def __init__( | ||
self, | ||
hass, | ||
method, | ||
resource, | ||
auth, | ||
headers, | ||
params, | ||
data, | ||
verify_ssl, | ||
timeout=DEFAULT_TIMEOUT, | ||
): | ||
"""Initialize the data object.""" | ||
self._hass = hass | ||
self._method = method | ||
self._resource = resource | ||
self._auth = auth | ||
self._headers = headers | ||
self._params = params | ||
self._request_data = data | ||
self._timeout = timeout | ||
self._verify_ssl = verify_ssl | ||
self._async_client = None | ||
self.data = None | ||
self.last_exception = None | ||
self.headers = None | ||
self.status = 0 | ||
|
||
async def async_update(self, log_errors=True): | ||
"""Get the latest data from REST service with provided method.""" | ||
if not self._async_client: | ||
self._async_client = get_async_client( | ||
self._hass, verify_ssl=self._verify_ssl | ||
) | ||
|
||
_LOGGER.debug("Updating from %s", self._resource) | ||
try: | ||
response = await self._async_client.request( | ||
self._method, | ||
self._resource, | ||
headers=self._headers, | ||
params=self._params, | ||
auth=self._auth, | ||
data=self._request_data, | ||
timeout=self._timeout, | ||
follow_redirects=True, | ||
) | ||
self.data = response.text | ||
self.headers = response.headers | ||
self.status = response.status_code | ||
except httpx.RequestError as ex: | ||
if log_errors: | ||
_LOGGER.error( | ||
"Error fetching data: %s failed with %s", self._resource, ex | ||
) | ||
self.last_exception = ex | ||
self.status = 500 | ||
self.data = None | ||
self.headers = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
{ | ||
"config": { | ||
"error": { | ||
"name_exists": "Name already exists", | ||
"instance_exists": "Instance already exists", | ||
"invalid_answer": "Invalid answer from server" | ||
}, | ||
"step": { | ||
"user": { | ||
"data": { | ||
"name": "Name of the rig", | ||
"address": "Instance address", | ||
"token": "Access token" | ||
}, | ||
"description": "XMRIG instance.", | ||
"title": "XMRIG" | ||
} | ||
} | ||
"config": { | ||
"error": { | ||
"name_exists": "Name already exists", | ||
"address_exists": "You are already connected to this address", | ||
"instance_exists": "Instance already exists", | ||
"invalid_answer": "Invalid answer from server", | ||
"no_answer": "No answer from the server. Check that server is running and you have correct address.", | ||
"not_authorized": "You have no rights to access this server." | ||
}, | ||
"step": { | ||
"user": { | ||
"data": { | ||
"name": "Name of the rig", | ||
"address": "Instance address", | ||
"token": "Access token" | ||
}, | ||
"description": "XMRIG instance.", | ||
"title": "XMRIG" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
{ | ||
"config": { | ||
"error": { | ||
"name_exists": "Name already exists", | ||
"instance_exists": "Instance already exists", | ||
"invalid_answer": "Invalid answer from server" | ||
}, | ||
"step": { | ||
"user": { | ||
"data": { | ||
"name": "Name of the rig", | ||
"address": "Instance address", | ||
"token": "Access token" | ||
}, | ||
"description": "XMRIG instance.", | ||
"title": "XMRIG" | ||
} | ||
} | ||
"config": { | ||
"error": { | ||
"name_exists": "Name already exists", | ||
"address_exists": "You are already connected to this address", | ||
"instance_exists": "Instance already exists", | ||
"invalid_answer": "Invalid answer from server", | ||
"no_answer": "No answer from the server. Check that server is running and you have correct address.", | ||
"not_authorized": "You have no rights to access this server." | ||
}, | ||
"step": { | ||
"user": { | ||
"data": { | ||
"name": "Name of the rig", | ||
"address": "Instance address", | ||
"token": "Access token" | ||
}, | ||
"description": "XMRIG instance.", | ||
"title": "XMRIG" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "XMRIG", | ||
"name": "XMRIG integration", | ||
"render_readme": true, | ||
"iot_class": "cloud_polling" | ||
} |