Esempio n. 1
0
def create_single_shot_watering(dt): # dt is a datetie.datetime instnace
    new_watering = iSprinkleWatering(str(uuid.uuid4()))
    new_watering.set_schedule_type(iSprinkleWatering.SINGLE_SHOT)
    new_watering.set_enabled(True)
    new_watering.set_start_date(dt.date())
    new_watering.set_start_time_of_day(dt.time())
    return new_watering
Esempio n. 2
0
def yaml_watering_to_watering(yaml_watering):
    try:
        watering_uuid = ''
        if yaml_watering.has_key('uuid'):
            watering_uuid = yaml_watering['uuid']
        watering = iSprinkleWatering(watering_uuid)
        watering.set_schedule_type(yaml_watering['schedule type'])
        watering.set_enabled(yaml_watering['enabled'])
        watering.set_start_time_of_day(string_to_time(yaml_watering['start time']))
        for zone_duration in yaml_watering['zone durations']:
            watering.add_zone(zone_duration[0], zone_duration[1])
        if yaml_watering['schedule type'] == iSprinkleWatering.EVERY_N_DAYS:
            watering.set_period_days(yaml_watering['period days'])
        elif yaml_watering['schedule type'] == iSprinkleWatering.SINGLE_SHOT:
            watering.set_start_date(string_to_date(yaml_watering['start date']))
        elif yaml_watering['schedule type'] == iSprinkleWatering.FIXED_DAYS_OF_WEEK:
            watering.set_days_of_week_mask(yaml_watering['days of week'])
        return watering
    except ValueError as error:
        raise Exception('Bad time format. Should be 17:45:00')
    except KeyError as error:
        raise Exception('Missing field "%s" in YAML stream' % (str(error)))