Add link to docs and update docstrings

This commit is contained in:
Fabian Affolter 2016-01-27 07:28:18 +01:00
parent ce9f76a0be
commit 232aa792f1

View file

@ -1,4 +1,11 @@
""" Support for DS18B20 One Wire Sensors"""
"""
homeassistant.components.sensor.onewire
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for DS18B20 One Wire Sensors.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.onewire/
"""
from glob import glob
import logging
import os
@ -6,7 +13,6 @@ import time
from homeassistant.const import TEMP_CELCIUS, STATE_UNKNOWN
from homeassistant.helpers.entity import Entity
BASE_DIR = '/sys/bus/w1/devices/'
DEVICE_FOLDERS = glob(os.path.join(BASE_DIR, '28*'))
SENSOR_IDS = []
@ -20,7 +26,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the one wire Sensors"""
""" Sets up the one wire Sensors. """
if DEVICE_FILES == []:
_LOGGER.error('No onewire sensor found.')
@ -51,7 +57,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class OneWire(Entity):
""" A Dallas 1 Wire Sensor"""
""" An One wire Sensor. """
def __init__(self, name, device_file):
self._name = name
@ -60,7 +66,7 @@ class OneWire(Entity):
self.update()
def _read_temp_raw(self):
""" read the temperature as it is returned by the sensor"""
""" Read the temperature as it is returned by the sensor. """
ds_device_file = open(self._device_file, 'r')
lines = ds_device_file.readlines()
ds_device_file.close()
@ -68,18 +74,21 @@ class OneWire(Entity):
@property
def name(self):
""" The name of the sensor. """
return self._name
@property
def state(self):
""" return temperature in unit_of_measurement"""
""" Returns the state of the device. """
return self._state
@property
def unit_of_measurement(self):
""" Unit the value is expressed in. """
return TEMP_CELCIUS
def update(self):
""" Gets the latest data from the device. """
lines = self._read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)