mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-27 11:06:32 +00:00
fix lint
This commit is contained in:
parent
44c17278b9
commit
bad4d90d43
@ -6,6 +6,7 @@ import aiohttp
|
|||||||
import docker
|
import docker
|
||||||
|
|
||||||
from . import bootstrap, tools
|
from . import bootstrap, tools
|
||||||
|
from .host_controll import HostControll
|
||||||
from .const import HOMEASSISTANT_TAG, SOCKET_DOCKER
|
from .const import HOMEASSISTANT_TAG, SOCKET_DOCKER
|
||||||
from .docker.homeassistant import DockerHomeAssistant
|
from .docker.homeassistant import DockerHomeAssistant
|
||||||
from .docker.supervisor import DockerSupervisor
|
from .docker.supervisor import DockerSupervisor
|
||||||
@ -32,6 +33,10 @@ async def run_hassio(loop):
|
|||||||
tag=config.homeassistant_tag
|
tag=config.homeassistant_tag
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# init hostcontroll
|
||||||
|
host_controll = HostControll(loop)
|
||||||
|
await host_controll.info()
|
||||||
|
|
||||||
# first start of supervisor?
|
# first start of supervisor?
|
||||||
if config.homeassistant_tag is None:
|
if config.homeassistant_tag is None:
|
||||||
_LOGGER.info("First start of supervisor, read version from github.")
|
_LOGGER.info("First start of supervisor, read version from github.")
|
||||||
@ -40,7 +45,7 @@ async def run_hassio(loop):
|
|||||||
current = None
|
current = None
|
||||||
while True:
|
while True:
|
||||||
current = await tools.fetch_current_versions(websession)
|
current = await tools.fetch_current_versions(websession)
|
||||||
if current and CONF_HOMEASSISTANT_TAG in current:
|
if current and HOMEASSISTANT_TAG in current:
|
||||||
if await docker_hass.install(current[HOMEASSISTANT_TAG]):
|
if await docker_hass.install(current[HOMEASSISTANT_TAG]):
|
||||||
break
|
break
|
||||||
_LOGGER.warning("Can't fetch info from github. Retry in 60.")
|
_LOGGER.warning("Can't fetch info from github. Retry in 60.")
|
||||||
|
@ -1,13 +1,81 @@
|
|||||||
"""Host controll for HassIO."""
|
"""Host controll for HassIO."""
|
||||||
import asyncio
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from .const import SOCKET_HC
|
from .const import SOCKET_HC
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class HostControll(object):
|
class HostControll(object):
|
||||||
"""Manage host function."""
|
"""Client for host controll."""
|
||||||
|
|
||||||
def __init__(self, loop):
|
def __init__(self, loop):
|
||||||
"""Initialize host controll."""
|
"""Initialize HostControll socket client."""
|
||||||
|
self.loop = loop
|
||||||
|
|
||||||
|
async def _send_command(self, command):
|
||||||
|
"""Send command to host.
|
||||||
|
|
||||||
|
Is a coroutine.
|
||||||
|
"""
|
||||||
|
if not os.path.isfile(SOCKET_HC):
|
||||||
|
return
|
||||||
|
|
||||||
|
reader, writer = await self.loop.create_unix_connection(SOCKET_HC)
|
||||||
|
|
||||||
|
# send
|
||||||
|
_LOGGER.info("Send '%s' to HostControll.", command)
|
||||||
|
writer.write(command.encode())
|
||||||
|
|
||||||
|
# receive
|
||||||
|
data = await reader.readline()
|
||||||
|
response = data.decode().Upper()
|
||||||
|
_LOGGER.info("Receive from HostControll: %s.", response)
|
||||||
|
|
||||||
|
if response == "OK":
|
||||||
|
return True
|
||||||
|
elif response == "ERROR":
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return json.loads(response)
|
||||||
|
|
||||||
|
def info(self):
|
||||||
|
"""Return Info from host.
|
||||||
|
|
||||||
|
Return a coroutine.
|
||||||
|
"""
|
||||||
|
return self._send_command("info")
|
||||||
|
|
||||||
|
def reboot(self):
|
||||||
|
"""Reboot the host system.
|
||||||
|
|
||||||
|
Return a coroutine.
|
||||||
|
"""
|
||||||
|
return self._send_command("reboot")
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
"""Shutdown the host system.
|
||||||
|
|
||||||
|
Return a coroutine.
|
||||||
|
"""
|
||||||
|
return self._send_command("shutdown")
|
||||||
|
|
||||||
|
def host_update(self, version=None):
|
||||||
|
"""Update the host system.
|
||||||
|
|
||||||
|
Return a coroutine.
|
||||||
|
"""
|
||||||
|
if version:
|
||||||
|
return self._send_command("host-update " + version)
|
||||||
|
return self._send_command("host-update")
|
||||||
|
|
||||||
|
def supervisor_update(self, version=None):
|
||||||
|
"""Update the supervisor on host system.
|
||||||
|
|
||||||
|
Return a coroutine.
|
||||||
|
"""
|
||||||
|
if version:
|
||||||
|
return self._send_command("supervisor-update " + version)
|
||||||
|
return self._send_command("supervisor-update")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
VERSION = "0.1"
|
VERSION = "0.2"
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='HassIO',
|
name='HassIO',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user