Update docstrings to match PEP257
parent
fd3ea95b82
commit
7d9e882d52
|
@ -1,7 +1,8 @@
|
||||||
"""
|
"""
|
||||||
homeassistant.components.sensor.tcp
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
Provides a sensor which gets its values from a TCP socket.
|
Provides a sensor which gets its values from a TCP socket.
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/sensor.tcp/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
@ -12,9 +13,6 @@ from homeassistant.util import template
|
||||||
from homeassistant.exceptions import TemplateError
|
from homeassistant.exceptions import TemplateError
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
|
||||||
# DEPENDENCIES = [DOMAIN]
|
|
||||||
|
|
||||||
DOMAIN = "tcp"
|
DOMAIN = "tcp"
|
||||||
|
|
||||||
CONF_PORT = "port"
|
CONF_PORT = "port"
|
||||||
|
@ -32,18 +30,18 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
""" Create the Sensor. """
|
"""Create the TCP Sensor."""
|
||||||
if not Sensor.validate_config(config):
|
if not Sensor.validate_config(config):
|
||||||
return False
|
return False
|
||||||
add_entities((Sensor(hass, config),))
|
add_entities((Sensor(hass, config),))
|
||||||
|
|
||||||
|
|
||||||
class Sensor(Entity):
|
class Sensor(Entity):
|
||||||
""" Sensor Entity which gets its value from a TCP socket. """
|
"""Sensor entity which gets its value from a TCP socket."""
|
||||||
required = tuple()
|
required = tuple()
|
||||||
|
|
||||||
def __init__(self, hass, config):
|
def __init__(self, hass, config):
|
||||||
""" Set all the config values if they exist and get initial state. """
|
"""Set all the config values if they exist and get initial state."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._config = {
|
self._config = {
|
||||||
CONF_NAME: config.get(CONF_NAME),
|
CONF_NAME: config.get(CONF_NAME),
|
||||||
|
@ -62,7 +60,7 @@ class Sensor(Entity):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_config(cls, config):
|
def validate_config(cls, config):
|
||||||
""" Ensure the config has all of the necessary values. """
|
"""Ensure the configuration has all of the necessary values."""
|
||||||
always_required = (CONF_HOST, CONF_PORT, CONF_PAYLOAD)
|
always_required = (CONF_HOST, CONF_PORT, CONF_PAYLOAD)
|
||||||
for key in always_required + tuple(cls.required):
|
for key in always_required + tuple(cls.required):
|
||||||
if key not in config:
|
if key not in config:
|
||||||
|
@ -73,6 +71,7 @@ class Sensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
"""The name of this sensor."""
|
||||||
name = self._config[CONF_NAME]
|
name = self._config[CONF_NAME]
|
||||||
if name is not None:
|
if name is not None:
|
||||||
return name
|
return name
|
||||||
|
@ -80,14 +79,16 @@ class Sensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
|
"""Unit of measurement of this entity."""
|
||||||
return self._config[CONF_UNIT]
|
return self._config[CONF_UNIT]
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
""" Get the latest value for this sensor. """
|
"""Get the latest value for this sensor."""
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||||
try:
|
try:
|
||||||
sock.connect(
|
sock.connect(
|
||||||
|
|
Loading…
Reference in New Issue