Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
44ddc6ba
Commit
44ddc6ba
authored
6 years ago
by
engrbm87
Committed by
Fabian Affolter
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
deluge-components-update (#14016)
parent
07f94eaa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
homeassistant/components/sensor/deluge.py
+20
-7
20 additions, 7 deletions
homeassistant/components/sensor/deluge.py
homeassistant/components/switch/deluge.py
+24
-8
24 additions, 8 deletions
homeassistant/components/switch/deluge.py
requirements_all.txt
+1
-1
1 addition, 1 deletion
requirements_all.txt
with
45 additions
and
16 deletions
homeassistant/components/sensor/deluge.py
+
20
−
7
View file @
44ddc6ba
...
...
@@ -14,8 +14,9 @@ from homeassistant.const import (
CONF_HOST
,
CONF_PASSWORD
,
CONF_USERNAME
,
CONF_NAME
,
CONF_PORT
,
CONF_MONITORED_VARIABLES
,
STATE_IDLE
)
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__
)
_THROTTLED_REFRESH
=
None
...
...
@@ -24,7 +25,6 @@ DEFAULT_NAME = 'Deluge'
DEFAULT_PORT
=
58846
DHT_UPLOAD
=
1000
DHT_DOWNLOAD
=
1000
SENSOR_TYPES
=
{
'
current_status
'
:
[
'
Status
'
,
None
],
'
download_speed
'
:
[
'
Down Speed
'
,
'
kB/s
'
],
...
...
@@ -58,8 +58,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
deluge_api
.
connect
()
except
ConnectionRefusedError
:
_LOGGER
.
error
(
"
Connection to Deluge Daemon failed
"
)
return
raise
PlatformNotReady
dev
=
[]
for
variable
in
config
[
CONF_MONITORED_VARIABLES
]:
dev
.
append
(
DelugeSensor
(
variable
,
deluge_api
,
name
))
...
...
@@ -79,6 +78,7 @@ class DelugeSensor(Entity):
self
.
_state
=
None
self
.
_unit_of_measurement
=
SENSOR_TYPES
[
sensor_type
][
1
]
self
.
data
=
None
self
.
_available
=
False
@property
def
name
(
self
):
...
...
@@ -90,6 +90,11 @@ class DelugeSensor(Entity):
"""
Return the state of the sensor.
"""
return
self
.
_state
@property
def
available
(
self
):
"""
Return true if device is available.
"""
return
self
.
_available
@property
def
unit_of_measurement
(
self
):
"""
Return the unit of measurement of this entity, if any.
"""
...
...
@@ -97,9 +102,17 @@ class DelugeSensor(Entity):
def
update
(
self
):
"""
Get the latest data from Deluge and updates the state.
"""
self
.
data
=
self
.
client
.
call
(
'
core.get_session_status
'
,
[
'
upload_rate
'
,
'
download_rate
'
,
'
dht_upload_rate
'
,
'
dht_download_rate
'
])
from
deluge_client
import
FailedToReconnectException
try
:
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
'
]
download
=
self
.
data
[
b
'
download_rate
'
]
-
self
.
data
[
...
...
This diff is collapsed.
Click to expand it.
homeassistant/components/switch/deluge.py
+
24
−
8
View file @
44ddc6ba
...
...
@@ -9,15 +9,16 @@ import logging
import
voluptuous
as
vol
from
homeassistant.components.switch
import
PLATFORM_SCHEMA
from
homeassistant.exceptions
import
PlatformNotReady
from
homeassistant.const
import
(
CONF_HOST
,
CONF_NAME
,
CONF_PORT
,
CONF_PASSWORD
,
CONF_USERNAME
,
STATE_OFF
,
STATE_ON
)
from
homeassistant.helpers.entity
import
ToggleEntity
import
homeassistant.helpers.config_validation
as
cv
REQUIREMENTS
=
[
'
deluge-client==1.
0.5
'
]
REQUIREMENTS
=
[
'
deluge-client==1.
4.0
'
]
_LOGG
ING
=
logging
.
getLogger
(
__name__
)
_LOGG
ER
=
logging
.
getLogger
(
__name__
)
DEFAULT_NAME
=
'
Deluge Switch
'
DEFAULT_PORT
=
58846
...
...
@@ -46,8 +47,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
try
:
deluge_api
.
connect
()
except
ConnectionRefusedError
:
_LOGG
ING
.
error
(
"
Connection to Deluge Daemon failed
"
)
r
eturn
_LOGG
ER
.
error
(
"
Connection to Deluge Daemon failed
"
)
r
aise
PlatformNotReady
add_devices
([
DelugeSwitch
(
deluge_api
,
name
)])
...
...
@@ -60,6 +61,7 @@ class DelugeSwitch(ToggleEntity):
self
.
_name
=
name
self
.
deluge_client
=
deluge_client
self
.
_state
=
STATE_OFF
self
.
_available
=
False
@property
def
name
(
self
):
...
...
@@ -76,18 +78,32 @@ class DelugeSwitch(ToggleEntity):
"""
Return true if device is on.
"""
return
self
.
_state
==
STATE_ON
@property
def
available
(
self
):
"""
Return true if device is available.
"""
return
self
.
_available
def
turn_on
(
self
,
**
kwargs
):
"""
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
):
"""
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
):
"""
Get the latest data from deluge and updates the state.
"""
torrent_list
=
self
.
deluge_client
.
call
(
'
core.get_torrents_status
'
,
{},
[
'
paused
'
])
from
deluge_client
import
FailedToReconnectException
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
():
item
=
torrent
.
popitem
()
if
not
item
[
1
]:
...
...
This diff is collapsed.
Click to expand it.
requirements_all.txt
+
1
−
1
View file @
44ddc6ba
...
...
@@ -243,7 +243,7 @@ defusedxml==0.5.0
# homeassistant.components.sensor.deluge
# homeassistant.components.switch.deluge
deluge-client==1.
0.5
deluge-client==1.
4.0
# homeassistant.components.media_player.denonavr
denonavr==0.6.1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment