Use now attr

This commit is contained in:
Pascal Vizeli 2018-04-14 00:19:29 +02:00
parent c5ee2ebc49
commit 41fed656c1
3 changed files with 23 additions and 22 deletions

View File

@ -1,8 +1,8 @@
"""Init file for HassIO docker object.""" """Init file for HassIO docker object."""
from contextlib import suppress from contextlib import suppress
from collections import namedtuple
import logging import logging
import attr
import docker import docker
from .network import DockerNetwork from .network import DockerNetwork
@ -10,7 +10,8 @@ from ..const import SOCKET_DOCKER
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CommandReturn = namedtuple('CommandReturn', ['exit_code', 'output']) # pylint: disable=invalid-name
CommandReturn = attr.make_class('CommandReturn', ['exit_code', 'output'])
class DockerAPI(object): class DockerAPI(object):

View File

@ -1,6 +1,5 @@
"""HomeAssistant control object.""" """HomeAssistant control object."""
import asyncio import asyncio
from collections import namedtuple
import logging import logging
import os import os
import re import re
@ -9,6 +8,7 @@ import time
import aiohttp import aiohttp
from aiohttp.hdrs import CONTENT_TYPE from aiohttp.hdrs import CONTENT_TYPE
import attr
from .const import ( from .const import (
FILE_HASSIO_HOMEASSISTANT, ATTR_IMAGE, ATTR_LAST_VERSION, ATTR_UUID, FILE_HASSIO_HOMEASSISTANT, ATTR_IMAGE, ATTR_LAST_VERSION, ATTR_UUID,
@ -24,7 +24,8 @@ _LOGGER = logging.getLogger(__name__)
RE_YAML_ERROR = re.compile(r"homeassistant\.util\.yaml") RE_YAML_ERROR = re.compile(r"homeassistant\.util\.yaml")
ConfigResult = namedtuple('ConfigResult', ['valid', 'log']) # pylint: disable=invalid-name
ConfigResult = attr.make_class('ConfigResult', ['valid', 'log'])
class HomeAssistant(JsonConfig, CoreSysAttributes): class HomeAssistant(JsonConfig, CoreSysAttributes):

View File

@ -1,16 +1,18 @@
"""Host Audio-support.""" """Host Audio-support."""
from collections import namedtuple
import logging import logging
import json import json
from pathlib import Path from pathlib import Path
from string import Template from string import Template
import attr
from ..const import ATTR_INPUT, ATTR_OUTPUT, ATTR_DEVICES, ATTR_NAME from ..const import ATTR_INPUT, ATTR_OUTPUT, ATTR_DEVICES, ATTR_NAME
from ..coresys import CoreSysAttributes from ..coresys import CoreSysAttributes
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DefaultConfig = namedtuple('DefaultConfig', ['input', 'output']) # pylint: disable=invalid-name
DefaultConfig = attr.make_class('DefaultConfig', ['input', 'output'])
class AlsaAudio(CoreSysAttributes): class AlsaAudio(CoreSysAttributes):
@ -85,25 +87,22 @@ class AlsaAudio(CoreSysAttributes):
def default(self): def default(self):
"""Generate ALSA default setting.""" """Generate ALSA default setting."""
# Init defaults # Init defaults
try: if self._default is None:
if self._default is None: database = self._audio_database()
database = self._audio_database() alsa_input = database.get(self._machine, {}).get(ATTR_INPUT)
alsa_input = database.get(self._machine, {}).get(ATTR_INPUT) alsa_output = database.get(self._machine, {}).get(ATTR_OUTPUT)
alsa_output = database.get(self._machine, {}).get(ATTR_OUTPUT)
self._default = DefaultConfig(alsa_input, alsa_output) self._default = DefaultConfig(alsa_input, alsa_output)
# Search exists/new output # Search exists/new output
if self._default.output is None and self.output_devices: if self._default.output is None and self.output_devices:
self._default.output = next(iter(self.output_devices)) self._default.output = next(iter(self.output_devices))
_LOGGER.info("Detect output device %s", self._default.output) _LOGGER.info("Detect output device %s", self._default.output)
# Search exists/new input # Search exists/new input
if self._default.input is None and self.input_devices: if self._default.input is None and self.input_devices:
self._default.input = next(iter(self.input_devices)) self._default.input = next(iter(self.input_devices))
_LOGGER.info("Detect input device %s", self._default.input) _LOGGER.info("Detect input device %s", self._default.input)
except:
_LOGGER.exception("hmm2")
return self._default return self._default