Python Beginner alert and long post warning :-o
I’m more or less a beginner with Python but I can follow the code and have used other programming languages.
I’ve managed to get mini-kit.py working by copying it into my “~/flotilla-offline/flotilla-python/library/flotilla/” folder along with all the other .py files, and running it from there.
Having had success with that I decided to try and get the “Light” module working. Using mini-kit.py as the basis for my new python light module.
I could see that first I probably needed to make some changes to __init__.py and light.py., as follows:
Extract from __init__.py
.
.
from .rainbow import Rainbow
from .light import Light ←ADDED BY ME
VID = “16d0”
PID = “08c3”
LANG_REQUIRES = “Oh no! I need a {module_type} on channel {channel}”
LANG_FOUND = “Yay! I’ve found a {module_type} on channel {channel}”
LANG_READY = “Everything connected properly. Let’s go!”
class Client:
_module_handlers = {
‘dial’: Dial,
‘slider’: Slider,
‘motion’: Motion,
‘matrix’: Matrix,
‘number’: Number,
‘touch’: Touch,
‘light’: Light, ←UNCOMMENTED BY ME
# ‘colour’: Colour,
‘joystick’: Joystick,
‘motor’: Motor,
# ‘weather’: Weather,
‘rainbow’: Rainbow
.
.
My light.py file ( This was based on the touch.py file)
from .module import Module
class Light(Module):
name = ‘light’
@property
def light(self):
if len(self.data) >= 0:
return int(self.data[0])
return 0
This is my “mini-kit_light.py” program:
1 print(“”"
2 This example requires the Light module,
3 you’ll find it in the mini kit.
4 Press Ctrl+C to exit.
5 “”")
6
7 import flotilla
8 import time
9
10 client = flotilla.Client(
11 requires={
12 ‘one’: flotilla.Light
13 })
14
15 def module_changed(channel, module):
16 light = client.first(flotilla.light)
17
18 while not client.ready:
19 pass
20
21 light = client.first(flotilla.Light)
22
23 try:
24 print(“OK”)
25 time.sleep(0.1)
26 except KeyboardInterrupt:
27 client.stop()
Before I started to write the code to display the output of the Light module I used the above for testing, just to see if it would get to line 24 .However, when I run it I get this error:
Traceback (most recent call last):
File “mini-kit_light.py”, line 12, in<module>
‘one’: flotilla.Light
AttributeError: ‘module’ object has no attribute ‘Light’
I’ve tried various things but cannot overcome this error. I’m thinking that the problem might be line 7 ? I don’t know what this import is for or what it contains.
If anyone could spare some time to point me in the right direction I would really appreciate it.
TIA Steve