def do_except(self, args):
        """except <date> <start> <stop>"""
        args = args.split()
        if _debug:
            TestConsoleCmd._debug("do_except %r", args)

        date_string, start_string, stop_string = args
        except_date = Date(date_string).value
        start_time = Time(start_string).value
        stop_time = Time(stop_string).value

        exception_schedule = ArrayOf(SpecialEvent)([
            SpecialEvent(
                period=SpecialEventPeriod(calendarEntry=CalendarEntry(
                    date=except_date)),
                listOfTimeValues=[
                    TimeValue(time=start_time, value=Real(999.0)),
                    TimeValue(time=stop_time, value=Null()),
                ],
                eventPriority=1,
            )
        ])
        if _debug:
            TestConsoleCmd._debug("    - exception_schedule: %r",
                                  exception_schedule)

        # new exception
        test_schedule.exceptionSchedule = exception_schedule
Esempio n. 2
0
def main():
    global args, schedule_objects

    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # set up testing
    setup_module()

    # reset the time machine
    reset_time_machine(start_time="1970-01-01")

    #
    #   Simple daily schedule (actually a weekly schedule with every day
    #   being identical.
    #
    so = LocalScheduleObject(
        objectIdentifier=('schedule', 1),
        objectName='Schedule 1',
        presentValue=Integer(5),
        effectivePeriod=DateRange(
            startDate=(0, 1, 1, 1),
            endDate=(254, 12, 31, 2),
        ),
        weeklySchedule=ArrayOf(DailySchedule)([
            DailySchedule(daySchedule=[
                TimeValue(time=(8, 0, 0, 0), value=Integer(8)),
                TimeValue(time=(14, 0, 0, 0), value=Null()),
                TimeValue(time=(17, 0, 0, 0), value=Integer(42)),
                #                   TimeValue(time=(0,0,0,0), value=Null()),
            ]),
        ] * 7),
        scheduleDefault=Integer(0),
    )
    _log.debug("    - so: %r", so)
    schedule_objects.append(so)

    print("{} @ {}".format(so.presentValue.value, Time().now()))

    for i in range(1, 25):
        hr = "{}:00:01".format(i)

        # let it run until just after midnight
        run_time_machine(stop_time=hr)

        print("{} @ {}".format(so.presentValue.value, Time().now()))

    # done testing
    teardown_module()
Esempio n. 3
0
    def create_weeklySchedule(self, dict_schedule, object_reference=None):
        """
        From a structured dict (see schedule_example), create a WeeklySchedule
        an ArrayOf(DailySchedule)
        """
        object_reference = object_reference
        ds = dict_schedule
        if object_reference is not None:
            self.schedules[object_reference] = ds

        def _set_value(v):
            try:
                if dict_schedule["states"].lower() == "analog":
                    return Real(v)
            except AttributeError:
                if dict_schedule["states"] == ["inactive", "active"]:
                    return Integer(dict_schedule["states"][v])
                else:
                    return Integer(dict_schedule["states"][v] - 1)

        daily_schedules = []
        for day in Schedule.days:
            list_of_events = dict_schedule["week"][day]
            _daily_schedule = [
                TimeValue(time=event[0], value=_set_value(event[1]))
                for event in list_of_events
            ]
            daily_schedules.append(DailySchedule(daySchedule=_daily_schedule))
        return Schedule.WeeklySchedule(daily_schedules)
def main():
    global args, test_analog_value, test_schedule

    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)

    # parse the command line arguments
    args = parser.parse_args()

    if _debug:
        _log.debug("initialization")
    if _debug:
        _log.debug("    - args: %r", args)

    # make a device object
    this_device = LocalDeviceObject(ini=args.ini)
    if _debug:
        _log.debug("    - this_device: %r", this_device)

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # create a writeable analog value object
    test_analog_value = WritableAnalogValueObject(
        objectIdentifier=("analogValue", 1),
        objectName="Test Analog Value",
        presentValue=0.0,
    )
    _log.debug("    - test_analog_value: %r", test_analog_value)
    this_application.add_object(test_analog_value)

    # print when the value changes
    test_analog_value._property_monitors["presentValue"].append(
        analog_value_changed)

    #
    #   Simple daily schedule (actually a weekly schedule with every day
    #   being identical.
    #
    test_schedule = LocalScheduleObject(
        objectIdentifier=("schedule", 1),
        objectName="Test Schedule",
        presentValue=Real(8.0),
        effectivePeriod=DateRange(startDate=(0, 1, 1, 1),
                                  endDate=(254, 12, 31, 2)),
        weeklySchedule=ArrayOf(DailySchedule, 7)([
            DailySchedule(daySchedule=[
                TimeValue(time=(8, 0, 0, 0), value=Real(8.0)),
                TimeValue(time=(14, 0, 0, 0), value=Null()),
                TimeValue(time=(17, 0, 0, 0), value=Real(42.0)),
            ])
        ] * 7),
        listOfObjectPropertyReferences=ListOf(DeviceObjectPropertyReference)([
            DeviceObjectPropertyReference(
                objectIdentifier=("analogValue", 1),
                propertyIdentifier="presentValue",
            )
        ]),
        scheduleDefault=Real(0.0),
    )
    _log.debug("    - test_schedule: %r", test_schedule)
    this_application.add_object(test_schedule)

    TestConsoleCmd()

    _log.debug("running")

    run()

    _log.debug("fini")
    def test_local_schedule(self):
        if _debug: TestLocalSchedule._debug("test_local_schedule")

        # reset the time machine
        reset_time_machine(start_time="1970-01-01")

        # make a device object
        this_device = LocalDeviceObject(
            objectName="device 1",
            objectIdentifier=('device', 1),
            maxApduLengthAccepted=1024,
            segmentationSupported='segmentedBoth',
            vendorIdentifier=999,
        )

        # make a floating application, no network interface
        this_application = Application(this_device)

        # create a writeable analog value object
        avo = WritableAnalogValueObject(
            objectIdentifier=('analogValue', 1),
            objectName='analog value 1',
            presentValue=0.0,
        )
        _log.debug("    - avo: %r", avo)
        this_application.add_object(avo)

        # create a simple daily schedule, actually a weekly schedule with
        # every day identical
        so = LocalScheduleObject(
            objectIdentifier=('schedule', 1),
            objectName='Schedule 1',
            presentValue=Real(-1.0),
            effectivePeriod=DateRange(
                startDate=(0, 1, 1, 1),
                endDate=(254, 12, 31, 2),
            ),
            weeklySchedule=ArrayOf(DailySchedule)([
                DailySchedule(daySchedule=[
                    TimeValue(time=(8, 0, 0, 0), value=Real(8)),
                    TimeValue(time=(14, 0, 0, 0), value=Null()),
                    TimeValue(time=(17, 0, 0, 0), value=Real(42)),
                ]),
            ] * 7),
            listOfObjectPropertyReferences=[
                DeviceObjectPropertyReference(
                    objectIdentifier=('analogValue', 1),
                    propertyIdentifier='presentValue',
                ),
            ],
            priorityForWriting=7,
            scheduleDefault=Real(0.0),
        )
        _log.debug("    - so: %r", so)
        this_application.add_object(so)

        # run from midnight to just after midnight the next day
        for hr, val in zip(range(0, 26),
                           [0] * 8 + [8] * 6 + [0] * 3 + [42] * 7 + [0]):
            # let it run
            run_time_machine(stop_time="{}:00:01".format(hr))
            if _debug:
                TestLocalSchedule._debug(
                    "    - hr, val, pv: %s, %s, %s",
                    hr,
                    val,
                    so.presentValue.value,
                )

            assert so.presentValue.value == val
            assert avo.presentValue == val
