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

Add IDTECK proximity card component #18309

Merged
merged 3 commits into from Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -503,6 +503,7 @@ omit =
homeassistant/components/folder_watcher.py
homeassistant/components/foursquare.py
homeassistant/components/goalfeed.py
homeassistant/components/idteck_prox.py
homeassistant/components/ifttt.py
homeassistant/components/image_processing/dlib_face_detect.py
homeassistant/components/image_processing/dlib_face_identify.py
Expand Down
70 changes: 70 additions & 0 deletions homeassistant/components/idteck_prox.py
@@ -0,0 +1,70 @@
"""Platform for interfacing RFK101 proximity card readers.
Copy link
Member

Choose a reason for hiding this comment

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

This is now a component, not a platform.


For more details about this component, please refer to the documentation at
https://home-assistant.io/components/idteck_prox/
"""
import logging
import voluptuous as vol
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
import homeassistant.helpers.config_validation as cv
from homeassistant.const import (
CONF_HOST, CONF_PORT, CONF_NAME, EVENT_HOMEASSISTANT_STOP)

REQUIREMENTS = ['rfk101py==0.0.1']

_LOGGER = logging.getLogger(__name__)

DOMAIN = "idteck_prox"

EVENT_KEYCARD = 'keycard'
Copy link
Member

Choose a reason for hiding this comment

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

Prefix the event string with the component name separated with underscore.


CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.All(cv.ensure_list, [vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PORT): cv.port,
vol.Required(CONF_NAME): cv.string,
})])
}, extra=vol.ALLOW_EXTRA)


def setup(hass, config):
"""Set up the IDTECK proximity card platform."""
Copy link
Member

Choose a reason for hiding this comment

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

component

conf = config[DOMAIN]
for unit in conf:
host = unit[CONF_HOST]
port = unit[CONF_PORT]
name = unit[CONF_NAME]

try:
idteck_platform(hass, host, port, name)
except OSError as error:
_LOGGER.error('Error creating "%s". %s', name, error)
return False

return True

class idteck_platform():

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

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 CapWords convention for class names:
https://www.python.org/dev/peps/pep-0008/#class-names

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps IdteckReader?

"""Representation of an ITECK proximity card reader."""
Copy link
Member

Choose a reason for hiding this comment

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

IDTECK


def __init__(self, hass, host, port, name):
"""Initialize the sensor."""
self.hass = hass
self._host = host
self._port = port
self._name = name
self._connection = None

from rfk101py.rfk101py import rfk101py
self._connection = rfk101py(self._host, self._port, self._callback)
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved

hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, self.stop)
Copy link
Member

Choose a reason for hiding this comment

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

Please move this out to setup function. We don't want side effects in init method.


def _callback(self, card):
"""Send a keycard event message into HASS whenever a card is read."""
self.hass.bus.fire(
EVENT_KEYCARD, {'card': card, 'name': self._name})

def stop(self):
"""Close resources."""
if self._connection:
self._connection.close()
self._connection = None
3 changes: 3 additions & 0 deletions requirements_all.txt
Expand Up @@ -1287,6 +1287,9 @@ regenmaschine==1.0.2
# homeassistant.components.python_script
restrictedpython==4.0b5

# homeassistant.components.idteck_prox
rfk101py==0.0.1

# homeassistant.components.rflink
rflink==0.0.37

Expand Down