Inverted_logic invalidate all group

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 pict
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.

Just a guess but uncommenting the line hasn’t changed your entity ids to something like switch.gate_inverted instead of switch.gate has it?

Did you check the developer tools states menu for the entity_ids?

Thank you for the guideline.
As you proposed, it is not showing the switches group. So the states are without those entities.
Also the configuration doesn’t pass the integrity check.

Yeah it was just a guess, what you are doing is well above my level of incompetence. :slight_smile:

The way you wrote your schema, the following config would be correct.

- platform: asus_gpio
  ports:
    15: Gate
    16: Pillar Lights
    1: Extra
  invert_logic: true

If you are trying to invert the logic on an individual port, you’d want this schema:

CONF_ENTITY_NAME = 'name'
CONF_ENTITY_INVERT = 'invert'

_SWITCHES_SCHEMA = vol.Schema({
    vol.Optional(CONF_ENTITY_NAME): cv.string,
    vol.Optional(CONF_ENTITY_INVERT): cv.boolean,
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_PORTS): 
      vol.Schema({cv.positive_int, _SWITCHES_SCHEMA})
})

with this config

- platform: asus_gpio
  ports:
    15:
      name: Gate
    16:
      name: Pillar Lights
    1:
      name: Extra
      invert: true

Or you could go the list object route:

CONF_ENTITY_NAME = 'name'
CONF_ENTITY_PORT = 'port'
CONF_ENTITY_INVERT = 'invert'

_SWITCHES_SCHEMA = vol.Schema({
    vol.Required(CONF_ENTITY_PORT): cv.positive_int,
    vol.Optional(CONF_ENTITY_NAME): cv.string,
    vol.Optional(CONF_ENTITY_INVERT): cv.boolean,
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_PORTS):
      vol.All(cv.ensure_list, [_SWITCHES_SCHEMA])
})

with this config

- platform: asus_gpio
  ports:
    - port: 15
      name: Gate
    - port: 16
      name: Pillar Lights
    - port: 1
      name: Extra
      invert: true

Personally, i’d go list route.

As far as I’m understanding, it seems that I oversought a wrong indentation.
Well I don’t expect to use a separated inverted mode, as it is a module (eastern one) with 4 relays.
Perhaps if I’ll expand the outputs I’ll have to care what it should do for that logic.

EDIT

Exactly an indentation problem !! :sob: