mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
deluge-components-update (#14016)
This commit is contained in:
parent
07f94eaa92
commit
44ddc6ba62
@ -14,8 +14,9 @@ from homeassistant.const import (
|
|||||||
CONF_HOST, CONF_PASSWORD, CONF_USERNAME, CONF_NAME, CONF_PORT,
|
CONF_HOST, CONF_PASSWORD, CONF_USERNAME, CONF_NAME, CONF_PORT,
|
||||||
CONF_MONITORED_VARIABLES, STATE_IDLE)
|
CONF_MONITORED_VARIABLES, STATE_IDLE)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
|
|
||||||
REQUIREMENTS = ['deluge-client==1.0.5']
|
REQUIREMENTS = ['deluge-client==1.4.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
_THROTTLED_REFRESH = None
|
_THROTTLED_REFRESH = None
|
||||||
@ -24,7 +25,6 @@ DEFAULT_NAME = 'Deluge'
|
|||||||
DEFAULT_PORT = 58846
|
DEFAULT_PORT = 58846
|
||||||
DHT_UPLOAD = 1000
|
DHT_UPLOAD = 1000
|
||||||
DHT_DOWNLOAD = 1000
|
DHT_DOWNLOAD = 1000
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
'current_status': ['Status', None],
|
'current_status': ['Status', None],
|
||||||
'download_speed': ['Down Speed', 'kB/s'],
|
'download_speed': ['Down Speed', 'kB/s'],
|
||||||
@ -58,8 +58,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
deluge_api.connect()
|
deluge_api.connect()
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
_LOGGER.error("Connection to Deluge Daemon failed")
|
_LOGGER.error("Connection to Deluge Daemon failed")
|
||||||
return
|
raise PlatformNotReady
|
||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
for variable in config[CONF_MONITORED_VARIABLES]:
|
for variable in config[CONF_MONITORED_VARIABLES]:
|
||||||
dev.append(DelugeSensor(variable, deluge_api, name))
|
dev.append(DelugeSensor(variable, deluge_api, name))
|
||||||
@ -79,6 +78,7 @@ class DelugeSensor(Entity):
|
|||||||
self._state = None
|
self._state = None
|
||||||
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
||||||
self.data = None
|
self.data = None
|
||||||
|
self._available = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -90,6 +90,11 @@ class DelugeSensor(Entity):
|
|||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return true if device is available."""
|
||||||
|
return self._available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
@ -97,9 +102,17 @@ class DelugeSensor(Entity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from Deluge and updates the state."""
|
"""Get the latest data from Deluge and updates the state."""
|
||||||
self.data = self.client.call('core.get_session_status',
|
from deluge_client import FailedToReconnectException
|
||||||
['upload_rate', 'download_rate',
|
try:
|
||||||
'dht_upload_rate', 'dht_download_rate'])
|
self.data = self.client.call('core.get_session_status',
|
||||||
|
['upload_rate', 'download_rate',
|
||||||
|
'dht_upload_rate',
|
||||||
|
'dht_download_rate'])
|
||||||
|
self._available = True
|
||||||
|
except FailedToReconnectException:
|
||||||
|
_LOGGER.error("Connection to Deluge Daemon Lost")
|
||||||
|
self._available = False
|
||||||
|
return
|
||||||
|
|
||||||
upload = self.data[b'upload_rate'] - self.data[b'dht_upload_rate']
|
upload = self.data[b'upload_rate'] - self.data[b'dht_upload_rate']
|
||||||
download = self.data[b'download_rate'] - self.data[
|
download = self.data[b'download_rate'] - self.data[
|
||||||
|
@ -9,15 +9,16 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.switch import PLATFORM_SCHEMA
|
from homeassistant.components.switch import PLATFORM_SCHEMA
|
||||||
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST, CONF_NAME, CONF_PORT, CONF_PASSWORD, CONF_USERNAME, STATE_OFF,
|
CONF_HOST, CONF_NAME, CONF_PORT, CONF_PASSWORD, CONF_USERNAME, STATE_OFF,
|
||||||
STATE_ON)
|
STATE_ON)
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['deluge-client==1.0.5']
|
REQUIREMENTS = ['deluge-client==1.4.0']
|
||||||
|
|
||||||
_LOGGING = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_NAME = 'Deluge Switch'
|
DEFAULT_NAME = 'Deluge Switch'
|
||||||
DEFAULT_PORT = 58846
|
DEFAULT_PORT = 58846
|
||||||
@ -46,8 +47,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
try:
|
try:
|
||||||
deluge_api.connect()
|
deluge_api.connect()
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
_LOGGING.error("Connection to Deluge Daemon failed")
|
_LOGGER.error("Connection to Deluge Daemon failed")
|
||||||
return
|
raise PlatformNotReady
|
||||||
|
|
||||||
add_devices([DelugeSwitch(deluge_api, name)])
|
add_devices([DelugeSwitch(deluge_api, name)])
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ class DelugeSwitch(ToggleEntity):
|
|||||||
self._name = name
|
self._name = name
|
||||||
self.deluge_client = deluge_client
|
self.deluge_client = deluge_client
|
||||||
self._state = STATE_OFF
|
self._state = STATE_OFF
|
||||||
|
self._available = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -76,18 +78,32 @@ class DelugeSwitch(ToggleEntity):
|
|||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return self._state == STATE_ON
|
return self._state == STATE_ON
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return true if device is available."""
|
||||||
|
return self._available
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
self.deluge_client.call('core.resume_all_torrents')
|
torrent_ids = self.deluge_client.call('core.get_session_state')
|
||||||
|
self.deluge_client.call('core.resume_torrent', torrent_ids)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn the device off."""
|
"""Turn the device off."""
|
||||||
self.deluge_client.call('core.pause_all_torrents')
|
torrent_ids = self.deluge_client.call('core.get_session_state')
|
||||||
|
self.deluge_client.call('core.pause_torrent', torrent_ids)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from deluge and updates the state."""
|
"""Get the latest data from deluge and updates the state."""
|
||||||
torrent_list = self.deluge_client.call('core.get_torrents_status', {},
|
from deluge_client import FailedToReconnectException
|
||||||
['paused'])
|
try:
|
||||||
|
torrent_list = self.deluge_client.call('core.get_torrents_status',
|
||||||
|
{}, ['paused'])
|
||||||
|
self._available = True
|
||||||
|
except FailedToReconnectException:
|
||||||
|
_LOGGER.error("Connection to Deluge Daemon Lost")
|
||||||
|
self._available = False
|
||||||
|
return
|
||||||
for torrent in torrent_list.values():
|
for torrent in torrent_list.values():
|
||||||
item = torrent.popitem()
|
item = torrent.popitem()
|
||||||
if not item[1]:
|
if not item[1]:
|
||||||
|
@ -243,7 +243,7 @@ defusedxml==0.5.0
|
|||||||
|
|
||||||
# homeassistant.components.sensor.deluge
|
# homeassistant.components.sensor.deluge
|
||||||
# homeassistant.components.switch.deluge
|
# homeassistant.components.switch.deluge
|
||||||
deluge-client==1.0.5
|
deluge-client==1.4.0
|
||||||
|
|
||||||
# homeassistant.components.media_player.denonavr
|
# homeassistant.components.media_player.denonavr
|
||||||
denonavr==0.6.1
|
denonavr==0.6.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user