Esempio n. 1
0
    def testUpdateActuator(self):
        ad = ActuatorData(actuatorType=ActuatorData.HUMIDIFIER_ACTUATOR_TYPE)
        ad.setCommand(ActuatorData.COMMAND_ON)
        ad.setValue(self.DEFAULT_VAL_A)
        print(self.hSimTask.name)
        self.assertTrue(self.hSimTask.updateActuator(ad))
        adr = self.hSimTask.getLatestActuatorResponse()

        self.assertIsNotNone(adr)
        self.assertEqual(adr.getValue(), self.DEFAULT_VAL_A)
        logging.info("ActuatorData: " + str(adr))

        ad.setValue(self.DEFAULT_VAL_B)
        self.assertTrue(self.hSimTask.updateActuator(ad))
        adr = self.hSimTask.getLatestActuatorResponse()

        self.assertIsNotNone(adr)
        self.assertEqual(adr.getValue(), self.DEFAULT_VAL_B)
        logging.info("ActuatorData: " + str(adr))

        ad.setCommand(ActuatorData.COMMAND_OFF)
        self.assertTrue(self.hSimTask.updateActuator(ad))
        adr = self.hSimTask.getLatestActuatorResponse()

        self.assertIsNotNone(adr)
        self.assertEqual(adr.getCommand(), ActuatorData.COMMAND_OFF)
        logging.info("ActuatorData: " + str(adr))
Esempio n. 2
0
    def testLedDisplayEmulation(self):
        ad = ActuatorData(actuatorType=ActuatorData.LED_DISPLAY_ACTUATOR_TYPE)
        ad.setCommand(ActuatorData.COMMAND_ON)
        ad.setStateData("What's up?")
        self.actuatorAdapterMgr.sendActuatorCommand(ad)

        ad.setCommand(ActuatorData.COMMAND_OFF)
        self.actuatorAdapterMgr.sendActuatorCommand(ad)
    def _createTestActuatorData(self):
        ad = ActuatorData()

        ad.setName(self.DEFAULT_NAME)
        ad.setCommand(ActuatorData.COMMAND_ON)
        ad.setStateData(self.DEFAULT_STATE_DATA)
        ad.setValue(self.DEFAULT_VALUE)

        return ad
    def testFullUpdate(self):
        ad = ActuatorData()
        ad2 = self._createTestActuatorData()

        ad.updateData(ad2)

        self.assertEqual(ad.getCommand(), ActuatorData.COMMAND_ON)
        self.assertEqual(ad.getStateData(), self.DEFAULT_STATE_DATA)
        self.assertEqual(ad.getValue(), self.DEFAULT_VALUE)
Esempio n. 5
0
    def testHvacEmulation(self):
        ad = ActuatorData(actuatorType=ActuatorData.HVAC_ACTUATOR_TYPE)
        ad.setValue(22.5)

        ad.setCommand(ActuatorData.COMMAND_ON)
        self.actuatorAdapterMgr.sendActuatorCommand(ad)

        ad.setCommand(ActuatorData.COMMAND_OFF)
        self.actuatorAdapterMgr.sendActuatorCommand(ad)
Esempio n. 6
0
    def testHumidifierEmulation(self):
        ad = ActuatorData(actuatorType=ActuatorData.HUMIDIFIER_ACTUATOR_TYPE)
        ad.setValue(50.0)

        ad.setCommand(ActuatorData.COMMAND_ON)
        self.actuatorAdapterMgr.sendActuatorCommand(ad)

        ad.setCommand(ActuatorData.COMMAND_OFF)
        self.actuatorAdapterMgr.sendActuatorCommand(ad)
 def __init__(self,
              actuatorType: int = ActuatorData.DEFAULT_ACTUATOR_TYPE,
              simpleName: str = "Actuator",
              actuatorName=ConfigConst.NOT_SET):
     self.name = actuatorName
     self.actuatorType = actuatorType
     self.simpleName = simpleName
     self.latestActuatorData = ActuatorData()
     self.value = 0.0
    def testWriteActuatorDataToCdaDataPath(self):
        logging.info("\n\n----- [ActuatorData to JSON to file] -----")

        dataObj = ActuatorData()
        dataStr = self.dataUtil.actuatorDataToJson(dataObj)
        fileName = self.cdaDataPath + '/ActuatorData.dat'

        logging.info("Sample ActuatorData JSON (validated): " + str(dataStr))
        logging.info("Writing ActuatorData JSON to CDA data path: " + fileName)

        fileRef = Path(fileName)
        fileRef.write_text(dataStr, encoding='utf-8')
Esempio n. 9
0
    def testStartAndStopManagerWithMqttAndCoap(self):
        ddMgr = DeviceDataManager(enableMqtt=False, enableCoap=False)

        actuatorData = ActuatorData(
            actuatorType=ActuatorData.HVAC_ACTUATOR_TYPE)

        actuatorData.setCommand(ActuatorData.COMMAND_ON)
        actuatorData.setStateData("This is a test.")

        ddMgr.handleActuatorCommandMessage(actuatorData)

        sleep(10)
Esempio n. 10
0
    def jsonToActuatorData(self, jsonData):
        jsonData = jsonData.replace("\'", "\"").replace('False',
                                                        'false').replace(
                                                            'True', 'true')
        adDict = json.loads(jsonData)
        ad = ActuatorData()
        mvDict = vars(ad)

        for key in adDict:
            if key in mvDict:
                setattr(ad, key, adDict[key])

        return ad
Esempio n. 11
0
    def _handleSensorDataAnalysis(self, data: SensorData):
        """
        Call this from handleSensorMessage() to determine if there's
        any action to take on the message. Steps to take:
        1) Check config: Is there a rule or flag that requires immediate processing of data?
        2) Act on data: If # 1 is true, determine what - if any - action is required, and execute.
        """

        logging.info("_handleSensorDataAnalysis is called." + str(data))
        #actuatorData = ActuatorData(ActuatorData.PATIENT_ACTUATOR_TYPE)
        if data.getValue() > 90:
            actuatorData = ActuatorData(
                ActuatorData.HEART_RATE_ACTUATOR_TYPE_UP)
            actuatorData.setCommand(ActuatorData.COMMAND_ON)
            self.actuatorAdapterManager.sendActuatorCommand(actuatorData)
