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

Ping device tracker #5176

Merged
merged 2 commits into from
Jan 4, 2017
Merged

Conversation

michaelarnauts
Copy link
Contributor

@michaelarnauts michaelarnauts commented Jan 4, 2017

Description:
Device tracker that uses ICMP ping messages to detect host status.

This can be useful when devices are running a firewall and is blocking UDP or TCP packets, but responding to ICMP (like Android phones).
This tracker doesn't need to know the mac address, since the host can be on a different subnet. This makes this the ideal solution to detect hosts on a different subnet when nmap or other solutions don't work since arp doesn't work.

Based on the code of @scipioni of PR #4577 and PR #4420, but dropped arp and added command line options to ping for windows, also, the way the hosts are defined isn't a list but key-value pairs.

Related issue (if applicable): fixes #

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

Example entry for configuration.yaml (if applicable):

device_tracker:
  - platform: ping
    count: 3 # number of packet used for each device (avoid false detection)
    hosts:
      hostone: 192.168.2.10
      hosttwo: 192.168.2.25

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
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@mention-bot
Copy link

@michaelarnauts, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @robbiet480 to be potential reviewers.

@michaelarnauts
Copy link
Contributor Author

@scipioni can you also take a look?
I used @balloob 's suggestion from #4577 (comment) to add the dev_id, since the IP addresses should be fixed anyway. The count option of the ping is also always 1, since you did it multiple times in a for loop anyway if count > 1.

@scipioni
Copy link
Contributor

scipioni commented Jan 4, 2017 via email

@michaelarnauts
Copy link
Contributor Author

That's right, but alive hosts will also be pinged number times then. Isn't the purpose of count to give it number retries in case the hosts doesn't answer?

Also, what should be the state of the host if it replies one time, and fails to reply another time (with count=2)? If it should be considered alive when at least one reply has been received, it's a waste of resources to send another ping.

@scipioni
Copy link
Contributor

scipioni commented Jan 4, 2017 via email

@balloob
Copy link
Member

balloob commented Jan 4, 2017

Looks good.

@balloob balloob merged commit 5e8e2a8 into home-assistant:dev Jan 4, 2017
@michaelarnauts michaelarnauts deleted the ping_device_tracker branch January 4, 2017 20:36
@home-assistant home-assistant locked and limited conversation to collaborators Apr 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants