Пример #1
0
	'''Invoke a desired sensor command invoker.'''
#	assert(isinstance(command, smart.sensor.commands.SmartSystemCommand))
	result = command.invoke()
	LOG.info(INVOKED.format(command.__class__.__name__))
	return result

################################################################################
# Module Exceptions
################################################################################
class SmartCLIException(Exception):
	pass

################################################################################
# Globals
################################################################################
LOG = LoggerFactory.get("core", __name__).payload

# Setup module globals
PROGRAM_VERSION = '0.0.1'
VERSION_START_DATE = '12.20.2015'
PROGRAM_NAME = 'Smart Command-line Interface (SmartCLI)'
PROGRAM_INFO = '{}\nv{} {}\nCopywrite (c) 2015, {}'.format(
        PROGRAM_NAME,
        PROGRAM_VERSION,
        VERSION_START_DATE,
	"Hayden McParlane"
)

# Misc Commands
CMD_VERSION = 'version'
Пример #2
0
import copy
import json as json
from pypatterns import commander as commander
import requests
from smart.core.system_logging import LoggerFactory
import smart.globals as G

# TODO: The specific implementation connecting the sensor to the core of the
#       smart system doesn't need to be understood by the commands. Add an
#       object that will abstract away the specific "system-core-interface"
#       used so that it is flexible to change later on.
API = None

# TODO: Modify URL to be dynamic and to be pulled from the json data
REST_BASE = G.REST_BASE_STORAGE
LOG = LoggerFactory.get('core', __name__).payload

EXECUTING = "executing command: {}"


class SmartSystemCommand(commander.Command):
    def __init__(self, **kwargs):
        super(SmartSystemCommand, self).__init__()


class InsertSensorData(SmartSystemCommand):
    def __init__(self, **kwargs):
        super(InsertSensorData, self).__init__()
        validated_data = kwargs['data']
        assert (len(validated_data) > 2)
        assert (validated_data.get(G.UNIT_ID) != "")
Пример #3
0
#
# Tests associated with module restful_service.py
#
import json as _JSON
import requests as _REQ
import unittest as _UT

from smart.core.system_logging import LoggerFactory as _LOG_FACTORY
import restful_service as _RS
################################################################################
# Globals
################################################################################
_BASE_RESOURCE_URL_FRAME = 'http://{}:{}'
_RESOURCE_BASE = _BASE_RESOURCE_URL_FRAME.format("127.0.0.1", "5000")
_LOG = _LOG_FACTORY.get("core", __name__).payload
_SAMPLE_SENSOR_DATA = {"key1":"value1", "key2":"value2", "key3":True}
_URL = _RESOURCE_BASE + "/sensors/sample_sensor_unit_id/sample_sensor_id/data/"

################################################################################
# Tests
################################################################################
class TestSensorToControllerInteractions(_UT.TestCase):

	def test_sensor_to_controller_data_storage_request(self):
		_REQUIRED_VALS = {
			"unsuccessful": { "error_occurred": self.verify_error_occurred, 
					  "raised_exception": self.verify_raised_exception, 
					  "raised_exception_message": 
						self.verify_exception_message
			 }, 
			"successful": { "payload": self.verify_payload }
Пример #4
0
import copy
import json as json
from pypatterns import commander as commander
import requests
from smart.core.system_logging import LoggerFactory
import smart.globals as G

# TODO: The specific implementation connecting the sensor to the core of the
#       smart system doesn't need to be understood by the commands. Add an
#       object that will abstract away the specific "system-core-interface"
#       used so that it is flexible to change later on.
API = None

# TODO: Modify URL to be dynamic and to be pulled from the json data
REST_BASE = G.REST_BASE_STORAGE
LOG = LoggerFactory.get('core', __name__).payload

EXECUTING = "executing command: {}"
class SmartSystemCommand(commander.Command):
	def __init__(self, **kwargs):
		super(SmartSystemCommand, self).__init__()

class InsertSensorData(SmartSystemCommand):
	def __init__(self, **kwargs):
		super(InsertSensorData, self).__init__()
		validated_data = kwargs['data']
		assert(len(validated_data) > 2)
		assert( validated_data.get(G.UNIT_ID) != "")
		assert( validated_data.get(G.SENSOR_ID) != "")
		assert( len(validated_data.get(G.PAYLOAD)) > 0 )
		for key in G.STANDARD_DATA_KEYS: