Skip to content

Added option to invert aREST pin switch logic for active low relays#14467

Merged
fabaff merged 5 commits into
home-assistant:devfrom
w1ll1am23:add_arest_switch_invert
May 16, 2018
Merged

Added option to invert aREST pin switch logic for active low relays#14467
fabaff merged 5 commits into
home-assistant:devfrom
w1ll1am23:add_arest_switch_invert

Conversation

@w1ll1am23
Copy link
Copy Markdown
Contributor

@w1ll1am23 w1ll1am23 commented May 15, 2018

Description:

The current aREST pin switch assumes that setting the pin HIGH will turn a switch on, however when using the widely available and super common mechanical relay module that isn't the case. These modules are active low, meaning that the relay is turned on when the pin is set LOW. This change allows the user to specify if the pin switch logic should be inverted i.e. HIGH = off and LOW = on

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5377

Example entry for configuration.yaml (if applicable):

  - platform: arest
    resource: http://192.168.X.X
    pins:
      2:
        name: Switch One
        invert: True
      3:
        name: Switch Two
        invert: True

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

one_or_zero = 1 if self.invert else 0
request = requests.get(
'{}/digital/{}/0'.format(self._resource, self._pin), timeout=10)
'{}/digital/{}/{}'.format(self._resource, self._pin, one_or_zero), timeout=10)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (90 > 79 characters)

one_or_zero = 0 if self.invert else 1
request = requests.get(
'{}/digital/{}/1'.format(self._resource, self._pin), timeout=10)
'{}/digital/{}/{}'.format(self._resource, self._pin, one_or_zero), timeout=10)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (90 > 79 characters)


PIN_FUNCTION_SCHEMA = vol.Schema({
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_INVERT): cv.boolean,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply the default (False) here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


def turn_off(self, **kwargs):
"""Turn the device off."""
one_or_zero = 1 if self.invert else 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not happy about the naming. turn_off_payload = int(not invert)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (83 > 79 characters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (82 > 79 characters)

@home-assistant home-assistant deleted a comment from homeassistant May 15, 2018
dev.append(ArestSwitchPin(
resource, config.get(CONF_NAME, response.json()[CONF_NAME]),
pin.get(CONF_NAME), pinnum))
pin.get(CONF_NAME), pinnum, pin.get(CONF_INVERT, False)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the default here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Done.

Copy link
Copy Markdown
Member

@syssi syssi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGFM. Please update the docs.

w1ll1am23 pushed a commit to home-assistant/home-assistant.io that referenced this pull request May 15, 2018
@fabaff fabaff merged commit 1533a68 into home-assistant:dev May 16, 2018
@balloob balloob mentioned this pull request May 28, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
…ome-assistant#14467)

* Added option to invert aREST pin switch logic for active low relays

* Fixed line lengths

* Changed naming and set optional invert default value.

* Fixed line length

* Removed default from get
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
@ghost ghost removed the platform: switch.arest label Mar 21, 2019
@ghost ghost added the integration: arest label Mar 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants