I finally achieve to make Asus GPIO working except for one condition. Passing the parameter to invert the logic will disable all the switches, called for that group.
The config:
- platform: asus_gpio
ports:
15: Gate
16: Pillar Lights
1: Extra
# invert_logic: true
If uncomment the line it will shows
With the following source
"""Allows to configure a switch using RPi GPIO."""
import logging
# from time import sleep
import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA
from homeassistant.components import asus_gpio
from homeassistant.const import DEVICE_DEFAULT_NAME
from homeassistant.helpers.entity import ToggleEntity
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
CONF_PULL_MODE = 'pull_mode'
CONF_PORTS = 'ports'
CONF_INVERT_LOGIC = 'invert_logic'
DEFAULT_RELAY_TIME = .5
DEFAULT_INVERT_LOGIC = False
_SWITCHES_SCHEMA = vol.Schema({
cv.positive_int: cv.string,
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_PORTS): _SWITCHES_SCHEMA,
vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean,
})
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Asus Tinker Board GPIO devices."""
invert_logic = config.get(CONF_INVERT_LOGIC)
switches = []
ports = config.get(CONF_PORTS)
for port, name in ports.items():
switches.append(AsusGPIOSwitch(name, port, invert_logic))
add_entities(switches)
class AsusGPIOSwitch(ToggleEntity):
"""Representation of a Asus Tinker Board GPIO."""
def __init__(self, name, port, invert_logic):
"""Initialize the pin."""
self._name = name or DEVICE_DEFAULT_NAME
self._port = port
self._relay_time = DEFAULT_RELAY_TIME
self._invert_logic = 1 if invert_logic else 0
self._state = False
asus_gpio.write_output(self._port, self._invert_logic)
@property
def name(self):
"""Return the name of the switch."""
return self._name
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def is_on(self):
"""Return true if device is on."""
return self._state
def turn_on(self, **kwargs):
"""Turn the device on."""
asus_gpio.write_output(self._port, self._invert_logic ^ 1)
self._state = True
self.schedule_update_ha_state()
def turn_off(self, **kwargs):
"""Turn the device off."""
asus_gpio.write_output(self._port, self._invert_logic)
self._state = False
self.schedule_update_ha_state()
def trigger(self, **kwargs):
"""Trigger the cover."""
asus_gpio.write_output(self._port, self._invert_logic)
sleep(self._relay_time)
self._state = False
asus_gpio.write_output(self._port, self._invert_logic ^ 1)
def read_input(self, **kwargs):
return asus_gpio.read_input(port)
I don’t have a clear idea what should be the value passed to the class. Perhaps it should be a string.