Skip to content

Commit

Permalink
Add IDTECK proximity card component (#18309)
Browse files Browse the repository at this point in the history
* Added IDTECK proximity card sensor component.

* Moved from sensor to platform

* Made requested standards changes
  • Loading branch information
dubnom authored and MartinHjelmare committed Dec 31, 2018
1 parent 855274e commit 4b541f4
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -552,6 +552,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
75 changes: 75 additions & 0 deletions homeassistant/components/idteck_prox.py
@@ -0,0 +1,75 @@
"""Component for interfacing RFK101 proximity card readers.
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

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_IDTECK_PROX_KEYCARD = 'idteck_prox_keycard'

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 component."""
conf = config[DOMAIN]
for unit in conf:
host = unit[CONF_HOST]
port = unit[CONF_PORT]
name = unit[CONF_NAME]

try:
reader = IdteckReader(hass, host, port, name)
reader.connect()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, reader.stop)
except OSError as error:
_LOGGER.error('Error creating "%s". %s', name, error)
return False

return True


class IdteckReader():
"""Representation of an IDTECK proximity card reader."""

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

def connect(self):
"""Connect to the reader."""
from rfk101py.rfk101py import rfk101py
self._connection = rfk101py(self._host, self._port, self._callback)

def _callback(self, card):
"""Send a keycard event message into HASS whenever a card is read."""
self.hass.bus.fire(
EVENT_IDTECK_PROX_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 @@ -1416,6 +1416,9 @@ regenmaschine==1.1.0
# homeassistant.components.python_script
restrictedpython==4.0b7

# homeassistant.components.idteck_prox
rfk101py==0.0.1

# homeassistant.components.rflink
rflink==0.0.37

Expand Down

0 comments on commit 4b541f4

Please sign in to comment.