Skip to content

Commit

Permalink
Merge pull request #7 from mudpi/feature
Browse files Browse the repository at this point in the history
Get upstream code
  • Loading branch information
yeyeto2788 committed Mar 18, 2021
2 parents f63f732 + 7e8d34f commit 810f31d
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 30 deletions.
1 change: 1 addition & 0 deletions mudpi/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
CLASSIFIER_FLOWMETER = "flowmeter"
CLASSIFIER_HUMIDITY = "humidity"
CLASSIFIER_ILLUMINANCE = "illuminance"
CLASSIFIER_LIQUID_LEVEL = "liquid_level"
CLASSIFIER_SIGNAL_STRENGTH = "signal_strength"
CLASSIFIER_TEMPERATURE = "temperature"
CLASSIFIER_TIMESTAMP = "timestamp"
Expand Down
2 changes: 1 addition & 1 deletion mudpi/extensions/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def increment_count(self):
""" Update the image counter """
self.image_count +=1
if self.image_count > self.max_count:
self.image_count = 0 # overflow
self.image_count = self.count_start # overflow


""" Actions """
Expand Down
2 changes: 1 addition & 1 deletion mudpi/extensions/dht/extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"description": "Provides interface for DHT sensors to take climate readings.",
"documentation": "https://mudpi.app/docs/pi-sensors-humidity"
},
"requirements": ["adafruit-blinka", "adafruit-circuitpython-dht"]
"requirements": ["adafruit-circuitpython-dht==3.5.5", "adafruit-blinka"]
}
40 changes: 22 additions & 18 deletions mudpi/extensions/dht/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,28 @@ def load(self, config):

def validate(self, config):
""" Validate the dht config """
if not config.get('pin'):
raise ConfigError('Missing `pin` in DHT config.')

if not re.match(r'D\d+$', config['pin']) and not re.match(r'A\d+$', config['pin']):
raise ConfigError(
"Cannot detect pin type (Digital or analog), "
"should be Dxx or Axx for digital or analog. "
"Please refer to "
"https://github.com/adafruit/Adafruit_Blinka/tree/master/src/adafruit_blinka/board"
)

valid_models = ['11', '22', '2302']
if config.get('model') not in valid_models:
config['model'] = '11'
Logger.log(
LOG_LEVEL["warning"],
'Sensor Model Error: Defaulting to DHT11'
)
if not isinstance(config, list):
config = [config]

for conf in config:
if not conf.get('pin'):
raise ConfigError('Missing `pin` in DHT config.')

if not re.match(r'D\d+$', conf['pin']) and not re.match(r'A\d+$', conf['pin']):
raise ConfigError(
"Cannot detect pin type (Digital or analog), "
"should be Dxx or Axx for digital or analog. "
"Please refer to "
"https://github.com/adafruit/Adafruit_Blinka/tree/master/src/adafruit_blinka/board"
)

valid_models = ['11', '22', '2302']
if conf.get('model') not in valid_models:
conf['model'] = '11'
Logger.log(
LOG_LEVEL["warning"],
'Sensor Model Error: Defaulting to DHT11'
)

return config

Expand Down
2 changes: 1 addition & 1 deletion mudpi/extensions/gpio/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def state(self):
@property
def classifier(self):
""" Classification further describing it, effects the data formatting """
return 'general'
return self.config.get('classifier', 'general')


""" Methods """
Expand Down
3 changes: 2 additions & 1 deletion mudpi/extensions/nanpy/char_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def update(self):
""" Control LCD display nanpy"""
if self.node.connected:
try:
super().update()
self.check_connection()
super().update()
except (SerialManagerError, SocketManagerError,
BrokenPipeError, ConnectionResetError, OSError,
socket.timeout) as e:
Expand Down
4 changes: 3 additions & 1 deletion mudpi/extensions/nanpy/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def validate(self, config):

if conf.get('pin') is None:
raise ConfigError(f'Missing `pin` in Nanpy control {conf["key"]} config. You need to add a pin.')

else:
conf['pin'] = int(conf['pin'])

if not conf.get('type'):
# Default to the button type
conf['type'] = 'button'
Expand Down
2 changes: 1 addition & 1 deletion mudpi/extensions/nanpy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def analog(self):
@property
def pin(self):
""" Return if gpio is digital or analog """
return self.config.get('pin')
return int(self.config.get('pin'))

""" Methods """
def init(self):
Expand Down
2 changes: 1 addition & 1 deletion mudpi/extensions/nanpy/toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class NanpyGPIOToggle(Toggle):
@property
def pin(self):
""" The GPIO pin """
return self.config.get('pin')
return int(self.config.get('pin'))


""" Methods """
Expand Down
1 change: 0 additions & 1 deletion mudpi/extensions/rtsp/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def update(self):
self.capture_recording(duration=self.record_duration)
else:
self.capture_image()
print(f'Camera {self.id} time:{self.duration}')
self.reset_duration()

def open_stream(self):
Expand Down
5 changes: 5 additions & 0 deletions mudpi/extensions/sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def name(self):
""" Friendly name of control """
return self.config.get('name') or f"{self.id.replace('_', ' ').title()}"

@property
def state(self):
""" Return state for the sensor """
return self._state


""" Actions """
def force_update(self, data=None):
Expand Down
2 changes: 1 addition & 1 deletion mudpi/extensions/sequence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def duration(self):
def topic(self):
""" Return the topic to listen on """
return self.config.get('topic', '').replace(" ", "/").lower() if self.config.get(
'topic') is not None else f'mudpi/sequences/{self.id}'
'topic') is not None else f'{NAMESPACE}/{self.id}'


""" Methods """
Expand Down
4 changes: 4 additions & 0 deletions mudpi/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ def _install_extension_requirements(mudpi, extension):
f'{FONT_YELLOW}{extension.namespace.title()}{FONT_RESET} requirements',
'Installing', 'notice'
)
Logger.log(
LOG_LEVEL["debug"],
f'Installing package {FONT_YELLOW}{requirement}{FONT_RESET}',
)
if not utils.install_package(requirement):
Logger.log(
LOG_LEVEL["error"],
Expand Down
4 changes: 2 additions & 2 deletions mudpi/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def parse_call(self, action_call):
parsed_action['action'] = action_call
return parsed_action

def call(self, action_call, namespace=None, action_data={}):
def call(self, action_call, action_data={}):
""" Call an action from the registry
Format: {namespace}.{action} or
{namespace}.{component}.{action}
Expand All @@ -132,7 +132,7 @@ def call(self, action_call, namespace=None, action_data={}):
validated_data = action.validate(action_data)
if not validated_data and action_data:
raise MudPiError("Action data was not valid!")
self.mudpi.events.publish('core', {'event': 'ActionCall', 'action': action_call, 'data': action_data, 'namespace': namespace or command['namespace']})
self.mudpi.events.publish('core', {'event': 'ActionCall', 'action': action_call, 'data': action_data, 'namespace': command['namespace']})
action(data=validated_data)


Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
redis
paho-mqtt
pyyaml
adafruit-circuitpython-mcp3xxx

0 comments on commit 810f31d

Please sign in to comment.