@@ -0,0 +1,2298 @@
+%22%22%22%0Ahomeassistant.components.switch.arduino%0A~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%0ASupport for switching Arduino pins on and off. So fare only digital pins are%0Asupported.%0A%0AConfiguration:%0A%0Aswitch:%0A  platform: arduino%0A  pins:%0A    11:%0A      name: Fan Office%0A      type: digital%0A    12:%0A      name: Light Desk%0A      type: digital%0A%0AVariables:%0A%0Apins%0A*Required%0AAn array specifying the digital pins to use on the Arduino board.%0A%0AThese are the variables for the pins array:%0A%0Aname%0A*Required%0AThe name for the pin that will be used in the frontend.%0A%0Atype%0A*Required%0AThe type of the pin: 'digital'.%0A%22%22%22%0Aimport logging%0A%0Aimport homeassistant.components.arduino as arduino%0Afrom homeassistant.components.switch import SwitchDevice%0Afrom homeassistant.const import DEVICE_DEFAULT_NAME%0A%0ADEPENDENCIES = %5B'arduino'%5D%0A%0A_LOGGER = logging.getLogger(__name__)%0A%0A%0Adef setup_platform(hass, config, add_devices, discovery_info=None):%0A    %22%22%22 Sets up the Arduino platform. %22%22%22%0A%0A    # Verify that Arduino board is present%0A    if arduino.BOARD is None:%0A        _LOGGER.error('A connection has not been made to the Arduino board.')%0A        return False%0A%0A    switches = %5B%5D%0A    pins = config.get('pins')%0A    for pinnum, pin in pins.items():%0A        if pin.get('name'):%0A            switches.append(ArduinoSwitch(pin.get('name'),%0A                                          pinnum,%0A                                          pin.get('type')))%0A    add_devices(switches)%0A%0A%0Aclass ArduinoSwitch(SwitchDevice):%0A    %22%22%22 Represents an Arduino Switch. %22%22%22%0A    def __init__(self, name, pin, pin_type):%0A        self._pin = pin%0A        self._name = name or DEVICE_DEFAULT_NAME%0A        self.pin_type = pin_type%0A        self.direction = 'out'%0A        self._state = False%0A%0A        arduino.BOARD.set_mode(self._pin, self.direction, self.pin_type)%0A%0A    @property%0A    def name(self):%0A        %22%22%22 Get the name of the pin. %22%22%22%0A        return self._name%0A%0A    @property%0A    def is_on(self):%0A        %22%22%22 Returns True if pin is high/on. %22%22%22%0A        return self._state%0A%0A    def turn_on(self):%0A        %22%22%22 Turns the pin to high/on. %22%22%22%0A        self._state = True%0A        arduino.BOARD.set_digital_out_high(self._pin)%0A%0A    def turn_off(self):%0A        %22%22%22 Turns the pin to low/off. %22%22%22%0A        self._state = False%0A        arduino.BOARD.set_digital_out_low(self._pin)%0A

add arduino switch platform