Update docstrings (#7374)

* Update docstrings

* Update docstrings

* Update docstrings

* Update docstrings

* Update docstrings

* Update docstrings

* Update docstring

* Update docstrings

* Update docstrings

* Fix lint issues

* Update docstrings

* Revert changes in dict
This commit is contained in:
Fabian Affolter 2017-05-02 18:18:47 +02:00 committed by Paulus Schoutsen
parent 0e08925259
commit a4f1f6e724
340 changed files with 1533 additions and 1708 deletions

View file

@ -5,28 +5,28 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.zabbix/
"""
import logging
import voluptuous as vol
from homeassistant.helpers.entity import Entity
import homeassistant.components.zabbix as zabbix
from homeassistant.components.sensor import PLATFORM_SCHEMA
import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['zabbix']
_CONF_TRIGGERS = "triggers"
_CONF_HOSTIDS = "hostids"
_CONF_INDIVIDUAL = "individual"
_CONF_NAME = "name"
_CONF_TRIGGERS = 'triggers'
_CONF_HOSTIDS = 'hostids'
_CONF_INDIVIDUAL = 'individual'
_ZABBIX_ID_LIST_SCHEMA = vol.Schema([int])
_ZABBIX_TRIGGER_SCHEMA = vol.Schema({
vol.Optional(_CONF_HOSTIDS, default=[]): _ZABBIX_ID_LIST_SCHEMA,
vol.Optional(_CONF_INDIVIDUAL, default=False): cv.boolean(True),
vol.Optional(_CONF_NAME, default=None): cv.string,
vol.Optional(CONF_NAME, default=None): cv.string,
})
# SCAN_INTERVAL = 30
@ -42,18 +42,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
zapi = hass.data[zabbix.DOMAIN]
if not zapi:
_LOGGER.error("zapi is None. Zabbix component hasn't been loaded?")
_LOGGER.error("zapi is None. Zabbix component hasn't been loaded?")
return False
_LOGGER.info("Connected to Zabbix API Version %s",
zapi.api_version())
_LOGGER.info("Connected to Zabbix API Version %s", zapi.api_version())
trigger_conf = config.get(_CONF_TRIGGERS)
# The following code seems overly complex. Need to think about this...
if trigger_conf:
hostids = trigger_conf.get(_CONF_HOSTIDS)
individual = trigger_conf.get(_CONF_INDIVIDUAL)
name = trigger_conf.get(_CONF_NAME)
name = trigger_conf.get(CONF_NAME)
if individual:
# Individual sensor per host
@ -63,10 +62,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
return False
for hostid in hostids:
_LOGGER.debug("Creating Zabbix Sensor: " + str(hostid))
sensor = ZabbixSingleHostTriggerCountSensor(zapi,
[hostid],
name)
_LOGGER.debug("Creating Zabbix Sensor: %s", str(hostid))
sensor = ZabbixSingleHostTriggerCountSensor(
zapi, [hostid], name)
sensors.append(sensor)
else:
if not hostids:
@ -75,10 +73,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
sensor = ZabbixTriggerCountSensor(zapi, name)
else:
# Single sensor that sums total issues for all hosts
_LOGGER.debug("Creating Zabbix Sensor group: " + str(hostids))
sensor = ZabbixMultipleHostTriggerCountSensor(zapi,
hostids,
name)
_LOGGER.debug("Creating Zabbix Sensor group: %s", str(hostids))
sensor = ZabbixMultipleHostTriggerCountSensor(
zapi, hostids, name)
sensors.append(sensor)
else:
# Single sensor that provides the total count of triggers.
@ -115,14 +112,12 @@ class ZabbixTriggerCountSensor(Entity):
return 'issues'
def _call_zabbix_api(self):
return self._zapi.trigger.get(output="extend",
only_true=1,
monitored=1,
filter={"value": 1})
return self._zapi.trigger.get(
output="extend", only_true=1, monitored=1, filter={"value": 1})
def update(self):
"""Update the sensor."""
_LOGGER.debug("Updating ZabbixTriggerCountSensor: " + str(self._name))
_LOGGER.debug("Updating ZabbixTriggerCountSensor: %s", str(self._name))
triggers = self._call_zabbix_api()
self._state = len(triggers)
@ -140,35 +135,31 @@ class ZabbixSingleHostTriggerCountSensor(ZabbixTriggerCountSensor):
super().__init__(zApi, name)
self._hostid = hostid
if not name:
self._name = self._zapi.host.get(hostids=self._hostid,
output="extend")[0]["name"]
self._name = self._zapi.host.get(
hostids=self._hostid, output="extend")[0]["name"]
self._attributes["Host ID"] = self._hostid
def _call_zabbix_api(self):
return self._zapi.trigger.get(hostids=self._hostid,
output="extend",
only_true=1,
monitored=1,
filter={"value": 1})
return self._zapi.trigger.get(
hostids=self._hostid, output="extend", only_true=1, monitored=1,
filter={"value": 1})
class ZabbixMultipleHostTriggerCountSensor(ZabbixTriggerCountSensor):
"""Get the active trigger count for specified Zabbix monitored hosts."""
def __init__(self, zApi, hostids, name=None):
"""Initiate Zabbix sensor."""
"""Initialize Zabbix sensor."""
super().__init__(zApi, name)
self._hostids = hostids
if not name:
host_names = self._zapi.host.get(hostids=self._hostids,
output="extend")
host_names = self._zapi.host.get(
hostids=self._hostids, output="extend")
self._name = " ".join(name["name"] for name in host_names)
self._attributes["Host IDs"] = self._hostids
def _call_zabbix_api(self):
return self._zapi.trigger.get(hostids=self._hostids,
output="extend",
only_true=1,
monitored=1,
filter={"value": 1})
return self._zapi.trigger.get(
hostids=self._hostids, output="extend", only_true=1,
monitored=1, filter={"value": 1})