Example #1
0
    def test_sendCommand(self, str, rept):
        str.return_value = "a"
        rept.return_value = "'a'"
        queue = MagicMock(spec=HMQueue)
        self.sched = HMScheduler(queue)

        device = 1
        port = 2
        listeners = ['a', 'b']
        scheduler_id = 1
        name = 'keep on keeping on'
        self.sched.sendCommand(name, device, port, listeners, scheduler_id)
        data = {}
        data[Constants.DataPacket.device] = device
        data[Constants.DataPacket.port] = port
        data[Constants.DataPacket.scheduler_id] = scheduler_id
        data[Constants.DataPacket.arrival_time] = GetDateTime()
        data[Constants.DataPacket.listeners] = copy.copy(listeners)
        data[Constants.DataPacket.name] = name
        de = DataEnvelope(type=Constants.EnvelopeTypes.STATUS, data=data)

        #         queue.transmit.assert_called_once_with( DataEnvelope( type='status', packet={},
        #              arrival_time='a', data={'name': 'scheduled status check',
        #                                                    'listeners': ['a', 'b'],
        #                                                    'at': 'a',
        #                                                    'device': 1, 'port': 2, 'scheduler_id': 1} ), 10 )
        #        # Not sure why this in not working.  I have tried all sorts of variations.
        self.assertEqual(queue.transmit.call_count, 1)
        args = queue.transmit.call_args
        self.sched.shutdown()
        self.sched = None
    def readFile( self, filename ):
        ''' Read the number of bytes transmitted and received. '''

        try:
            with open( filename, 'r' ) as f:
                results = f.read()
                dt = GetDateTime()
                return results, dt
        except Exception as ex:
            self.logger.exception( ex )
            raise
Example #3
0
    def add_one_shot( self, delta, args=None, kwargs=None ):
        '''
        Schedule sendCommand to be called after some interval. (ie. in 5 seconds or one hour).  For more information
        on timeDelta see:

        .. seealso:: http://docs.python.org/2/library/datetime.html#timedelta-objects

        :param name: delta the time until sendCommand is called
        :type weeks: timedelta
        :param date: Set the time to call sendCommand
        :type date: datetime
        :param args: the arguments to call sendCommand with
        :type weeks: tuple
        :param date: the kwwargs to call sendCommand with
        :type date: dictionary

        '''
        name = args[0]
        now = GetDateTime()
        dt = now.datetime()
        dt = dt + delta
        token = self.scheduler.add_date_job( self.sendCommand, date=dt,
                                name=name, args=args, kwargs=kwargs )
        self.jobs[name].append( token )
 def test_toString( self ):
     gdt = GetDateTime()
     gdt.dt = datetime.datetime( 2012, 11, 10, 01, 02, 03 )
     self.assertEqual( gdt.toString(), "2012/11/10 01:02:03" )
 def test_str( self ):
     gdt = GetDateTime()
     gdt.dt = datetime.datetime( 2012, 11, 10, 01, 02, 03 )
     self.assertEqual( str( gdt ), "2012/11/10 01:02:03" )
 def test_initializing_datetime( self ):
     dt = datetime.datetime( 2012, 11, 10, 9, 8, 7 )
     gdt = GetDateTime( date_time_value=dt )
     self.assertEqual( gdt.datetime(), dt )
     self.assertEqual( gdt.isoformat(), '2012-11-10T09:08:07' )
Example #7
0
        def step(self, value, data={}, listeners=[]):
            """
            Will detect if the garage door has been opened.  If it has it will:
                | 1. Set the time when the door was opened
                | 2. disable the alarm
                | 3. Turn off the alarm
            
            It will always do the following:
                | 1. Set the garage door to the value that was passed in
                | 2. Start a timer that will send a message in X minutes telling the system
                | to recheck the garage door and if it is still open start the alarm.
                
            :param value: The state of the garage door
            :type value: Boolean
            :param data: a dictionary containing more information about the value.
            :param listeners: a list of the subscribed routines to send the data to
            :returns: value, data, listeners
            :rtype: Boolean, dict, listeners
    
            """

            # Garage Door transitioning from Open to Closed
            if self.status_panel.garage_door == self.status_panel.GARAGE_DOOR_OPEN and \
                    value == self.status_panel.GARAGE_DOOR_CLOSED:
                self.status_panel.changeDisableButtonWarningLight(
                    self.status_panel.LED_OFF)
                self.status_panel.changeAlarm(self.status_panel.ALARM_OFF)
                self.status_panel.process_delayed_alarm.delayedAlarmState = \
                                        self.status_panel.process_delayed_alarm.Disabled
                try:
                    pub.sendMessage(Constants.TopicNames.SchedulerDeleteJob,
                                    name=self.status_panel.
                                    scheduler_turn_off_initial_alarm)
                except Exception as ex:
                    self.logger.exception('Common.send error {}'.format(ex))
                try:
                    pub.sendMessage(
                        Constants.TopicNames.SchedulerDeleteJob,
                        name=self.status_panel.scheduler_delayed_sound_alarm)
                except Exception as ex:
                    self.logger.exception('Common.send error {}'.format(ex))

                self.logger.info('Garage door closed')

            # Garage Door transitioning from Closed to Open
            if self.status_panel.garage_door == self.status_panel.GARAGE_DOOR_CLOSED and \
                    value == self.status_panel.GARAGE_DOOR_OPEN:
                self.status_panel.changeAlarm(self.status_panel.ALARM_ON)
                self.status_panel.changeDisableButtonWarningLight(
                    self.status_panel.LED_OFF)
                self.status_panel.when_garage_door_opened = GetDateTime(
                ).datetime()
                self.status_panel.disenable_alarm_button_pressed = self.status_panel.DISABLE_ALARM_BUTTON_NOT_PRESSED
                self.turnOffAlarmAfterInterval()
                self.setTimerToActivateAlarmAfterInterval()
                self.status_panel.process_delayed_alarm.delayedAlarmState = self.status_panel.process_delayed_alarm.PreAlarm
                self.logger.info('Garage door opening')

            # Garage Door is Closed
            if value == self.status_panel.GARAGE_DOOR_CLOSED:
                self.status_panel.when_garage_door_opened = None
                self.status_panel.process_delayed_alarm.delayedAlarmState = self.status_panel.process_delayed_alarm.Disabled
                self.status_panel.disenable_alarm_button_pressed = self.status_panel.DISABLE_ALARM_BUTTON_NOT_PRESSED
                self.status_panel.changeDisableButtonWarningLight(
                    self.status_panel.LED_OFF)

            self.status_panel.garage_door = value
            self.status_panel.changeGarageDoorWarningLight(value)
            return value, data, listeners