#!/usr/bin/env python3 # vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab ######################################################################### # Copyright 2011-2013 Niko Will ######################################################################### # This file is part of SmartHome.py. http://mknx.github.io/smarthome/ # # SmartHome.py is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # SmartHome.py is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with SmartHome.py. If not, see . ########################################################################## # Item Data Format # # Each UZSU item is of type list. Each list entry has to be a dict with specific key and value pairs. Here are the possible keys and what their for: # # dtstart: a datetime object. Exact datetime as start value for the rrule algorithm. Important e.g. for FREQ=MINUTELY rrules (optional). # # value: the value which will be set to the item. # # active: True if the entry is activated, False if not. A deactivated entry is stored to the database but doesn't trigger the setting of the value. It can be enabled later with the update method. # # time: time as string to use sunrise/sunset arithmetics like in the crontab eg. 17:008:00, 17:00 datetime.now(self._sh.tzinfo()): return next, value if 'sun' in time: next = self.sun(datetime.combine(today, datetime.min.time()).replace(tzinfo=self._sh.tzinfo()), time) self.logger.debug("Result parsing time (sun) {}: {}".format(time, next)) else: next = datetime.combine(today, parser.parse(time.strip()).time()).replace(tzinfo=self._sh.tzinfo()) if next and next.date() == today and next > datetime.now(self._sh.tzinfo()): return next, value except Exception as e: self.logger.error("Error '{}' parsing time: {}".format(time, e)) return None, None def _sun(self, dt, tstr): #dt contains a datetime object, whereas tstr should contain a string like '6:00 next_time: next_time = dmin if smax is not None: h, sep, m = smax.partition(':') try: dmax = next_time.replace(hour=int(h), minute=int(m), second=0, tzinfo=self._sh.tzinfo()) except Exception: self.logger.error('Wrong syntax: {0}. Should be [H:M<](sunrise|sunset)[+|-][offset][ dmax: self.logger.error('Wrong times: the earliest time should be smaller than the latest time in {}'.format(tstr)) return return next_time