Passed
Push — master ( d9ae97...694e2f )
by Dean
09:21 queued 06:02
created

SyncIdleDelayOption.on_plex_changed()   A

Complexity

Conditions 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 1
CRAP Score 4.5185

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
ccs 1
cts 7
cp 0.1429
rs 9.4285
cc 2
crap 4.5185
1 1
from plugin.preferences.options.core.base import SimpleOption
2 1
from plugin.preferences.options.o_sync.constants import IDLE_DELAY_LABELS_BY_KEY, IDLE_DELAY_IDS_BY_KEY, \
3
    IDLE_DELAY_KEYS_BY_LABEL
4 1
from plugin.sync.core.enums import SyncIdleDelay
5
6 1
import logging
7
8
9 1
log = logging.getLogger(__name__)
10
11
12 1 View Code Duplication
class SyncIdleDelayOption(SimpleOption):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
13 1
    key = 'sync.idle_delay'
14 1
    type = 'enum'
15
16 1
    choices = IDLE_DELAY_LABELS_BY_KEY
17 1
    default = SyncIdleDelay.M30
18 1
    scope = 'server'
19
20 1
    group = ('Advanced', 'Sync - Triggers')
21 1
    label = 'Idle delay'
22 1
    order = 131
23
24 1
    preference = 'sync_idle_delay'
25
26 1
    def on_database_changed(self, value, account=None):
27
        if value not in IDLE_DELAY_IDS_BY_KEY:
28
            log.warn('Unknown value: %r', value)
29
            return
30
31
        # Map `value` to plex preference
32
        value = IDLE_DELAY_IDS_BY_KEY[value]
33
34
        # Update preference
35
        return self._update_preference(value, account)
36
37 1
    def on_plex_changed(self, value, account=None):
38
        if value not in IDLE_DELAY_KEYS_BY_LABEL:
39
            log.warn('Unknown value: %r', value)
40
            return
41
42
        # Map plex `value`
43
        value = IDLE_DELAY_KEYS_BY_LABEL[value]
44
45
        # Update database
46
        self.update(value, account, emit=False)
47
        return value
48