Skip to content

Commit 9cf9480

Browse files
authored
v0.9.0 Merge pull request #11 from mudpi/feature
v0.9.0
2 parents d336134 + 4978177 commit 9cf9480

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1277
-1004
lines changed

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ These are the devices and sensors I tested and used with MudPi successfully. Man
5353
Let me know if you are able to confirm tests on any other devices
5454

5555
## License
56-
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
56+
This project is licensed under the BSD-4-Clause License - see the [LICENSE.md](LICENSE.md) file for details
5757

5858

5959
<img alt="MudPi Smart Garden" title="MudPi Smart Garden" src="https://mudpi.app/img/mudPI_LOGO_small_flat.png" width="50px">

action.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import subprocess
55
import sys
66
sys.path.append('..')
7-
import variables
87

98
class Action():
109

@@ -15,6 +14,10 @@ def __init__(self, config):
1514
self.key = config.get("key", None).replace(" ", "_").lower() if config.get("key") is not None else self.name.replace(" ", "_").lower()
1615
# Actions will be either objects to publish for events or a command string to execute
1716
self.action = config.get("action")
17+
try:
18+
self.r = config["redis"] if config["redis"] is not None else redis.Redis(host='127.0.0.1', port=6379)
19+
except KeyError:
20+
self.r = redis.Redis(host='127.0.0.1', port=6379)
1821
return
1922

2023
def init_action(self):
@@ -31,7 +34,7 @@ def trigger(self, value=None):
3134
return
3235

3336
def emitEvent(self):
34-
variables.r.publish(self.topic, json.dumps(self.action))
37+
self.r.publish(self.topic, json.dumps(self.action))
3538
return
3639

3740
def runCommand(self, value=None):

controls/arduino/button_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class ButtonControl(Control):
1212

13-
def __init__(self, pin, name='ButtonControl', key=None, connection=default_connection, analog_pin_mode=False, topic=None):
14-
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode)
13+
def __init__(self, pin, name='ButtonControl', key=None, connection=default_connection, analog_pin_mode=False, topic=None, redis_conn=None):
14+
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode, redis_conn=redis_conn)
1515
self.topic = topic.replace(" ", "/").lower() if topic is not None else 'mudpi/relay/'
1616
self.state_counter = 3
1717
self.previous_state = 0

controls/arduino/control.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
from nanpy import (ArduinoApi, SerialManager)
55
import sys
66
sys.path.append('..')
7-
import variables
87

98
default_connection = SerialManager()
109

1110
# Base sensor class to extend all other arduino sensors from.
1211
class Control():
1312

14-
def __init__(self, pin, name='Control', connection=default_connection, analog_pin_mode=False, key=None):
13+
def __init__(self, pin, name='Control', connection=default_connection, analog_pin_mode=False, key=None, redis_conn=None):
1514
self.pin = pin
1615
self.name = name
1716
self.key = key.replace(" ", "_").lower() if key is not None else self.name.replace(" ", "_").lower()
1817
self.analog_pin_mode = analog_pin_mode
1918
self.connection = connection
2019
self.api = ArduinoApi(connection)
20+
try:
21+
self.r = redis_conn if redis_conn is not None else redis.Redis(host='127.0.0.1', port=6379)
22+
except KeyError:
23+
self.r = redis.Redis(host='127.0.0.1', port=6379)
2124
return
2225

2326
def init_control(self):
@@ -46,4 +49,4 @@ def emitEvent(self, data):
4649
}
4750
}
4851
print(message["data"])
49-
variables.r.publish('controls', json.dumps(message))
52+
self.r.publish('controls', json.dumps(message))

controls/arduino/potentiometer_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class PotentiometerControl(Control):
1212

13-
def __init__(self, pin, name='PotentiometerControl', key=None, connection=default_connection, analog_pin_mode=True, topic=None, reading_buffer=3):
14-
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode)
13+
def __init__(self, pin, name='PotentiometerControl', key=None, connection=default_connection, analog_pin_mode=True, topic=None, reading_buffer=3, redis_conn=None):
14+
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode, redis_conn=redis_conn)
1515
self.previous_state = 0
1616
# Reading buffer helps prevent multiple events when values are floating between small amounts
1717
self.reading_buffer = reading_buffer

controls/arduino/switch_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class SwitchControl(Control):
1212

13-
def __init__(self, pin, name='SwitchControl', key=None, connection=default_connection, analog_pin_mode=False, topic=None):
14-
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode)
13+
def __init__(self, pin, name='SwitchControl', key=None, connection=default_connection, analog_pin_mode=False, topic=None, redis_conn=None):
14+
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode, redis_conn=redis_conn)
1515
self.topic = topic.replace(" ", "/").lower() if topic is not None else 'mudpi/relay/'
1616
self.state_counter = 3
1717
self.previous_state = 0

controls/pi/button_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
class ButtonControl(Control):
1111

12-
def __init__(self, pin, name='ButtonControl', key=None, resistor=None, edge_detection=None, debounce=None, topic=None):
13-
super().__init__(pin, name=name, key=key, resistor=resistor, edge_detection=edge_detection, debounce=debounce)
12+
def __init__(self, pin, name='ButtonControl', key=None, resistor=None, edge_detection=None, debounce=None, topic=None, redis_conn=None):
13+
super().__init__(pin, name=name, key=key, resistor=resistor, edge_detection=edge_detection, debounce=debounce, redis_conn=redis_conn)
1414
self.topic = topic.replace(" ", "/").lower() if topic is not None else 'mudpi/relay/'
1515
return
1616

controls/pi/control.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
import RPi.GPIO as GPIO
55
import sys
66
sys.path.append('..')
7-
import variables
87

98
# Base sensor class to extend all other arduino sensors from.
109
class Control():
1110

12-
def __init__(self, pin, name='Control',key=None, resistor=None, edge_detection=None, debounce=None):
11+
def __init__(self, pin, name='Control',key=None, resistor=None, edge_detection=None, debounce=None, redis_conn=None):
1312
self.pin = pin
1413
self.name = name
1514
self.key = key.replace(" ", "_").lower() if key is not None else self.name.replace(" ", "_").lower()
1615
self.gpio = GPIO
1716
self.debounce = debounce if debounce is not None else None
17+
try:
18+
self.r = redis_conn if redis_conn is not None else redis.Redis(host='127.0.0.1', port=6379)
19+
except KeyError:
20+
self.r = redis.Redis(host='127.0.0.1', port=6379)
1821

1922
if resistor is not None:
2023
if resistor == "up" or resistor == GPIO.PUD_UP:
@@ -67,4 +70,4 @@ def emitEvent(self, data):
6770
}
6871
}
6972
print(message["data"])
70-
variables.r.publish('controls', json.dumps(message))
73+
self.r.publish('controls', json.dumps(message))

controls/pi/switch_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
class SwitchControl(Control):
1111

12-
def __init__(self, pin, name='SwitchControl', key=None, resistor=None, edge_detection=None, debounce=None, topic=None):
13-
super().__init__(pin, name=name, key=key, resistor=resistor, edge_detection=edge_detection, debounce=debounce)
12+
def __init__(self, pin, name='SwitchControl', key=None, resistor=None, edge_detection=None, debounce=None, topic=None, redis_conn=None):
13+
super().__init__(pin, name=name, key=key, resistor=resistor, edge_detection=edge_detection, debounce=debounce, redis_conn=redis_conn)
1414
self.topic = topic.replace(" ", "/").lower() if topic is not None else 'mudpi/relay/'
1515
# Keep counter 1 above delay to avoid event on boot
1616
self.state_counter = 3

0 commit comments

Comments
 (0)