Esempio n. 12
0
    def testUpdateEmulator(self):
        ad = ActuatorData(actuatorType=ActuatorData.HUMIDIFIER_ACTUATOR_TYPE)
        ad.setCommand(ActuatorData.COMMAND_ON)
        ad.setValue(50.0)

        self.assertTrue(self.huSimTask.updateActuator(ad))
        adr = self.huSimTask.getLatestActuatorResponse()

        if adr:
            self.assertEqual(adr.getCommand(), ActuatorData.COMMAND_ON)
            self.assertEqual(adr.getStatusCode(), 0)
            logging.info("ActuatorData: " + str(adr))

            # wait 5 seconds
            sleep(5)
        else:
            logging.warning("ActuatorData is None.")

        ad.setValue(35.0)

        self.assertTrue(self.huSimTask.updateActuator(ad))
        adr = self.huSimTask.getLatestActuatorResponse()

        if adr:
            self.assertEqual(adr.getCommand(), ActuatorData.COMMAND_ON)
            self.assertEqual(adr.getStatusCode(), 0)
            logging.info("ActuatorData: " + str(adr))

            # wait 5 seconds
        else:
            logging.warning("ActuatorData is None.")

        ad.setCommand(ActuatorData.COMMAND_OFF)

        self.assertTrue(self.huSimTask.updateActuator(ad))
        adr = self.huSimTask.getLatestActuatorResponse()

        if adr:
            self.assertEqual(adr.getCommand(), ActuatorData.COMMAND_OFF)
            self.assertEqual(adr.getStatusCode(), 0)
            logging.info("ActuatorData: " + str(adr))
        else:
            logging.warning("ActuatorData is None.")
    def testUpdateEmulator(self):
        ad = ActuatorData(actuatorType=ActuatorData.LED_DISPLAY_ACTUATOR_TYPE)
        ad.setCommand(ActuatorData.COMMAND_ON)
        ad.setStateData(self.HELLO_WORLD_A)

        self.assertTrue(self.lddSimTask.updateActuator(ad))
        adr = self.lddSimTask.getLatestActuatorResponse()

        if adr:
            self.assertEqual(adr.getCommand(), ActuatorData.COMMAND_ON)
            self.assertEqual(adr.getStatusCode(), 0)
            logging.info("ActuatorData: " + str(adr))

            # wait 5 seconds
            sleep(5)
        else:
            logging.warning("ActuatorData is None.")

        ad.setStateData(self.HELLO_WORLD_B)

        self.assertTrue(self.lddSimTask.updateActuator(ad))
        adr = self.lddSimTask.getLatestActuatorResponse()

        if adr:
            self.assertEqual(adr.getCommand(), ActuatorData.COMMAND_ON)
            self.assertEqual(adr.getStatusCode(), 0)
            logging.info("ActuatorData: " + str(adr))

            # wait 5 seconds
        else:
            logging.warning("ActuatorData is None.")

        ad.setCommand(ActuatorData.COMMAND_OFF)

        self.assertTrue(self.lddSimTask.updateActuator(ad))
        adr = self.lddSimTask.getLatestActuatorResponse()

        if adr:
            self.assertEqual(adr.getCommand(), ActuatorData.COMMAND_OFF)
            self.assertEqual(adr.getStatusCode(), 0)
            logging.info("ActuatorData: " + str(adr))
        else:
            logging.warning("ActuatorData is None.")
Esempio n. 14
0
    def testActuatorDataConversionsFromObject(self):
        logging.info("\n\n----- [JSON Conversions from ActuatorData] -----")

        adName = "FooBar2 Actuator"
        adObj1 = ActuatorData()
        adObj1.setName(adName)

        adObj1Str = self.dataUtil.actuatorDataToJson(adObj1)
        adObj2 = self.dataUtil.jsonToActuatorData(adObj1Str)
        adObj2Str = self.dataUtil.actuatorDataToJson(adObj2)

        logging.info("Sample ActuatorData: " + str(adObj1))
        logging.info("ActuatorData to JSON: " + str(adObj1Str))
        logging.info("JSON back to ActuatorData: " + str(adObj2))
        logging.info("ActuatorData back to JSON: " + str(adObj2Str))

        self.assertEqual(adName, adObj1.getName())
        self.assertEqual(adObj1.getName(), adObj2.getName())
        self.assertEqual(adObj1.getTimeStamp(), adObj2.getTimeStamp())
        self.assertEqual(adObj1Str, adObj2Str)
Esempio n. 15
0
    def testActuatorCmdPubSub(self):
        qos = 1

        # NOTE: delay can be anything you'd like - the sleep() calls are simply to slow things down a bit for observation
        delay = self.cfg.getInteger(ConfigConst.MQTT_GATEWAY_SERVICE,
                                    ConfigConst.KEEP_ALIVE_KEY,
                                    ConfigConst.DEFAULT_KEEP_ALIVE)

        actuatorData = ActuatorData()
        payload = DataUtil().actuatorDataToJson(actuatorData)

        self.mcc.connectClient()

        sleep(5)

        self.mcc.publishMessage(
            resource=ResourceNameEnum.CDA_ACTUATOR_CMD_RESOURCE,
            msg=payload,
            qos=qos)

        sleep(delay)

        self.mcc.disconnectClient()
    def testDefaultValues(self):
        ad = ActuatorData()

        self.assertEqual(ad.getCommand(), ActuatorData.DEFAULT_COMMAND)
        self.assertEqual(ad.getStatusCode(), ActuatorData.DEFAULT_STATUS)