Skip to content

Added Zyxel Keenetic NDMS2 based routers support for device tracking#9315

Merged
MartinHjelmare merged 4 commits into
home-assistant:devfrom
foxel:keenetik-ndms2
Sep 16, 2017
Merged

Added Zyxel Keenetic NDMS2 based routers support for device tracking#9315
MartinHjelmare merged 4 commits into
home-assistant:devfrom
foxel:keenetik-ndms2

Conversation

@foxel
Copy link
Copy Markdown
Contributor

@foxel foxel commented Sep 6, 2017

Description:

Pull request in home-assistant.github.io with documentation: home-assistant/home-assistant.io#3373

Example entry for configuration.yaml (if applicable):

device_tracker:
  - platform: keenetic_ndms2
    host: !secret router_ip
    username: !secret router_username
    password: !secret router_password

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

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,
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.

There's already a global option consider_home to handle stale devices. You don't need to add this for this platform.

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.

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=[]):
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.

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.

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.

At least i use it to exclude some devices, e.g. IoT switches and so on from tracking.

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.

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
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 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
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 sort the imported names alphabetically 🔡.

self._username, self._password
))
except requests.exceptions.Timeout:
_LOGGER.exception(
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.

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(
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.

Error or warning.

result = res.json()
except ValueError:
# If json decoder could not parse the response
_LOGGER.exception("Failed to parse response from router")
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.

Error.

@MartinHjelmare
Copy link
Copy Markdown
Member

See my comment: #9315 (comment).

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

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'])
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.

You can remove ip and last_update as they are now not used anymore.

return False

# parsing response
now = dt_util.now()
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.

Remove.

continue

name = info.get('name')
last_results.append(Device(mac.upper(), name, ipv4, now))
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.

Update.

if info.get('interface') != self._interface:
continue
mac = info.get('mac')
ipv4 = info.get('ip')
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.

Remove.

mac = info.get('mac')
ipv4 = info.get('ip')
# No address = no item :)
if mac is None or ipv4 is None:
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.

Update.

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
import homeassistant.util.dt as dt_util
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.

Remove.

@foxel
Copy link
Copy Markdown
Contributor Author

foxel commented Sep 14, 2017

@MartinHjelmare, thanks for the catch

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Link to a docs PR in the description and we can merge this.

@MartinHjelmare MartinHjelmare merged commit 78bb0da into home-assistant:dev Sep 16, 2017
@balloob balloob mentioned this pull request Sep 22, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Mar 3, 2018
@foxel foxel deleted the keenetik-ndms2 branch November 14, 2019 14:37
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.

4 participants