mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-25 18:16:32 +00:00
Make HassIO more objectable
This commit is contained in:
parent
f26e09c3cc
commit
c4c1ce8e64
@ -16,8 +16,10 @@ if __name__ == "__main__":
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
hassio = core.HassIO(loop)
|
||||||
|
|
||||||
_LOGGER.info("Start Hassio task")
|
_LOGGER.info("Start Hassio task")
|
||||||
loop.create_task(core.run_hassio(loop))
|
loop.create_task(hassio.start())
|
||||||
|
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
_LOGGER.info("Close Hassio")
|
_LOGGER.info("Close Hassio")
|
||||||
|
@ -14,53 +14,58 @@ from .docker.supervisor import DockerSupervisor
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def run_hassio(loop):
|
class HassIO(object):
|
||||||
"""Start HassIO."""
|
"""Main object of hassio."""
|
||||||
websession = aiohttp.ClientSession(loop=loop)
|
|
||||||
dock = docker.DockerClient(
|
|
||||||
base_url="unix:/{}".format(SOCKET_DOCKER), version='auto')
|
|
||||||
|
|
||||||
# init system
|
def __init__(self, loop):
|
||||||
config = bootstrap.initialize_system_data()
|
"""Initialize hassio object."""
|
||||||
|
self.loop = loop
|
||||||
|
self.config = bootstrap.initialize_system_data()
|
||||||
|
self.websession = aiohttp.ClientSession(loop=self.loop)
|
||||||
|
self.dock = docker.DockerClient(
|
||||||
|
base_url="unix:/{}".format(SOCKET_DOCKER), version='auto')
|
||||||
|
|
||||||
# init Supervisor Docker
|
# init basic docker container
|
||||||
docker_super = DockerSupervisor(config, loop, dock)
|
self.supervisor = DockerSupervisor(
|
||||||
await docker_super.attach()
|
self.config, self.loop, self.dock)
|
||||||
_LOGGER.info(
|
self.homeassistant = DockerHomeAssistant(
|
||||||
"Attach to supervisor image %s tag %s", docker_super.image,
|
self.config, self.loop, self.dock)
|
||||||
docker_super.tag)
|
|
||||||
|
|
||||||
# init HomeAssistant Docker
|
# init HostControll
|
||||||
docker_hass = DockerHomeAssistant(
|
self.host_controll = HostControll(self.loop)
|
||||||
config, loop, dock, image=config.homeassistant_image,
|
|
||||||
tag=config.homeassistant_tag
|
|
||||||
)
|
|
||||||
|
|
||||||
# init HostControll
|
async def start(self):
|
||||||
host_controll = HostControll(loop)
|
"""Start HassIO."""
|
||||||
host_info = await host_controll.info()
|
await self.supervisor.attach()
|
||||||
if host_info:
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Connected to host controll daemon. OS: %s Version: %s",
|
"Attach to supervisor image %s tag %s", self.supervisor.image,
|
||||||
host_info.get('host'), host_info.get('version'))
|
self.supervisor.tag)
|
||||||
|
|
||||||
# first start of supervisor?
|
host_info = await self.host_controll.info()
|
||||||
if config.homeassistant_tag is None:
|
if host_info:
|
||||||
_LOGGER.info("First start of supervisor, read version from github.")
|
_LOGGER.info(
|
||||||
|
"Connected to host controll daemon. OS: %s Version: %s",
|
||||||
|
host_info.get('host'), host_info.get('version'))
|
||||||
|
|
||||||
# read homeassistant tag and install it
|
# first start of supervisor?
|
||||||
current = None
|
if self.config.homeassistant_tag is None:
|
||||||
while True:
|
_LOGGER.info("First start of supervisor, read version from github.")
|
||||||
current = await tools.fetch_current_versions(websession)
|
|
||||||
if current and HOMEASSISTANT_TAG in current:
|
|
||||||
if await docker_hass.install(current[HOMEASSISTANT_TAG]):
|
|
||||||
break
|
|
||||||
_LOGGER.warning("Can't fetch info from github. Retry in 60.")
|
|
||||||
await asyncio.sleep(60, loop=loop)
|
|
||||||
|
|
||||||
config.homeassistant_tag = current[HOMEASSISTANT_TAG]
|
# read homeassistant tag and install it
|
||||||
else:
|
current = None
|
||||||
_LOGGER.info("HomeAssistant docker is exists.")
|
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=loop)
|
||||||
|
|
||||||
# run HomeAssistant
|
self.config.homeassistant_tag = current[HOMEASSISTANT_TAG]
|
||||||
await docker_hass.run()
|
else:
|
||||||
|
_LOGGER.info("HomeAssistant docker is exists.")
|
||||||
|
|
||||||
|
# run HomeAssistant
|
||||||
|
await self.homeassistant.run()
|
||||||
|
@ -13,6 +13,13 @@ HASS_DOCKER_NAME = 'homeassistant'
|
|||||||
class DockerHomeAssistant(DockerBase):
|
class DockerHomeAssistant(DockerBase):
|
||||||
"""Docker hassio wrapper for HomeAssistant."""
|
"""Docker hassio wrapper for HomeAssistant."""
|
||||||
|
|
||||||
|
def __init__(self, config, loop, dock):
|
||||||
|
"""Initialize docker homeassistant wrapper."""
|
||||||
|
super().__init__(
|
||||||
|
config, loop, dock, image=config.homeassistant_image,
|
||||||
|
tag=config.homeassistant_tag
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def docker_name(self):
|
def docker_name(self):
|
||||||
"""Return name of docker container."""
|
"""Return name of docker container."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user