diff --git a/API.md b/API.md index 352c087eb..db9e103ec 100644 --- a/API.md +++ b/API.md @@ -243,6 +243,7 @@ Optional: "serial": ["/dev/xy"], "input": ["Input device name"], "disk": ["/dev/sdax"], + "gpio": ["gpiochip0", "gpiochip100"], "audio": { "CARD_ID": { "name": "xy", diff --git a/hassio/api/host.py b/hassio/api/host.py index 5815ebf76..5087e6837 100644 --- a/hassio/api/host.py +++ b/hassio/api/host.py @@ -8,7 +8,7 @@ from .util import api_process_hostcontrol, api_process, api_validate from ..const import ( ATTR_VERSION, ATTR_LAST_VERSION, ATTR_TYPE, ATTR_HOSTNAME, ATTR_FEATURES, ATTR_OS, ATTR_SERIAL, ATTR_INPUT, ATTR_DISK, ATTR_AUDIO, ATTR_AUDIO_INPUT, - ATTR_AUDIO_OUTPUT) + ATTR_AUDIO_OUTPUT, ATTR_GPIO) from ..validate import ALSA_CHANNEL _LOGGER = logging.getLogger(__name__) @@ -83,8 +83,9 @@ class APIHost(object): async def hardware(self, request): """Return local hardware infos.""" return { - ATTR_SERIAL: self.local_hw.serial_devices, - ATTR_INPUT: self.local_hw.input_devices, - ATTR_DISK: self.local_hw.disk_devices, + ATTR_SERIAL: list(self.local_hw.serial_devices), + ATTR_INPUT: list(self.local_hw.input_devices), + ATTR_DISK: list(self.local_hw.disk_devices), + ATTR_GPIO: list(self.local_hw.gpio_devices), ATTR_AUDIO: self.local_hw.audio_devices, } diff --git a/hassio/hardware.py b/hassio/hardware.py index eddfc6f39..09be04acc 100644 --- a/hassio/hardware.py +++ b/hassio/hardware.py @@ -19,6 +19,8 @@ RE_DEVICES = re.compile(r"\[.*(\d+)- (\d+).*\]: ([\w ]*)") PROC_STAT = Path("/proc/stat") RE_BOOT_TIME = re.compile(r"btime (\d+)") +GPIO_DEVICES = Path("/sys/class/gpio") + class Hardware(object): """Represent a interface to procfs, sysfs and udev.""" @@ -35,7 +37,7 @@ class Hardware(object): if 'ID_VENDOR' in device: dev_list.add(device.device_node) - return list(dev_list) + return dev_list @property def input_devices(self): @@ -45,7 +47,7 @@ class Hardware(object): if 'NAME' in device: dev_list.add(device['NAME'].replace('"', '')) - return list(dev_list) + return dev_list @property def disk_devices(self): @@ -55,7 +57,7 @@ class Hardware(object): if device.device_node.startswith('/dev/sd'): dev_list.add(device.device_node) - return list(dev_list) + return dev_list @property def audio_devices(self): @@ -90,6 +92,15 @@ class Hardware(object): return audio_list + @property + def gpio_devices(self): + """Return list of GPIO interface on device.""" + dev_list = set() + for interface in GPIO_DEVICES.glob("gpio*"): + dev_list.add(interface.name) + + return dev_list + @property def last_boot(self): """Return last boot time."""