mirror of https://github.com/home-assistant/core
Modify docstrings to match PEP257
This commit is contained in:
parent
49982ac83c
commit
9c4fe6e7fe
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.lock
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Component to interface with various locks that can be controlled remotely.
|
||||
|
||||
For more details about this component, please refer to the documentation
|
||||
|
@ -43,13 +41,13 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def is_locked(hass, entity_id=None):
|
||||
""" Returns if the lock is locked based on the statemachine. """
|
||||
"""Returns if the lock is locked based on the statemachine."""
|
||||
entity_id = entity_id or ENTITY_ID_ALL_LOCKS
|
||||
return hass.states.is_state(entity_id, STATE_LOCKED)
|
||||
|
||||
|
||||
def lock(hass, entity_id=None, code=None):
|
||||
""" Locks all or specified locks. """
|
||||
"""Locks all or specified locks."""
|
||||
data = {}
|
||||
if code:
|
||||
data[ATTR_CODE] = code
|
||||
|
@ -60,7 +58,7 @@ def lock(hass, entity_id=None, code=None):
|
|||
|
||||
|
||||
def unlock(hass, entity_id=None, code=None):
|
||||
""" Unlocks all or specified locks. """
|
||||
"""Unlocks all or specified locks."""
|
||||
data = {}
|
||||
if code:
|
||||
data[ATTR_CODE] = code
|
||||
|
@ -71,14 +69,14 @@ def unlock(hass, entity_id=None, code=None):
|
|||
|
||||
|
||||
def setup(hass, config):
|
||||
""" Track states and offer events for locks. """
|
||||
"""Track states and offer events for locks."""
|
||||
component = EntityComponent(
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS,
|
||||
GROUP_NAME_ALL_LOCKS)
|
||||
component.setup(config)
|
||||
|
||||
def handle_lock_service(service):
|
||||
""" Handles calls to the lock services. """
|
||||
"""Handles calls to the lock services."""
|
||||
target_locks = component.extract_from_service(service)
|
||||
|
||||
if ATTR_CODE not in service.data:
|
||||
|
@ -106,30 +104,29 @@ def setup(hass, config):
|
|||
|
||||
|
||||
class LockDevice(Entity):
|
||||
""" Represents a lock within Home Assistant. """
|
||||
"""Represents a lock."""
|
||||
# pylint: disable=no-self-use
|
||||
|
||||
@property
|
||||
def code_format(self):
|
||||
""" regex for code format or None if no code is required. """
|
||||
"""Regex for code format or None if no code is required."""
|
||||
return None
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
""" Is the lock locked or unlocked. """
|
||||
"""Is the lock locked or unlocked."""
|
||||
return None
|
||||
|
||||
def lock(self, **kwargs):
|
||||
""" Locks the lock. """
|
||||
"""Locks the lock."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
""" Unlocks the lock. """
|
||||
"""Unlocks the lock."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
""" Return the state attributes. """
|
||||
"""Return the state attributes."""
|
||||
if self.code_format is None:
|
||||
return None
|
||||
state_attr = {
|
||||
|
@ -139,6 +136,7 @@ class LockDevice(Entity):
|
|||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state."""
|
||||
locked = self.is_locked
|
||||
if locked is None:
|
||||
return STATE_UNKNOWN
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.lock.verisure
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Interfaces with Verisure locks.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -17,8 +15,7 @@ ATTR_CODE = 'code'
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the Verisure platform. """
|
||||
|
||||
"""Sets up the Verisure platform."""
|
||||
locks = []
|
||||
if int(hub.config.get('locks', '1')):
|
||||
hub.update_locks()
|
||||
|
@ -31,8 +28,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
|
||||
# pylint: disable=abstract-method
|
||||
class VerisureDoorlock(LockDevice):
|
||||
""" Represents a Verisure doorlock status. """
|
||||
|
||||
"""Represents a Verisure doorlock."""
|
||||
def __init__(self, device_id):
|
||||
self._id = device_id
|
||||
self._state = STATE_UNKNOWN
|
||||
|
@ -40,21 +36,21 @@ class VerisureDoorlock(LockDevice):
|
|||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the device. """
|
||||
"""Returns the name of the lock."""
|
||||
return 'Lock {}'.format(self._id)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state of the device. """
|
||||
"""Returns the state of the lock."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def code_format(self):
|
||||
""" Six digit code required. """
|
||||
"""Six digit code required."""
|
||||
return '^\\d{%s}$' % self._digits
|
||||
|
||||
def update(self):
|
||||
""" Update lock status """
|
||||
"""Update lock status."""
|
||||
hub.update_locks()
|
||||
|
||||
if hub.lock_status[self._id].status == 'unlocked':
|
||||
|
@ -68,18 +64,18 @@ class VerisureDoorlock(LockDevice):
|
|||
|
||||
@property
|
||||
def is_locked(self):
|
||||
""" True if device is locked. """
|
||||
"""Return true if lock is locked."""
|
||||
return hub.lock_status[self._id].status
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
""" Send unlock command. """
|
||||
"""Send unlock command."""
|
||||
hub.my_pages.lock.set(kwargs[ATTR_CODE], self._id, 'UNLOCKED')
|
||||
_LOGGER.info('verisure doorlock unlocking')
|
||||
hub.my_pages.lock.wait_while_pending()
|
||||
self.update()
|
||||
|
||||
def lock(self, **kwargs):
|
||||
""" Send lock command. """
|
||||
"""Send lock command."""
|
||||
hub.my_pages.lock.set(kwargs[ATTR_CODE], self._id, 'LOCKED')
|
||||
_LOGGER.info('verisure doorlock locking')
|
||||
hub.my_pages.lock.wait_while_pending()
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.lock.wink
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Support for Wink locks.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -15,7 +13,7 @@ REQUIREMENTS = ['python-wink==0.6.2']
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the Wink platform. """
|
||||
"""Setup the Wink platform."""
|
||||
import pywink
|
||||
|
||||
if discovery_info is None:
|
||||
|
@ -33,34 +31,33 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
|
||||
|
||||
class WinkLockDevice(LockDevice):
|
||||
""" Represents a Wink lock. """
|
||||
|
||||
"""Represents a Wink lock."""
|
||||
def __init__(self, wink):
|
||||
self.wink = wink
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns the id of this wink lock """
|
||||
"""Return the id of this wink lock."""
|
||||
return "{}.{}".format(self.__class__, self.wink.device_id())
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the lock if any. """
|
||||
"""Return the name of the lock if any."""
|
||||
return self.wink.name()
|
||||
|
||||
def update(self):
|
||||
""" Update the state of the lock. """
|
||||
"""Update the state of the lock."""
|
||||
self.wink.update_state()
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
""" True if device is locked. """
|
||||
"""Return true if device is locked."""
|
||||
return self.wink.state()
|
||||
|
||||
def lock(self, **kwargs):
|
||||
""" Lock the device. """
|
||||
"""Lock the device."""
|
||||
self.wink.set_state(True)
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
""" Unlock the device. """
|
||||
"""Unlock the device."""
|
||||
self.wink.set_state(False)
|
||||
|
|
Loading…
Reference in New Issue