1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Update/add docstrings (PEP257)

This commit is contained in:
Fabian Affolter
2016-02-23 06:21:49 +01:00
parent c64da761f1
commit 60d579af84
46 changed files with 407 additions and 510 deletions

View File

@@ -1,6 +1,4 @@
"""
homeassistant.components.modbus
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Modbus sensors.
For more details about this platform, please refer to the documentation at
@@ -18,7 +16,7 @@ DEPENDENCIES = ['modbus']
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Read config and create Modbus devices. """
"""Create Modbus devices."""
sensors = []
slave = config.get("slave", None)
if modbus.TYPE == "serial" and not slave:
@@ -54,7 +52,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ModbusSensor(Entity):
# pylint: disable=too-many-arguments
""" Represents a Modbus Sensor. """
"""Represents a Modbus Sensor."""
def __init__(self, name, slave, register, bit=None, unit=None, coil=False):
self._name = name
@@ -66,26 +64,24 @@ class ModbusSensor(Entity):
self._coil = coil
def __str__(self):
"""Returns the name and the state of the sensor."""
return "%s: %s" % (self.name, self.state)
@property
def should_poll(self):
"""
We should poll, because slaves are not allowed to
initiate communication on Modbus networks.
"""
""" Polling needed."""
return True
@property
def unique_id(self):
""" Returns a unique id. """
"""Returns a unique id."""
return "MODBUS-SENSOR-{}-{}-{}".format(self.slave,
self.register,
self.bit)
@property
def state(self):
""" Returns the state of the sensor. """
"""Returns the state of the sensor."""
if self.bit:
return STATE_ON if self._value else STATE_OFF
else:
@@ -93,12 +89,12 @@ class ModbusSensor(Entity):
@property
def name(self):
""" Get the name of the sensor. """
"""Get the name of the sensor."""
return self._name
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity, if any. """
"""Unit of measurement of this entity, if any."""
if self._unit == "C":
return TEMP_CELCIUS
elif self._unit == "F":
@@ -107,7 +103,7 @@ class ModbusSensor(Entity):
return self._unit
def update(self):
""" Update the state of the sensor. """
"""Update the state of the sensor."""
if self._coil:
result = modbus.NETWORK.read_coils(self.register, 1)
self._value = result.bits[0]