Passed
Push — master ( 0976a9...d25d71 )
by Matt
01:29
created

PyDMXControl.profiles.Pulse._Compact_LED_PAR   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 22.06 %

Importance

Changes 0
Metric Value
wmc 5
eloc 39
dl 15
loc 68
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Compact_LED_PAR_8Ch.__init__() 0 20 1
A Compact_LED_PAR_4Ch.__init__() 15 15 1
A Compact_LED_PAR.__init__() 0 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
"""
2
 *  PyDMXControl: A Python 3 module to control DMX using uDMX.
3
 *                Featuring fixture profiles, built-in effects and a web control panel.
4
 *  <https://github.com/MattIPv4/PyDMXControl/>
5
 *  Copyright (C) 2020 Matt Cowley (MattIPv4) ([email protected])
6
"""
7
8
from ..defaults import Fixture, Vdim
9
10
11
class Compact_LED_PAR_4Ch(Vdim):
12
13 View Code Duplication
    def __init__(self, *args, **kwargs):
14
        """
15
        These models can be configured to use 4 or 8 DMX channels. Use this
16
        class for the 4 channel configuration.
17
        """
18
        super().__init__(*args, **kwargs)
19
20
        self._register_channel('red', vdim=True)
21
        self._register_channel_aliases('red', 'r')
22
        self._register_channel('green', vdim=True)
23
        self._register_channel_aliases('green', 'g')
24
        self._register_channel('blue', vdim=True)
25
        self._register_channel_aliases('blue', 'b')
26
        self._register_channel('white', vdim=True)
27
        self._register_channel_aliases('white', 'w')
28
29
30
class Compact_LED_PAR_8Ch(Fixture):
31
32
    def __init__(self, *args, **kwargs):
33
        """
34
        These models can be configured to use 4 or 8 DMX channels. Use this
35
        class for the 8 channel configuration.
36
        """
37
        super().__init__(*args, **kwargs)
38
39
        self._register_channel('dimmer')
40
        self._register_channel_aliases('dimmer', 'dim', 'd')
41
        self._register_channel('red')
42
        self._register_channel_aliases('red', 'r')
43
        self._register_channel('green')
44
        self._register_channel_aliases('green', 'g')
45
        self._register_channel('blue')
46
        self._register_channel_aliases('blue', 'b')
47
        self._register_channel('white')
48
        self._register_channel_aliases('white', 'w')
49
        self._register_channel('strobe')
50
        self._register_channel('function')
51
        self._register_channel('speed')
52
53
54
class Compact_LED_PAR(Fixture):
55
56
    def __init__(self, mode: int, *args, **kwargs):
57
        super().__init__(*args, **kwargs)
58
59
        if mode == 4:
60
            new = Compact_LED_PAR_4Ch(*args, **kwargs)
61
        elif mode == 8:
62
            new = Compact_LED_PAR_8Ch(*args, **kwargs)
63
        else:
64
            raise ValueError('Number of channels (mode) has to be 4 or 8. You passed '
65
                             '{}.'.format(mode))
66
67
        self.__dict__ = new.__dict__
68