cleanup old stuff.

This commit is contained in:
pvizeli 2017-03-30 10:37:07 +02:00
parent 5a642cafa4
commit b0a6d50d32
3 changed files with 31 additions and 21 deletions

View File

@ -35,7 +35,7 @@ class HassIO(object):
self.host_controll = HostControll(self.loop)
async def start(self):
"""Start HassIO."""
"""Start HassIO orchestration."""
await self.supervisor.attach()
_LOGGER.info(
"Attach to supervisor image %s version %s", self.supervisor.image,
@ -50,22 +50,34 @@ class HassIO(object):
# first start of supervisor?
if self.config.homeassistant_tag is None:
_LOGGER.info("No HomeAssistant docker found. Install it now")
# read homeassistant tag and install it
current = None
while True:
current = await tools.fetch_current_versions(self.websession)
if current and HOMEASSISTANT_TAG in current:
resp = await self.homeassistant.install(
current[HOMEASSISTANT_TAG])
if resp:
break
_LOGGER.warning("Can't fetch info from github. Retry in 60.")
await asyncio.sleep(60, loop=self.loop)
self.config.homeassistant_tag = current[HOMEASSISTANT_TAG]
await self._setup_homeassistant()
else:
_LOGGER.info("HomeAssistant docker exists. Run it now")
# run HomeAssistant
await self.homeassistant.run()
async def stop(self):
"""Stop a running orchestration."""
tasks = [self.websession.close()]
await asyncio.wait(tasks, loop=self.loop)
self.loop.close()
async def _setup_homeassistant(self):
"""Install a homeassistant docker container."""
current = None
while True:
# read homeassistant tag and install it
current = await tools.fetch_current_versions(self.websession)
if current and HOMEASSISTANT_TAG in current:
resp = await self.homeassistant.install(
current[HOMEASSISTANT_TAG])
if resp:
break
_LOGGER.warning("Error on setup HomeAssistant. Retry in 60.")
await asyncio.sleep(60, loop=self.loop)
# store version
self.config.homeassistant_tag = current[HOMEASSISTANT_TAG]
_LOGGER.info("HomeAssistant docker now exists.")

View File

@ -11,13 +11,12 @@ _LOGGER = logging.getLogger(__name__)
class DockerBase(object):
"""Docker hassio wrapper."""
def __init__(self, config, loop, dock, image=None, tag=None):
def __init__(self, config, loop, dock, image=None):
"""Initialize docker base wrapper."""
self.config = config
self.loop = loop
self.dock = dock
self.image = image
self.tag = tag
self.container = None
self.version = None
@ -64,6 +63,8 @@ class DockerBase(object):
if not self.container:
try:
self.container = self.dock.containers.get(self.docker_name)
self.version = get_version_from_env(
self.container.attrs['Config']['Env'])
except docker.errors.DockerException:
return False
return self.container.status == 'running'

View File

@ -16,10 +16,7 @@ class DockerHomeAssistant(DockerBase):
def __init__(self, config, loop, dock):
"""Initialize docker homeassistant wrapper."""
super().__init__(
config, loop, dock, image=config.homeassistant_image,
tag=config.homeassistant_tag
)
super().__init__(config, loop, dock, image=config.homeassistant_image)
@property
def docker_name(self):