Conditions | 14 |
Total Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Complex classes like doorpi.status.status_lib.get() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | #!/usr/bin/env python |
||
10 | def get(*args, **kwargs): |
||
11 | try: |
||
12 | if len(kwargs['name']) == 0: kwargs['name'] = [''] |
||
13 | if len(kwargs['value']) == 0: kwargs['value'] = [''] |
||
14 | |||
15 | keyboard = kwargs['DoorPiObject'].keyboard |
||
16 | |||
17 | status = {} |
||
18 | |||
19 | for name_requested in kwargs['name']: |
||
20 | if name_requested in 'name': |
||
21 | status['name'] = keyboard.name |
||
22 | |||
23 | if name_requested in 'input': |
||
24 | status['input'] = {} |
||
25 | for value_requested in kwargs['value']: |
||
26 | for input_pin in keyboard.input_pins: |
||
27 | if value_requested in input_pin: |
||
28 | status['input'][input_pin] = keyboard.status_input(input_pin) |
||
29 | |||
30 | if name_requested in 'output': |
||
31 | status['output'] = keyboard.output_status |
||
32 | for value_requested in kwargs['value']: |
||
33 | for output_pin in status['output'].keys(): |
||
34 | if value_requested not in output_pin: |
||
35 | del status['output'][output_pin] |
||
36 | return status |
||
37 | |||
38 | except Exception as exp: |
||
39 | logger.exception(exp) |
||
40 | return {'Error': 'could not create keyboard object - '+str(exp)} |
||
41 | |||
47 |