From cd13ecf6d97d43372fa4317d22c29d7cfe7245d9 Mon Sep 17 00:00:00 2001 From: pvizeli Date: Wed, 29 Mar 2017 15:40:21 +0200 Subject: [PATCH] cleanup things --- hassio_api/hassio/core.py | 4 ++-- hassio_api/hassio/dock/__init__.py | 19 +++---------------- hassio_api/hassio/host_controll.py | 4 ++-- hassio_api/hassio/tools.py | 11 ----------- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/hassio_api/hassio/core.py b/hassio_api/hassio/core.py index baceba29a..24d139c99 100644 --- a/hassio_api/hassio/core.py +++ b/hassio_api/hassio/core.py @@ -38,8 +38,8 @@ class HassIO(object): """Start HassIO.""" await self.supervisor.attach() _LOGGER.info( - "Attach to supervisor image %s tag %s", self.supervisor.image, - self.supervisor.tag) + "Attach to supervisor image %s version %s", self.supervisor.image, + self.supervisor.version) host_info = await self.host_controll.info() if host_info: diff --git a/hassio_api/hassio/dock/__init__.py b/hassio_api/hassio/dock/__init__.py index 02a3288ac..d1b509325 100644 --- a/hassio_api/hassio/dock/__init__.py +++ b/hassio_api/hassio/dock/__init__.py @@ -82,26 +82,13 @@ class DockerBase(object): """ try: self.container = self.dock.containers.get(self.docker_name) - self.image, self.tag = self.image = extract_image_name( - self.container.attrs['Config']['Image']) + self.image = self.container.attrs['Config']['Image'] + self.version = get_version_from_env( + self.container.attrs['Config']['Env']) except (docker.errors.DockerException, KeyError): _LOGGER.fatal( "Can't attach to %s docker container!", self.docker_name) - async def get_version(self): - """Read VERSION tag from ENV docker. - - Is a coroutine. - """ - if self.container: - try: - self.version = get_version_from_env( - self.container.attrs['Config']['Env']) - except KeyError: - _LOGGER.error("Can't read VERSION from docker env.") - - return None - def run(self): """Run docker image. diff --git a/hassio_api/hassio/host_controll.py b/hassio_api/hassio/host_controll.py index f69af14da..e9c4cc5ff 100644 --- a/hassio_api/hassio/host_controll.py +++ b/hassio_api/hassio/host_controll.py @@ -40,11 +40,11 @@ class HostControll(object): try: # send _LOGGER.info("Send '%s' to HostControll.", command) - writer.write("{}\n".format(command).encode()) - # receive with async_timeout.timeout(TIMEOUT, loop=self.loop): + writer.write("{}\n".format(command).encode()) data = await reader.readline() + response = data.decode().Upper() _LOGGER.info("Receive from HostControll: %s.", response) diff --git a/hassio_api/hassio/tools.py b/hassio_api/hassio/tools.py index b44ffaf59..238bd1c33 100644 --- a/hassio_api/hassio/tools.py +++ b/hassio_api/hassio/tools.py @@ -9,7 +9,6 @@ from .const import URL_HASSIO_VERSION _LOGGER = logging.getLogger(__name__) _RE_VERSION = re.compile(r"VERSION=(.*)") -_RE_IMAGE = re.compile(r"(.*):(.*)") async def fetch_current_versions(websession): @@ -32,13 +31,3 @@ def get_version_from_env(env_list): _LOGGER.error("Can't find VERSION in env") return None - - -def extract_image_name(image): - """Extract image name and tag from docker attrs.""" - data = _RE_IMAGE.match(image) - if not data: - _LOGGER.error("Invalid docker information: %s", image) - return (None, None) - - return (data.group(1), data.group(2))