Merge pull request #3 from vadimtitov/main

Add Connection Error handling
This commit is contained in:
Vadim Titov
2021-09-18 15:14:03 +01:00
committed by GitHub
3 changed files with 8 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
## [Home Assistant](https://www.home-assistant.io/) Web API Client for Python
[![PyPI - Downloads](https://img.shields.io/pypi/dm/hassapi?style=flat-square)](https://pypistats.org/packages/hassapi)
## Examples
```python

View File

@@ -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

View File

@@ -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}