8000 Nello.io lock support by pschmitt · Pull Request #8957 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Nello.io lock support #8957

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

Merged
merged 3 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ omit =
homeassistant/components/light/yeelightsunflower.py
homeassistant/components/light/zengge.py
homeassistant/components/lirc.py
homeassistant/components/lock/nello.py
homeassistant/components/lock/nuki.py
homeassistant/components/lock/lockitron.py
homeassistant/components/lock/sesame.py
Expand Down
99 changes: 99 additions & 0 deletions homeassistant/components/lock/nello.py
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
Nello.io lock platform.

For more details about this platform, please refer to the documentation
https://home-assistant.io/components/lock.nello/
"""
from itertools import filterfalse
import logging

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.lock import (LockDevice, PLATFORM_SCHEMA)
from homeassistant.const import (CONF_PASSWORD, CONF_USERNAME)

REQUIREMENTS = ['pynello==1.5']

_LOGGER = logging.getLogger(__name__)

ATTR_ADDRESS = 'address'
ATTR_LOCATION_ID = 'location_id'
EVENT_DOOR_BELL = 'nello_bell_ring'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string
})


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Nello lock platform."""
from pynello import Nello
nello = Nello(config.get(CONF_USERNAME), config.get(CONF_PASSWORD))
add_devices([NelloLock(lock) for lock in nello.locations], True)


class NelloLock(LockDevice):
"""Representation of a Nello lock."""

def __init__(self, nello_lock):
"""Initialize the lock."""
self._nello_lock = nello_lock
self._device_attrs = None
self._activity = None
self._name = None

@property
def name(self):
"""Return the name of the lock."""
return self._name

@property
def is_locked(self):
"""Return true if lock is locked."""
return True

@property
def device_state_attributes(self):
"""Return the device specific state attributes."""
return self._device_attrs

def update(self):
"""Update the nello lock properties."""
self._nello_lock.update()
# Location identifiers
location_id = self._nello_lock.location_id
short_id = self._nello_lock.short_id
address = self._nello_lock.address
self._name = 'Nello {}'.format(short_id)
self._device_attrs = {
ATTR_ADDRESS: address,
ATTR_LOCATION_ID: location_id
}
# Process recent activity
activity = self._nello_lock.activity
if self._activity:
# Filter out old events
new_activity = list(
filterfalse(lambda x: x in self._activity, activity))
if new_activity:
for act in new_activity:
activity_type = act.get('type')
if activity_type == 'bell.ring.denied':
event_data = {
'address': address,
'date': act.get('date'),
'description': act.get('description'),
'location_id': location_id,
'short_id': short_id
}
self.hass.bus.fire(EVENT_DOOR_BELL, event_data)
# Save the activity history so that we don't trigger an event twice
self._activity = activity

def unlock(self, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is a little confusing. Isn't self._locked always going to be reset to True before this method exits?

Copy link
Contributor Author
@pschmitt pschmitt Aug 13, 2017

Choose a reason for hiding this comment

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

Yes. See 55ef048

"""Unlock the device."""
if not self._nello_lock.open_door():
_LOGGER.error("Failed to unlock")
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ pymyq==0.0.8
# homeassistant.components.mysensors
pymysensors==0.10.0

# homeassistant.components.lock.nello
pynello==1.5

# homeassistant.components.device_tracker.netgear
pynetgear==0.3.3

Expand Down
0