Fix docstrings to conform to pep

This commit is contained in:
MartinHjelmare 2015-12-08 01:03:07 +01:00
parent 59524c7933
commit 7cc707f1ce
3 changed files with 71 additions and 46 deletions

View File

@ -68,9 +68,7 @@ def setup(hass, config): # noqa
IS_METRIC = (hass.config.temperature_unit == TEMP_CELCIUS)
def callback_generator(port, devices):
"""
Generator of callback, should be run once per gateway setup.
"""
"""Return a new callback function. Run once per gateway setup."""
def node_update(update_type, nid):
"""Callback for node updates from the MySensors gateway."""
_LOGGER.info('update %s: node %s', update_type, nid)
@ -85,11 +83,7 @@ def setup(hass, config): # noqa
return node_update
def setup_gateway(port, persistence, persistence_file):
"""
Instantiate gateway, set gateway attributes and start gateway.
If persistence is true, update all nodes.
Listen for stop of home-assistant, then stop gateway.
"""
"""Return gateway after setup of the gateway."""
devices = {} # keep track of devices added to HA
gateway = mysensors.SerialGateway(port,
persistence=persistence,
@ -137,10 +131,7 @@ def setup(hass, config): # noqa
def mysensors_update(platform_type):
"""
Decorator for callback function for sensor updates from the MySensors
component.
"""
"""Decorator for callback function for mysensor updates."""
def wrapper(gateway, port, devices, nid):
"""Wrapper function in the decorator."""
sensor = gateway.sensors[nid]

View File

@ -23,7 +23,6 @@ DEPENDENCIES = ['mysensors']
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the mysensors platform for sensors."""
# Define the V_TYPES that the platform should handle as states.
v_types = []
for _, member in mysensors.CONST.SetReq.__members__.items():
@ -52,21 +51,39 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class MySensorsSensor(Entity):
"""Represent the value of a MySensors child node."""
""" Represents the value of a MySensors child node. """
# pylint: disable=too-many-arguments, too-many-instance-attributes
def __init__(self, port, node_id, child_id, name, value_type):
"""Setup class attributes on instantiation.
Args:
port (str): Gateway port.
node_id (str): Id of node.
child_id (str): Id of child.
name (str): Sketch name.
value_type (str): Value type of child. Value is entity state.
Attributes:
port (str): Gateway port.
node_id (str): Id of node.
child_id (str): Id of child.
_name (str): Sketch name.
value_type (str): Value type of child. Value is entity state.
battery_level (int): Node battery level.
_values (dict): Child values. Non state values set as state attributes.
"""
self.port = port
self._name = name
self.node_id = node_id
self.child_id = child_id
self.battery_level = 0
self._name = name
self.value_type = value_type
self.battery_level = 0
self._values = {}
def as_dict(self):
""" Returns a dict representation of this Entity. """
"""Return a dict representation of this Entity."""
return {
'port': self.port,
'name': self._name,
@ -89,7 +106,7 @@ class MySensorsSensor(Entity):
@property
def state(self):
""" Returns the state of the device. """
"""Return the state of the device."""
if not self._values:
return ''
return self._values[self.value_type]
@ -121,15 +138,14 @@ class MySensorsSensor(Entity):
@property
def device_state_attributes(self):
""" Returns device specific state attributes. """
"""Return device specific state attributes."""
device_attr = dict(self._values)
device_attr.pop(self.value_type, None)
return device_attr
@property
def state_attributes(self):
""" Returns the state attributes. """
"""Return the state attributes."""
data = {
mysensors.ATTR_NODE_ID: self.node_id,
mysensors.ATTR_CHILD_ID: self.child_id,

View File

@ -23,7 +23,6 @@ DEPENDENCIES = ['mysensors']
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the mysensors platform for switches."""
# Define the V_TYPES that the platform should handle as states.
v_types = []
for _, member in mysensors.CONST.SetReq.__members__.items():
@ -52,21 +51,39 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class MySensorsSwitch(SwitchDevice):
"""Represent the value of a MySensors child node."""
""" Represents the value of a MySensors child node. """
# pylint: disable=too-many-arguments, too-many-instance-attributes
def __init__(self, port, node_id, child_id, name, value_type):
"""Setup class attributes on instantiation.
Args:
port (str): Gateway port.
node_id (str): Id of node.
child_id (str): Id of child.
name (str): Sketch name.
value_type (str): Value type of child. Value is entity state.
Attributes:
port (str): Gateway port.
node_id (str): Id of node.
child_id (str): Id of child.
_name (str): Sketch name.
value_type (str): Value type of child. Value is entity state.
battery_level (int): Node battery level.
_values (dict): Child values. Non state values set as state attributes.
"""
self.port = port
self._name = name
self.node_id = node_id
self.child_id = child_id
self.battery_level = 0
self._name = name
self.value_type = value_type
self.battery_level = 0
self._values = {}
def as_dict(self):
""" Returns a dict representation of this Entity. """
"""Return a dict representation of this Entity."""
return {
'port': self.port,
'name': self._name,
@ -114,15 +131,14 @@ class MySensorsSwitch(SwitchDevice):
@property
def device_state_attributes(self):
""" Returns device specific state attributes. """
"""Return device specific state attributes."""
device_attr = dict(self._values)
device_attr.pop(self.value_type, None)
return device_attr
@property
def state_attributes(self):
""" Returns the state attributes. """
"""Return the state attributes."""
data = {
mysensors.ATTR_NODE_ID: self.node_id,
mysensors.ATTR_CHILD_ID: self.child_id,
@ -138,18 +154,20 @@ class MySensorsSwitch(SwitchDevice):
@property
def is_on(self):
""" Returns True if switch is on. """
"""Return True if switch is on."""
if self.value_type in self._values:
return self._values[self.value_type] == STATE_ON
return False
def turn_on(self):
""" Turns the switch on. """
"""Turn the switch on."""
mysensors.GATEWAYS[self.port].set_child_value(
self.node_id, self.child_id, self.value_type, 1)
self._values[self.value_type] = STATE_ON
self.update_ha_state()
def turn_off(self):
""" Turns the pin to low/off. """
"""Turn the pin to low/off."""
mysensors.GATEWAYS[self.port].set_child_value(
self.node_id, self.child_id, self.value_type, 0)
self._values[self.value_type] = STATE_OFF