Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telnet switch #8913

Merged
merged 8 commits into from
Sep 18, 2017
Merged

Telnet switch #8913

merged 8 commits into from
Sep 18, 2017

Conversation

multiholle
Copy link
Contributor

@multiholle multiholle commented Aug 10, 2017

Description:

New platform telnet switch. Allows to control a device with telnet commands for on and off. Can fetch the state of the device or work as optimistic switch.

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

Example entry for configuration.yaml (if applicable):

switch:
  platform: telnet
  switches:
    projector:
      resource: "host_or_ip"
      command_on: "PWR ON"
      command_off: "PWR OFF"
      command_state: "PWR?"
      value_template: '{{ value == "PWR=01" }}'

Checklist:

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

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

Copy link
Contributor

@emlove emlove left a comment

Choose a reason for hiding this comment

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

Looks great overall! Just a few small questions/requests.

vol.Required(CONF_COMMAND_ON): cv.string,
vol.Optional(CONF_COMMAND_STATE): cv.string,
vol.Optional(CONF_FRIENDLY_NAME): cv.string,
vol.Optional(CONF_OPTIMISTIC): cv.boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we drop the optimistic configuration and just assume it's optimistic if there's no command state defined, or is there something I'm missing? For example, assumed_state can just be return self._command_state is None.

"""Update device state."""
response = self.__telnet_command(self._command_state)
if response:
_LOGGER.error(
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be debug level, correct?

self._optimistic = optimistic
self._value_template = value_template

def __telnet_command(self, command):
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nitpick, but single underscore prefix is preferred for normal internal methods.

@multiholle
Copy link
Contributor Author

Updated PR.

@emlove
Copy link
Contributor

emlove commented Aug 13, 2017

Good to go once the docs PR is up-to-date.

@lwis
Copy link
Member

lwis commented Aug 17, 2017

Should the encoding be hardcoded to ASCII? Doesn't it depend on what the host is configured to accept?

@multiholle
Copy link
Contributor Author

Here it states that Telnet uses ASCII encoding: http://www.pcmicro.com/netfoss/telnet.html

"""Update device state."""
response = self._telnet_command(self._command_state)
if response:
_LOGGER.info(
Copy link
Member

Choose a reason for hiding this comment

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

Don't log this. Maybe a debug but not more.

@pvizeli
Copy link
Member

pvizeli commented Aug 17, 2017

I think if someone have a no ASCII Telnet device, he can make a PR for set encoding as options.

vol.Required(CONF_COMMAND_OFF): cv.string,
vol.Required(CONF_COMMAND_ON): cv.string,
vol.Optional(CONF_COMMAND_STATE): cv.string,
vol.Optional(CONF_FRIENDLY_NAME): cv.string,
Copy link
Member

Choose a reason for hiding this comment

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

Please use CONF_NAME instead of CONF_FRIENDLY_NAME.


DEFAULT_PORT = 23

SWITCH_SCHEMA = vol.Schema({
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to keep it ordered.


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Find and return switches controlled by shell commands."""
Copy link
Member

Choose a reason for hiding this comment

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

Stale docstring.

@pvizeli
Copy link
Member

pvizeli commented Aug 30, 2017

Ping @multiholle

@multiholle
Copy link
Contributor Author

multiholle commented Aug 31, 2017

I'm quite busy at the moment. I'm trying to get back to the PR next week.

@multiholle
Copy link
Contributor Author

@pvizeli @fabaff I updated the pull request.

@pvizeli pvizeli merged commit 5851944 into home-assistant:dev Sep 18, 2017
@balloob balloob mentioned this pull request Sep 22, 2017
@elRadix
Copy link

elRadix commented Sep 23, 2017

How can I use this addon when authentication is required in order to perform the on/off commands
and would I use this addon in order to replace my script with status of the switch ****

#!/usr/bin/expect
spawn telnet 192.168.1.61 2024
expect ">Ready"
send "\r"
send "Pass password \r"
send "Setrelay 34,1 \r" # switch ON
>Relay 34,ON
send "Setrelay 34,0 \r" # switch OFF
>Relay 34,OFF
send "Getrelay 34\r"   # switch status 
>Relay 34,ON

@MartinHjelmare
Copy link
Member

Please use the forum or chat for support questions.

https://home-assistant.io/help/#communication-channels

@home-assistant home-assistant locked and limited conversation to collaborators Sep 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants