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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Platform 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 | ||
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use CapWords convention for class names: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps |
||
"""Representation of an ITECK proximity card reader.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this out to |
||
|
||
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 |
There was a problem hiding this comment.
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.