Check exists hardware for audio/gpio devices (#753)

* Update hardware.py

* Update addon.py

* Update hardware.py

* Update addon.py
This commit is contained in:
Pascal Vizeli 2018-10-12 10:22:58 +02:00 committed by GitHub
parent 468cb0c36b
commit 7dbbcf24c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View File

@ -1,7 +1,6 @@
"""Init file for Hass.io add-on Docker object."""
import logging
import os
from pathlib import Path
import docker
import requests
@ -101,7 +100,7 @@ class DockerAddon(DockerInterface):
devices = self.addon.devices or []
# Use audio devices
if self.addon.with_audio and AUDIO_DEVICE not in devices:
if self.addon.with_audio and self.sys_hardware.support_audio:
devices.append(AUDIO_DEVICE)
# Auto mapping UART devices
@ -216,10 +215,8 @@ class DockerAddon(DockerInterface):
# Init other hardware mappings
# GPIO support
if self.addon.with_gpio:
if self.addon.with_gpio and self.sys_hardware.support_gpio:
for gpio_path in ("/sys/class/gpio", "/sys/devices/platform/soc"):
if not Path(gpio_path).exists():
continue
volumes.update({
gpio_path: {
'bind': gpio_path, 'mode': 'rw'

View File

@ -20,6 +20,7 @@ PROC_STAT = Path("/proc/stat")
RE_BOOT_TIME = re.compile(r"btime (\d+)")
GPIO_DEVICES = Path("/sys/class/gpio")
SOC_DEVICES = Path("/sys/devices/platform/soc")
RE_TTY = re.compile(r"tty[A-Z]+")
@ -60,6 +61,11 @@ class Hardware:
return dev_list
@property
def support_audio(self):
"""Return True if the system have audio support."""
return bool(self.audio_devices)
@property
def audio_devices(self):
"""Return all available audio interfaces."""
@ -68,10 +74,8 @@ class Hardware:
return {}
try:
with ASOUND_CARDS.open('r') as cards_file:
cards = cards_file.read()
with ASOUND_DEVICES.open('r') as devices_file:
devices = devices_file.read()
cards = ASOUND_CARDS.read_text()
devices = ASOUND_DEVICES.read_text()
except OSError as err:
_LOGGER.error("Can't read asound data: %s", err)
return {}
@ -97,6 +101,11 @@ class Hardware:
return audio_list
@property
def support_gpio(self):
"""Return True if device support GPIOs."""
return SOC_DEVICES.exists() and GPIO_DEVICES.exists()
@property
def gpio_devices(self):
"""Return list of GPIO interface on device."""