Add link to docs and update docstrings
This commit is contained in:
parent
ce9f76a0be
commit
232aa792f1
1 changed files with 15 additions and 6 deletions
|
@ -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
|
from glob import glob
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -6,7 +13,6 @@ import time
|
||||||
from homeassistant.const import TEMP_CELCIUS, STATE_UNKNOWN
|
from homeassistant.const import TEMP_CELCIUS, STATE_UNKNOWN
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
|
||||||
BASE_DIR = '/sys/bus/w1/devices/'
|
BASE_DIR = '/sys/bus/w1/devices/'
|
||||||
DEVICE_FOLDERS = glob(os.path.join(BASE_DIR, '28*'))
|
DEVICE_FOLDERS = glob(os.path.join(BASE_DIR, '28*'))
|
||||||
SENSOR_IDS = []
|
SENSOR_IDS = []
|
||||||
|
@ -20,7 +26,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
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 == []:
|
if DEVICE_FILES == []:
|
||||||
_LOGGER.error('No onewire sensor found.')
|
_LOGGER.error('No onewire sensor found.')
|
||||||
|
@ -51,7 +57,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class OneWire(Entity):
|
class OneWire(Entity):
|
||||||
""" A Dallas 1 Wire Sensor"""
|
""" An One wire Sensor. """
|
||||||
|
|
||||||
def __init__(self, name, device_file):
|
def __init__(self, name, device_file):
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -60,7 +66,7 @@ class OneWire(Entity):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def _read_temp_raw(self):
|
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')
|
ds_device_file = open(self._device_file, 'r')
|
||||||
lines = ds_device_file.readlines()
|
lines = ds_device_file.readlines()
|
||||||
ds_device_file.close()
|
ds_device_file.close()
|
||||||
|
@ -68,18 +74,21 @@ class OneWire(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
""" The name of the sensor. """
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
""" return temperature in unit_of_measurement"""
|
""" Returns the state of the device. """
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
|
""" Unit the value is expressed in. """
|
||||||
return TEMP_CELCIUS
|
return TEMP_CELCIUS
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
""" Gets the latest data from the device. """
|
||||||
lines = self._read_temp_raw()
|
lines = self._read_temp_raw()
|
||||||
while lines[0].strip()[-3:] != 'YES':
|
while lines[0].strip()[-3:] != 'YES':
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue