Add interface and home-assistant api proxy (#205)

* Add initial for hass interface

* For better compatibility, remove extra options for cleanup old stuff

* Add new functions to api

* Add api proxy to home-assistant

* use const

* fix lint

* fix lint

* Add check_api_state function

* Add api watchdog

* Fix lint

* update output

* fix url

* Fix API call

* fix API documentation

* remove password

* fix api call to hass api only

* fix problem with config missmatch

* test

* Detect wrong ssl settings

* disable watchdog & add options

* Update API
This commit is contained in:
Pascal Vizeli
2017-10-03 00:31:14 +02:00
committed by GitHub
parent 2998cd94ff
commit f38e28a4d9
9 changed files with 246 additions and 23 deletions

View File

@@ -62,18 +62,54 @@ def hassio_update(supervisor, updater):
return _hassio_update
def homeassistant_watchdog(loop, homeassistant):
"""Create scheduler task for montoring running state."""
async def _homeassistant_watchdog():
"""Check running state and start if they is close."""
def homeassistant_watchdog_docker(loop, homeassistant):
"""Create scheduler task for montoring running state of docker."""
async def _homeassistant_watchdog_docker():
"""Check running state of docker and start if they is close."""
# if Home-Assistant is active
if not await homeassistant.is_initialize():
if not await homeassistant.is_initialize() or \
not homeassistant.watchdog:
return
# If Home-Assistant is running
# if Home-Assistant is running
if homeassistant.in_progress or await homeassistant.is_running():
return
loop.create_task(homeassistant.run())
_LOGGER.error("Watchdog found a problem with Home-Assistant docker!")
return _homeassistant_watchdog
return _homeassistant_watchdog_docker
def homeassistant_watchdog_api(loop, homeassistant):
"""Create scheduler task for montoring running state of API.
Try 2 times to call API before we restart Home-Assistant. Maybe we had a
delay in our system.
"""
retry_scan = 0
async def _homeassistant_watchdog_api():
"""Check running state of API and start if they is close."""
nonlocal retry_scan
# if Home-Assistant is active
if not await homeassistant.is_initialize() or \
not homeassistant.watchdog:
return
# if Home-Assistant API is up
if homeassistant.in_progress or await homeassistant.check_api_state():
return
retry_scan += 1
# Retry active
if retry_scan == 1:
_LOGGER.warning("Watchdog miss API response from Home-Assistant")
return
loop.create_task(homeassistant.restart())
_LOGGER.error("Watchdog found a problem with Home-Assistant API!")
retry_scan = 0
return _homeassistant_watchdog_api