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