From 58f1d1754e1af545b26c75e95ebcadb247355348 Mon Sep 17 00:00:00 2001 From: Michael Auchter Date: Tue, 16 Jun 2020 07:42:21 -0500 Subject: [PATCH] Fix remote_rpi_gpio switch inversion (#34390) This removes the double-inversion of switches on the remote_rpi_gpio platform. Fixes #24571 --- homeassistant/components/remote_rpi_gpio/__init__.py | 4 +++- homeassistant/components/remote_rpi_gpio/switch.py | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/remote_rpi_gpio/__init__.py b/homeassistant/components/remote_rpi_gpio/__init__.py index e1b66128e3f..aa0a75c3331 100644 --- a/homeassistant/components/remote_rpi_gpio/__init__.py +++ b/homeassistant/components/remote_rpi_gpio/__init__.py @@ -26,7 +26,9 @@ def setup_output(address, port, invert_logic): """Set up a GPIO as output.""" try: - return LED(port, active_high=invert_logic, pin_factory=PiGPIOFactory(address)) + return LED( + port, active_high=not invert_logic, pin_factory=PiGPIOFactory(address) + ) except (ValueError, IndexError, KeyError): return None diff --git a/homeassistant/components/remote_rpi_gpio/switch.py b/homeassistant/components/remote_rpi_gpio/switch.py index a5b255179cd..42ce258ef98 100644 --- a/homeassistant/components/remote_rpi_gpio/switch.py +++ b/homeassistant/components/remote_rpi_gpio/switch.py @@ -37,7 +37,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): led = remote_rpi_gpio.setup_output(address, port, invert_logic) except (ValueError, IndexError, KeyError, OSError): return - new_switch = RemoteRPiGPIOSwitch(name, led, invert_logic) + new_switch = RemoteRPiGPIOSwitch(name, led) devices.append(new_switch) add_entities(devices) @@ -46,11 +46,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class RemoteRPiGPIOSwitch(SwitchDevice): """Representation of a Remtoe Raspberry Pi GPIO.""" - def __init__(self, name, led, invert_logic): + def __init__(self, name, led): """Initialize the pin.""" self._name = name or DEVICE_DEFAULT_NAME self._state = False - self._invert_logic = invert_logic self._switch = led @property @@ -75,12 +74,12 @@ class RemoteRPiGPIOSwitch(SwitchDevice): def turn_on(self, **kwargs): """Turn the device on.""" - remote_rpi_gpio.write_output(self._switch, 0 if self._invert_logic else 1) + remote_rpi_gpio.write_output(self._switch, 1) self._state = True self.schedule_update_ha_state() def turn_off(self, **kwargs): """Turn the device off.""" - remote_rpi_gpio.write_output(self._switch, 1 if self._invert_logic else 0) + remote_rpi_gpio.write_output(self._switch, 0) self._state = False self.schedule_update_ha_state()