mirror of
https://github.com/hass-api/hassapi.git
synced 2022-10-22 18:29:31 +03:00
Merge pull request #3 from vadimtitov/main
Add Connection Error handling
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
## [Home Assistant](https://www.home-assistant.io/) Web API Client for Python
|
||||
[](https://pypistats.org/packages/hassapi)
|
||||
|
||||
## Examples
|
||||
```python
|
||||
|
||||
@@ -36,7 +36,10 @@ class BaseClient(AuthenticatedClient):
|
||||
|
||||
def _api_is_running(self) -> bool:
|
||||
"""Check if Home Assistant API is running."""
|
||||
return self._get("/")["message"] == "API running." # type: ignore
|
||||
try:
|
||||
return self._get("/")["message"] == "API running." # type: ignore
|
||||
except requests.exceptions.ConnectionError:
|
||||
return False
|
||||
|
||||
def _get(
|
||||
self, endpoint: str, params: Optional[Dict] = None, **kwargs: HassValueType
|
||||
|
||||
6
tox.ini
6
tox.ini
@@ -8,7 +8,7 @@ envlist =
|
||||
mypy
|
||||
|
||||
[testenv]
|
||||
basepython = python3.8
|
||||
basepython = python3
|
||||
deps =
|
||||
pytest: coverage
|
||||
pytest: pytest
|
||||
@@ -31,7 +31,7 @@ commands =
|
||||
flake8 --max-line-length 99 src/hassapi setup.py
|
||||
|
||||
[testenv:format]
|
||||
basepython = python3.8
|
||||
basepython = python3
|
||||
description = format source code
|
||||
deps = black == 19.10b0
|
||||
isort[pyproject] == 4.3.21
|
||||
@@ -44,7 +44,7 @@ commands =
|
||||
isort -rc src tests setup.py
|
||||
|
||||
[testenv:format-check]
|
||||
basepython = python3.8
|
||||
basepython = python3
|
||||
description = check that the source code is well formatted
|
||||
deps = {[testenv:format]deps}
|
||||
skip_install = {[testenv:format]skip_install}
|
||||
|
||||
Reference in New Issue
Block a user