Passed
Push — develop ( 325416...706c15 )
by Dean
02:50
created

on_database_changed()   A

Complexity

Conditions 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 1
CRAP Score 4.3145

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
ccs 1
cts 6
cp 0.1666
rs 9.4285
cc 2
crap 4.3145
1 1
from plugin.preferences.options.core.base import SimpleOption
2 1
from plugin.preferences.options.o_sync.constants import DUPLICATION_PERIOD_LABELS_BY_KEY, DUPLICATION_PERIOD_IDS_BY_KEY, \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (122/120).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
3
    DUPLICATION_PERIOD_KEYS_BY_LABEL
4 1
from plugin.sync.core.enums import ScrobbleDuplicationPeriod
5
6 1
import logging
7
8
9 1
log = logging.getLogger(__name__)
10
11
12 1 View Code Duplication
class ScrobbleDuplicationPeriodOption(SimpleOption):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
13 1
    key = 'scrobble.duplication_period'
14 1
    type = 'enum'
15
16 1
    choices = DUPLICATION_PERIOD_LABELS_BY_KEY
17 1
    default = ScrobbleDuplicationPeriod.H6
18 1
    scope = 'server'
19
20 1
    group = ('Advanced', 'Scrobble')
21 1
    label = 'Ignore duplicates for'
22 1
    order = 115
23
24 1
    preference = 'scrobble_duplication_period'
25
26 1
    def on_database_changed(self, value, account=None):
27
        if value not in DUPLICATION_PERIOD_IDS_BY_KEY:
28
            log.warn('Unknown value: %r', value)
29
            return
30
31
        # Map `value` to plex preference
32
        value = DUPLICATION_PERIOD_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 DUPLICATION_PERIOD_KEYS_BY_LABEL:
39
            log.warn('Unknown value: %r', value)
40
            return
41
42
        # Map plex `value`
43
        value = DUPLICATION_PERIOD_KEYS_BY_LABEL[value]
44
45
        # Update database
46
        self.update(value, account, emit=False)
47
        return value
48