Added Zyxel Keenetic NDMS2 based routers support for device tracking#9315
Conversation
MartinHjelmare
left a comment
There was a problem hiding this comment.
I think you can remove the two options CONF_HOME_INTERVAL and CONF_EXCLUDE. See below for all comments.
You also need to fix the linting errors, see the travis build log. Also add a line for this platform in .coveragerc to remove the platform from the coveralls build.
| vol.Required(CONF_USERNAME): cv.string, | ||
| vol.Required(CONF_PASSWORD): cv.string, | ||
| vol.Required(CONF_INTERFACE, default=DEFAULT_INTERFACE): cv.string, | ||
| vol.Required(CONF_HOME_INTERVAL, default=0): cv.positive_int, |
There was a problem hiding this comment.
There's already a global option consider_home to handle stale devices. You don't need to add this for this platform.
There was a problem hiding this comment.
Looked into it. Looks like so
| vol.Required(CONF_PASSWORD): cv.string, | ||
| vol.Required(CONF_INTERFACE, default=DEFAULT_INTERFACE): cv.string, | ||
| vol.Required(CONF_HOME_INTERVAL, default=0): cv.positive_int, | ||
| vol.Optional(CONF_EXCLUDE, default=[]): |
There was a problem hiding this comment.
You seem to have modeled this platform after the NMAP device tracker. That one is a special case which requires the CONF_EXCLUDE option. I don't think you need that option for this platform.
There was a problem hiding this comment.
At least i use it to exclude some devices, e.g. IoT switches and so on from tracking.
There was a problem hiding this comment.
There is already the track boolean option in the known_devices.yaml for this purpose. You can also set the global option track_new_devices to false in the config if you don't want to track new devices.
| import logging | ||
|
|
||
| import requests | ||
| from collections import namedtuple |
There was a problem hiding this comment.
Please move this line to the builtin group above.
| from homeassistant.components.device_tracker import ( | ||
| DOMAIN, PLATFORM_SCHEMA, DeviceScanner) | ||
| from homeassistant.const import ( | ||
| CONF_HOST, CONF_USERNAME, CONF_PASSWORD |
There was a problem hiding this comment.
Please sort the imported names alphabetically 🔡.
| self._username, self._password | ||
| )) | ||
| except requests.exceptions.Timeout: | ||
| _LOGGER.exception( |
There was a problem hiding this comment.
Log with error is enough.
| "Connection to the router timed out at URL %s", self._url) | ||
| return False | ||
| if res.status_code != 200: | ||
| _LOGGER.exception( |
| result = res.json() | ||
| except ValueError: | ||
| # If json decoder could not parse the response | ||
| _LOGGER.exception("Failed to parse response from router") |
|
See my comment: #9315 (comment). |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Clean the remaining things and this is good to go.
| return scanner if scanner.success_init else None | ||
|
|
||
|
|
||
| Device = namedtuple('Device', ['mac', 'name', 'ip', 'last_update']) |
There was a problem hiding this comment.
You can remove ip and last_update as they are now not used anymore.
| return False | ||
|
|
||
| # parsing response | ||
| now = dt_util.now() |
| continue | ||
|
|
||
| name = info.get('name') | ||
| last_results.append(Device(mac.upper(), name, ipv4, now)) |
| if info.get('interface') != self._interface: | ||
| continue | ||
| mac = info.get('mac') | ||
| ipv4 = info.get('ip') |
| mac = info.get('mac') | ||
| ipv4 = info.get('ip') | ||
| # No address = no item :) | ||
| if mac is None or ipv4 is None: |
| import voluptuous as vol | ||
|
|
||
| import homeassistant.helpers.config_validation as cv | ||
| import homeassistant.util.dt as dt_util |
|
@MartinHjelmare, thanks for the catch |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Link to a docs PR in the description and we can merge this.
Description:
Pull request in home-assistant.github.io with documentation: home-assistant/home-assistant.io#3373
Example entry for
configuration.yaml(if applicable):