smart_brain/function/helpers.py

33 lines
778 B
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import config
import geo
import inspect
import time
class changed_value_indicator(dict):
def __init__(self):
super().__init__(self)
def changed_here(self, topic, key, value):
caller_name = inspect.getmodule(inspect.stack()[1][0]).__name__ + '.' + inspect.stack()[1][3]
key = '::'.join([caller_name, topic, key])
#
rv = self.get(key) != value
self[key] = value
return rv
def now():
return time.mktime(time.localtime())
def sunrise_time(time_offs_min=30):
return time.mktime(geo.sun.sunrise(config.GEO_POSITION)) + time_offs_min * 60
def sunset_time(time_offs_min=-30):
return time.mktime(geo.sun.sunset(config.GEO_POSITION)) + time_offs_min * 60