mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Tidied up the documentations and linting warnings
This commit is contained in:
parent
ba13f78d49
commit
e63d0d7aac
@ -1,39 +1,49 @@
|
|||||||
"""
|
"""
|
||||||
homeassistant.components.sensor.sabnzbd
|
homeassistant.components.sensor.transmission
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Monitors SABnzbd NZB client API
|
Monitors Transmission BitTorrent client API
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
|
|
||||||
To use the SABnzbd sensor you will need to add something like the following to
|
To use the Transmission sensor you will need to add something like the
|
||||||
your config/configuration.yaml
|
following to your config/configuration.yaml
|
||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
platform: sabnzbd
|
platform: transmission
|
||||||
name: SAB
|
name: Transmission
|
||||||
api_key: YOUR_API_KEY
|
host: 192.168.1.26
|
||||||
base_url: YOUR_SABNZBD_BASE_URL
|
port: 9091
|
||||||
|
username: YOUR_USERNAME
|
||||||
|
password: YOUR_PASSWORD
|
||||||
monitored_variables:
|
monitored_variables:
|
||||||
- type: 'current_status'
|
- type: 'current_status'
|
||||||
- type: 'speed'
|
- type: 'download_speed'
|
||||||
- type: 'queue_size'
|
- type: 'upload_speed'
|
||||||
- type: 'queue_remaining'
|
|
||||||
- type: 'disk_size'
|
|
||||||
- type: 'disk_free'
|
|
||||||
|
|
||||||
VARIABLES:
|
VARIABLES:
|
||||||
|
|
||||||
base_url
|
host
|
||||||
*Required
|
*Required
|
||||||
This is the base URL of your SABnzbd instance including the port number if not
|
This is the IP address of your Transmission Daemon
|
||||||
running on 80
|
Example: 192.168.1.32
|
||||||
Example: http://192.168.1.32:8124/
|
|
||||||
|
|
||||||
|
port
|
||||||
|
*Optional
|
||||||
|
The port your Transmission daemon uses, defaults to 9091
|
||||||
|
Example: 8080
|
||||||
|
|
||||||
|
username
|
||||||
|
*Required
|
||||||
|
Your Transmission username
|
||||||
|
|
||||||
|
password
|
||||||
|
*Required
|
||||||
|
Your Transmission password
|
||||||
|
|
||||||
name
|
name
|
||||||
*Optional
|
*Optional
|
||||||
The name to use when displaying this SABnzbd instance
|
The name to use when displaying this Transmission instance
|
||||||
|
|
||||||
monitored_variables
|
monitored_variables
|
||||||
*Required
|
*Required
|
||||||
@ -64,11 +74,7 @@ import logging
|
|||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
'current_status': ['Status', ''],
|
'current_status': ['Status', ''],
|
||||||
'download_speed': ['Down Speed', 'MB/s'],
|
'download_speed': ['Down Speed', 'MB/s'],
|
||||||
'upload_speed': ['Up Speed', 'MB/s'],
|
'upload_speed': ['Up Speed', 'MB/s']
|
||||||
'queue_size': ['Queue', 'MB'],
|
|
||||||
'queue_remaining': ['Left', 'MB'],
|
|
||||||
'disk_size': ['Disk', 'GB'],
|
|
||||||
'disk_free': ['Disk Free', 'GB'],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -82,7 +88,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
username = config.get(CONF_USERNAME, None)
|
username = config.get(CONF_USERNAME, None)
|
||||||
password = config.get(CONF_PASSWORD, None)
|
password = config.get(CONF_PASSWORD, None)
|
||||||
port = config.get('port')
|
port = config.get('port', 9091)
|
||||||
|
|
||||||
name = config.get("name", "Transmission")
|
name = config.get("name", "Transmission")
|
||||||
if not host:
|
if not host:
|
||||||
@ -92,24 +98,26 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
# import logging
|
# import logging
|
||||||
# logging.getLogger('transmissionrpc').setLevel(logging.DEBUG)
|
# logging.getLogger('transmissionrpc').setLevel(logging.DEBUG)
|
||||||
|
|
||||||
transmission_api = transmissionrpc.Client(host, port=port, user=username, password=password)
|
transmission_api = transmissionrpc.Client(
|
||||||
|
host, port=port, user=username, password=password)
|
||||||
try:
|
try:
|
||||||
session = transmission_api.session_stats()
|
transmission_api.session_stats()
|
||||||
print(transmission_api.session)
|
|
||||||
except TransmissionError:
|
except TransmissionError:
|
||||||
_LOGGER.exception("Connection to Transmission API failed.")
|
_LOGGER.exception("Connection to Transmission API failed.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# pylint: disable=global-statement
|
# pylint: disable=global-statement
|
||||||
global _THROTTLED_REFRESH
|
global _THROTTLED_REFRESH
|
||||||
_THROTTLED_REFRESH = Throttle(timedelta(seconds=1))(transmission_api.session_stats)
|
_THROTTLED_REFRESH = Throttle(timedelta(seconds=1))(
|
||||||
|
transmission_api.session_stats)
|
||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
for variable in config['monitored_variables']:
|
for variable in config['monitored_variables']:
|
||||||
if variable['type'] not in SENSOR_TYPES:
|
if variable['type'] not in SENSOR_TYPES:
|
||||||
_LOGGER.error('Sensor type: "%s" does not exist', variable['type'])
|
_LOGGER.error('Sensor type: "%s" does not exist', variable['type'])
|
||||||
else:
|
else:
|
||||||
dev.append(TransmissionSensor(variable['type'], transmission_api, name))
|
dev.append(TransmissionSensor(
|
||||||
|
variable['type'], transmission_api, name))
|
||||||
|
|
||||||
add_devices(dev)
|
add_devices(dev)
|
||||||
|
|
||||||
@ -169,8 +177,10 @@ class TransmissionSensor(Entity):
|
|||||||
|
|
||||||
if self.transmission_client.session:
|
if self.transmission_client.session:
|
||||||
if self.type == 'download_speed':
|
if self.type == 'download_speed':
|
||||||
mb_spd = float(self.transmission_client.session.downloadSpeed) / 1024 / 1024
|
mb_spd = float(self.transmission_client.session.downloadSpeed)
|
||||||
|
mb_spd = mb_spd / 1024 / 1024
|
||||||
self._state = round(mb_spd, 2 if mb_spd < 0.1 else 1)
|
self._state = round(mb_spd, 2 if mb_spd < 0.1 else 1)
|
||||||
elif self.type == 'upload_speed':
|
elif self.type == 'upload_speed':
|
||||||
mb_spd = float(self.transmission_client.session.uploadSpeed) / 1024 / 1024
|
mb_spd = float(self.transmission_client.session.uploadSpeed)
|
||||||
|
mb_spd = mb_spd / 1024 / 1024
|
||||||
self._state = round(mb_spd, 2 if mb_spd < 0.1 else 1)
|
self._state = round(mb_spd, 2 if mb_spd < 0.1 else 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user