mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix docstrings to conform to pep
This commit is contained in:
parent
59524c7933
commit
7cc707f1ce
@ -68,9 +68,7 @@ def setup(hass, config): # noqa
|
|||||||
IS_METRIC = (hass.config.temperature_unit == TEMP_CELCIUS)
|
IS_METRIC = (hass.config.temperature_unit == TEMP_CELCIUS)
|
||||||
|
|
||||||
def callback_generator(port, devices):
|
def callback_generator(port, devices):
|
||||||
"""
|
"""Return a new callback function. Run once per gateway setup."""
|
||||||
Generator of callback, should be run once per gateway setup.
|
|
||||||
"""
|
|
||||||
def node_update(update_type, nid):
|
def node_update(update_type, nid):
|
||||||
"""Callback for node updates from the MySensors gateway."""
|
"""Callback for node updates from the MySensors gateway."""
|
||||||
_LOGGER.info('update %s: node %s', update_type, nid)
|
_LOGGER.info('update %s: node %s', update_type, nid)
|
||||||
@ -85,11 +83,7 @@ def setup(hass, config): # noqa
|
|||||||
return node_update
|
return node_update
|
||||||
|
|
||||||
def setup_gateway(port, persistence, persistence_file):
|
def setup_gateway(port, persistence, persistence_file):
|
||||||
"""
|
"""Return gateway after setup of the gateway."""
|
||||||
Instantiate gateway, set gateway attributes and start gateway.
|
|
||||||
If persistence is true, update all nodes.
|
|
||||||
Listen for stop of home-assistant, then stop gateway.
|
|
||||||
"""
|
|
||||||
devices = {} # keep track of devices added to HA
|
devices = {} # keep track of devices added to HA
|
||||||
gateway = mysensors.SerialGateway(port,
|
gateway = mysensors.SerialGateway(port,
|
||||||
persistence=persistence,
|
persistence=persistence,
|
||||||
@ -137,10 +131,7 @@ def setup(hass, config): # noqa
|
|||||||
|
|
||||||
|
|
||||||
def mysensors_update(platform_type):
|
def mysensors_update(platform_type):
|
||||||
"""
|
"""Decorator for callback function for mysensor updates."""
|
||||||
Decorator for callback function for sensor updates from the MySensors
|
|
||||||
component.
|
|
||||||
"""
|
|
||||||
def wrapper(gateway, port, devices, nid):
|
def wrapper(gateway, port, devices, nid):
|
||||||
"""Wrapper function in the decorator."""
|
"""Wrapper function in the decorator."""
|
||||||
sensor = gateway.sensors[nid]
|
sensor = gateway.sensors[nid]
|
||||||
|
@ -23,7 +23,6 @@ DEPENDENCIES = ['mysensors']
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the mysensors platform for sensors."""
|
"""Setup the mysensors platform for sensors."""
|
||||||
|
|
||||||
# Define the V_TYPES that the platform should handle as states.
|
# Define the V_TYPES that the platform should handle as states.
|
||||||
v_types = []
|
v_types = []
|
||||||
for _, member in mysensors.CONST.SetReq.__members__.items():
|
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):
|
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
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
|
|
||||||
def __init__(self, port, node_id, child_id, name, value_type):
|
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.port = port
|
||||||
self._name = name
|
|
||||||
self.node_id = node_id
|
self.node_id = node_id
|
||||||
self.child_id = child_id
|
self.child_id = child_id
|
||||||
self.battery_level = 0
|
self._name = name
|
||||||
self.value_type = value_type
|
self.value_type = value_type
|
||||||
|
self.battery_level = 0
|
||||||
self._values = {}
|
self._values = {}
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
""" Returns a dict representation of this Entity. """
|
"""Return a dict representation of this Entity."""
|
||||||
return {
|
return {
|
||||||
'port': self.port,
|
'port': self.port,
|
||||||
'name': self._name,
|
'name': self._name,
|
||||||
@ -89,7 +106,7 @@ class MySensorsSensor(Entity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
""" Returns the state of the device. """
|
"""Return the state of the device."""
|
||||||
if not self._values:
|
if not self._values:
|
||||||
return ''
|
return ''
|
||||||
return self._values[self.value_type]
|
return self._values[self.value_type]
|
||||||
@ -121,15 +138,14 @@ class MySensorsSensor(Entity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
""" Returns device specific state attributes. """
|
"""Return device specific state attributes."""
|
||||||
device_attr = dict(self._values)
|
device_attr = dict(self._values)
|
||||||
device_attr.pop(self.value_type, None)
|
device_attr.pop(self.value_type, None)
|
||||||
return device_attr
|
return device_attr
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
""" Returns the state attributes. """
|
"""Return the state attributes."""
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
mysensors.ATTR_NODE_ID: self.node_id,
|
mysensors.ATTR_NODE_ID: self.node_id,
|
||||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
mysensors.ATTR_CHILD_ID: self.child_id,
|
||||||
|
@ -23,7 +23,6 @@ DEPENDENCIES = ['mysensors']
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the mysensors platform for switches."""
|
"""Setup the mysensors platform for switches."""
|
||||||
|
|
||||||
# Define the V_TYPES that the platform should handle as states.
|
# Define the V_TYPES that the platform should handle as states.
|
||||||
v_types = []
|
v_types = []
|
||||||
for _, member in mysensors.CONST.SetReq.__members__.items():
|
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):
|
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
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
|
|
||||||
def __init__(self, port, node_id, child_id, name, value_type):
|
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.port = port
|
||||||
self._name = name
|
|
||||||
self.node_id = node_id
|
self.node_id = node_id
|
||||||
self.child_id = child_id
|
self.child_id = child_id
|
||||||
self.battery_level = 0
|
self._name = name
|
||||||
self.value_type = value_type
|
self.value_type = value_type
|
||||||
|
self.battery_level = 0
|
||||||
self._values = {}
|
self._values = {}
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
""" Returns a dict representation of this Entity. """
|
"""Return a dict representation of this Entity."""
|
||||||
return {
|
return {
|
||||||
'port': self.port,
|
'port': self.port,
|
||||||
'name': self._name,
|
'name': self._name,
|
||||||
@ -114,15 +131,14 @@ class MySensorsSwitch(SwitchDevice):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
""" Returns device specific state attributes. """
|
"""Return device specific state attributes."""
|
||||||
device_attr = dict(self._values)
|
device_attr = dict(self._values)
|
||||||
device_attr.pop(self.value_type, None)
|
device_attr.pop(self.value_type, None)
|
||||||
return device_attr
|
return device_attr
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
""" Returns the state attributes. """
|
"""Return the state attributes."""
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
mysensors.ATTR_NODE_ID: self.node_id,
|
mysensors.ATTR_NODE_ID: self.node_id,
|
||||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
mysensors.ATTR_CHILD_ID: self.child_id,
|
||||||
@ -138,18 +154,20 @@ class MySensorsSwitch(SwitchDevice):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
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 self._values[self.value_type] == STATE_ON
|
||||||
|
return False
|
||||||
|
|
||||||
def turn_on(self):
|
def turn_on(self):
|
||||||
""" Turns the switch on. """
|
"""Turn the switch on."""
|
||||||
mysensors.GATEWAYS[self.port].set_child_value(
|
mysensors.GATEWAYS[self.port].set_child_value(
|
||||||
self.node_id, self.child_id, self.value_type, 1)
|
self.node_id, self.child_id, self.value_type, 1)
|
||||||
self._values[self.value_type] = STATE_ON
|
self._values[self.value_type] = STATE_ON
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
""" Turns the pin to low/off. """
|
"""Turn the pin to low/off."""
|
||||||
mysensors.GATEWAYS[self.port].set_child_value(
|
mysensors.GATEWAYS[self.port].set_child_value(
|
||||||
self.node_id, self.child_id, self.value_type, 0)
|
self.node_id, self.child_id, self.value_type, 0)
|
||||||
self._values[self.value_type] = STATE_OFF
|
self._values[self.value_type] = STATE_OFF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user