def main():
    global args, schedule_objects

    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a device object
    this_device = LocalDeviceObject(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    #
    #   Simple daily schedule (actually a weekly schedule with every day
    #   being identical.
    #
    so = LocalScheduleObject(
        objectIdentifier=('schedule', 1),
        objectName='Schedule 1',
        presentValue=Integer(8),
        effectivePeriod=DateRange(
            startDate=(0, 1, 1, 1),
            endDate=(254, 12, 31, 2),
        ),
        weeklySchedule=ArrayOf(DailySchedule)([
            DailySchedule(daySchedule=[
                TimeValue(time=(8, 0, 0, 0), value=Integer(8)),
                TimeValue(time=(14, 0, 0, 0), value=Null()),
                TimeValue(time=(17, 0, 0, 0), value=Integer(42)),
                #                   TimeValue(time=(0,0,0,0), value=Null()),
            ]),
        ] * 7),
        scheduleDefault=Integer(0),
    )
    _log.debug("    - so: %r", so)
    this_application.add_object(so)
    schedule_objects.append(so)

    #
    #   A special schedule when the Year 2000 problem was supposed to collapse
    #   systems, the panic clears ten minutes later when it didn't.
    #
    so = LocalScheduleObject(
        objectIdentifier=('schedule', 2),
        objectName='Schedule 2',
        presentValue=CharacterString(""),
        effectivePeriod=DateRange(
            startDate=(0, 1, 1, 1),
            endDate=(254, 12, 31, 2),
        ),
        exceptionSchedule=ArrayOf(SpecialEvent)([
            SpecialEvent(
                period=SpecialEventPeriod(calendarEntry=CalendarEntry(
                    date=Date("2000-01-01").value, ), ),
                listOfTimeValues=[
                    TimeValue(time=(0, 0, 0, 0),
                              value=CharacterString("Panic!")),
                    TimeValue(time=(0, 10, 0, 0), value=Null()),
                ],
                eventPriority=1,
            ),
        ]),
        scheduleDefault=CharacterString("Don't panic."),
    )
    _log.debug("    - so: %r", so)
    this_application.add_object(so)
    schedule_objects.append(so)

    #
    #   A special schedule to celebrate Friday.
    #
    so = LocalScheduleObject(
        objectIdentifier=('schedule', 3),
        objectName='Schedule 3',
        presentValue=CharacterString(""),
        effectivePeriod=DateRange(
            startDate=(0, 1, 1, 1),
            endDate=(254, 12, 31, 2),
        ),
        exceptionSchedule=ArrayOf(SpecialEvent)([
            SpecialEvent(
                period=SpecialEventPeriod(calendarEntry=CalendarEntry(
                    weekNDay=xtob("FF.FF.05"), ), ),
                listOfTimeValues=[
                    TimeValue(time=(0, 0, 0, 0),
                              value=CharacterString("It's Friday!")),
                ],
                eventPriority=1,
            ),
        ]),
        scheduleDefault=CharacterString("Keep working."),
    )
    _log.debug("    - so: %r", so)
    this_application.add_object(so)
    schedule_objects.append(so)

    #
    #   A schedule object that refers to an AnalogValueObject in the test
    #   device.
    #
    so = LocalScheduleObject(
        objectIdentifier=('schedule', 4),
        objectName='Schedule 4',
        presentValue=Real(73.5),
        effectivePeriod=DateRange(
            startDate=(0, 1, 1, 1),
            endDate=(254, 12, 31, 2),
        ),
        weeklySchedule=ArrayOf(DailySchedule)([
            DailySchedule(daySchedule=[
                TimeValue(time=(9, 0, 0, 0), value=Real(78.0)),
                TimeValue(time=(10, 0, 0, 0), value=Null()),
            ]),
        ] * 7),
        scheduleDefault=Real(72.0),
        listOfObjectPropertyReferences=SequenceOf(
            DeviceObjectPropertyReference)([
                DeviceObjectPropertyReference(
                    objectIdentifier=('analogValue', 1),
                    propertyIdentifier='presentValue',
                ),
            ]),
    )
    _log.debug("    - so: %r", so)
    this_application.add_object(so)
    schedule_objects.append(so)

    #
    #   The beast
    #
    so = LocalScheduleObject(
        objectIdentifier=('schedule', 5),
        objectName='Schedule 5',
        presentValue=Integer(0),
        effectivePeriod=DateRange(
            startDate=(0, 1, 1, 1),
            endDate=(254, 12, 31, 2),
        ),
        exceptionSchedule=ArrayOf(SpecialEvent)([
            SpecialEvent(
                period=SpecialEventPeriod(calendarEntry=CalendarEntry(
                    weekNDay=xtob("FF.FF.FF"), ), ),
                listOfTimeValues=[
                    TimeValue(time=(5, 0, 0, 0), value=Integer(5)),
                    TimeValue(time=(6, 0, 0, 0), value=Null()),
                ],
                eventPriority=1,
            ),
            SpecialEvent(
                period=SpecialEventPeriod(calendarEntry=CalendarEntry(
                    weekNDay=xtob("FF.FF.FF"), ), ),
                listOfTimeValues=[
                    TimeValue(time=(4, 0, 0, 0), value=Integer(4)),
                    TimeValue(time=(7, 0, 0, 0), value=Null()),
                ],
                eventPriority=2,
            ),
            SpecialEvent(
                period=SpecialEventPeriod(calendarEntry=CalendarEntry(
                    weekNDay=xtob("FF.FF.FF"), ), ),
                listOfTimeValues=[
                    TimeValue(time=(3, 0, 0, 0), value=Integer(3)),
                    TimeValue(time=(8, 0, 0, 0), value=Null()),
                ],
                eventPriority=3,
            ),
            SpecialEvent(
                period=SpecialEventPeriod(calendarEntry=CalendarEntry(
                    weekNDay=xtob("FF.FF.FF"), ), ),
                listOfTimeValues=[
                    TimeValue(time=(2, 0, 0, 0), value=Integer(2)),
                    TimeValue(time=(9, 0, 0, 0), value=Null()),
                ],
                eventPriority=4,
            ),
            SpecialEvent(
                period=SpecialEventPeriod(calendarEntry=CalendarEntry(
                    weekNDay=xtob("FF.FF.FF"), ), ),
                listOfTimeValues=[
                    TimeValue(time=(1, 0, 0, 0), value=Integer(1)),
                ],
                eventPriority=5,
            ),
        ]),
        scheduleDefault=Integer(0),
    )
    _log.debug("    - so: %r", so)
    this_application.add_object(so)
    schedule_objects.append(so)

    # list of time values for every five minutes
    ltv = []
    for hr in range(24):
        for mn in range(0, 60, 5):
            ltv.append(
                TimeValue(time=(hr, mn, 0, 0), value=Integer(hr * 100 + mn)))

    so = LocalScheduleObject(
        objectIdentifier=('schedule', 6),
        objectName='Schedule 6',
        presentValue=Integer(0),
        effectivePeriod=DateRange(
            startDate=(0, 1, 1, 1),
            endDate=(254, 12, 31, 2),
        ),
        exceptionSchedule=ArrayOf(SpecialEvent)([
            SpecialEvent(
                period=SpecialEventPeriod(calendarEntry=CalendarEntry(
                    weekNDay=xtob("FF.FF.FF"), ), ),
                listOfTimeValues=ltv,
                eventPriority=1,
            ),
        ]),
        scheduleDefault=Integer(0),
    )
    _log.debug("    - so: %r", so)
    this_application.add_object(so)
    schedule_objects.append(so)

    # make sure they are all there
    _log.debug("    - object list: %r", this_device.objectList)

    TestConsoleCmd()

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 7
0
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # make a schedule object with an integer value
    so1 = ScheduleObject(
        objectIdentifier=1,
        objectName='Schedule 1 (integer)',
        presentValue=Integer(8),
        weeklySchedule=ArrayOf(DailySchedule)([
            DailySchedule(daySchedule=[
                TimeValue(time=(8, 0, 0, 0), value=Integer(8)),
                TimeValue(time=(14, 0, 0, 0), value=Null()),
                TimeValue(time=(17, 0, 0, 0), value=Integer(42)),
                TimeValue(time=(0, 0, 0, 0), value=Null()),
            ]),
        ] * 7),
        scheduleDefault=Integer(0),
    )
    _log.debug("    - so1: %r", so1)

    so2 = ScheduleObject(
        objectIdentifier=2,
        objectName='Schedule 2 (real)',
        presentValue=Real(73.5),
        weeklySchedule=ArrayOf(DailySchedule)([
            DailySchedule(daySchedule=[
Esempio n. 8
0
def main():
    global args, schedule_objects

    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # set up testing
    setup_module()

    # reset the time machine
    reset_time_machine(start_time="1970-01-01")

    # make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=('device', int(args.ini.objectidentifier)),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a floating application, no network interface
    this_application = Application(this_device)

    #
    #   Simple daily schedule (actually a weekly schedule with every day
    #   being identical.
    #
    so = LocalScheduleObject(
        objectIdentifier=('schedule', 1),
        objectName='Schedule 1',
        presentValue=Real(-1.0),
        effectivePeriod=DateRange(
            startDate=(0, 1, 1, 1),
            endDate=(254, 12, 31, 2),
            ),
        weeklySchedule=ArrayOf(DailySchedule)([
            DailySchedule(
                daySchedule=[
                    TimeValue(time=(8,0,0,0), value=Real(8)),
                    TimeValue(time=(14,0,0,0), value=Null()),
                    TimeValue(time=(17,0,0,0), value=Real(42)),
#                   TimeValue(time=(0,0,0,0), value=Null()),
                    ]
                ),
            ] * 7),
        listOfObjectPropertyReferences=[
            DeviceObjectPropertyReference(
                objectIdentifier=('analogValue', 1),
                propertyIdentifier='presentValue',
#               propertyArrayIndex=5,
#               deviceIdentifier=('device', 999),
                ),
            ],
        priorityForWriting=7,
        scheduleDefault=Real(0.0),
        )
    _log.debug("    - so: %r", so)
    this_application.add_object(so)

    # add an analog value object
    avo = WritableAnalogValueObject(
        objectIdentifier=('analogValue', 1),
        objectName='analog value 1',
        presentValue=0.0,
        )
    _log.debug("    - avo: %r", avo)
    this_application.add_object(avo)

    print("{} @ {}".format(so.presentValue.value, Time().now()))

    for i in range(1, 25):
        hr = "{}:00:01".format(i)

        # let it run until just after midnight
        run_time_machine(stop_time=hr)

        print("{}, {} @ {}".format(
            so.presentValue.value,
            avo.presentValue,
            Time().now(),
            ))

    # done testing
    teardown_module()