Commit 878057eb authored by nextime's avatar nextime

fix some bugs in Sunrise/Sunset calculation

parent d2b620ab
###########################################################################
# Copyright (c) 2011-2013 Unixmedia S.r.l. <info@unixmedia.it>
# Copyright (c) 2011-2013 Franco (nextime) Lanza <franco@unixmedia.it>
#
# Domotika System Controller Daemon "domotikad" [http://trac.unixmedia.it]
#
# This file is part of domotikad.
#
# domotikad 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from zope.interface import Interface, Attribute
from zope.interface import implements
from twisted.python import reflect
import logging
from dmlib import constants as C
log = logging.getLogger( 'Core' )
class IDMBoards(Interface):
""" Base plugin Interface """
def AutoDiscovery(self):
"""
Discover I/O on this gateway or return configs
"""
def isOnline(self):
"""
Return 1 or 0 for gateway reachable
"""
def initialize(self):
"""
Initialize the gateway if needed
"""
def context2section(ctx):
if int(ctx) in C.SECTIONS.keys():
section=C.SECTIONS[int(ctx)]
else:
section="none"
return section
import logging import logging
from gateways import igateways, modules from gateways import igateways, modules, io
log = logging.getLogger('Core') log = logging.getLogger('Core')
...@@ -16,6 +16,7 @@ def getGatewayPlugin(name): ...@@ -16,6 +16,7 @@ def getGatewayPlugin(name):
qual = "%s.%s" % (p.__module__, p.__class__.__name__) qual = "%s.%s" % (p.__module__, p.__class__.__name__)
log.info("Calling Gateway Module "+qual) log.info("Calling Gateway Module "+qual)
if p.__module__.split('.')[-1]==name: if p.__module__.split('.')[-1]==name:
p.io = gateways.io
return p return p
return None return None
......
...@@ -36,6 +36,15 @@ class DMSun(object): ...@@ -36,6 +36,15 @@ class DMSun(object):
sunrise_ts = calendar.timegm(sunrise.datetime().utctimetuple()) sunrise_ts = calendar.timegm(sunrise.datetime().utctimetuple())
sunset = self.obs.next_setting(ephem.Sun()) #Sunset sunset = self.obs.next_setting(ephem.Sun()) #Sunset
sunset_ts = calendar.timegm(sunset.datetime().utctimetuple()) sunset_ts = calendar.timegm(sunset.datetime().utctimetuple())
beg=self.obs.next_rising(ephem.Sun(), use_center=True)
beg_ts = calendar.timegm(beg.datetime().utctimetuple())
if beg_ts < sunset_ts:
sunrise_ts = beg_ts
sunrise = beg
dayreal = 0 dayreal = 0
if now > sunrise_ts and now < sunset_ts: if now > sunrise_ts and now < sunset_ts:
dayreal = 1 dayreal = 1
...@@ -48,7 +57,17 @@ class DMSun(object): ...@@ -48,7 +57,17 @@ class DMSun(object):
self.obs.horizon = '-0:34' self.obs.horizon = '-0:34'
sunrise=self.obs.previous_rising(ephem.Sun()) #Sunrise sunrise=self.obs.previous_rising(ephem.Sun()) #Sunrise
sunrise_ts = calendar.timegm(sunrise.datetime().utctimetuple()) sunrise_ts = calendar.timegm(sunrise.datetime().utctimetuple())
noon =self.obs.next_transit(ephem.Sun(), start=sunrise) #Solar noon sunset=self.obs.next_setting(ephem.Sun(), use_center=True)
sunset_ts=calendar.timegm(sunset.datetime().utctimetuple())
beg=self.obs.next_rising(ephem.Sun(), use_center=True)
beg_ts = calendar.timegm(beg.datetime().utctimetuple())
if beg_ts < sunset_ts:
sunrise = beg
sunrise_ts = beg_ts
noon=self.obs.next_transit(ephem.Sun(), start=sunrise) #Solar noon
daymax_ts = calendar.timegm(noon.datetime().utctimetuple()) daymax_ts = calendar.timegm(noon.datetime().utctimetuple())
daymax = 0 daymax = 0
if now > daymax_ts-1800 and now < daymax_ts+1800: if now > daymax_ts-1800 and now < daymax_ts+1800:
...@@ -61,10 +80,20 @@ class DMSun(object): ...@@ -61,10 +80,20 @@ class DMSun(object):
self.setObsDate() self.setObsDate()
now = time.time() now = time.time()
self.obs.horizon = '-6' self.obs.horizon = '-6'
beg_civil_twilight=self.obs.previous_rising(ephem.Sun(), use_center=True) #Begin civil twilight beg_civil_twilight=self.obs.previous_rising(ephem.Sun(), use_center=True) #Begin civil twilight
beg_civil_twilight_ts = calendar.timegm(beg_civil_twilight.datetime().utctimetuple()) beg_civil_twilight_ts = calendar.timegm(beg_civil_twilight.datetime().utctimetuple())
end_civil_twilight=self.obs.next_setting(ephem.Sun(), use_center=True) #End civil twilight end_civil_twilight=self.obs.next_setting(ephem.Sun(), use_center=True) #End civil twilight
end_civil_twilight_ts = calendar.timegm(end_civil_twilight.datetime().utctimetuple()) end_civil_twilight_ts = calendar.timegm(end_civil_twilight.datetime().utctimetuple())
beg=self.obs.next_rising(ephem.Sun(), use_center=True)
beg_ts = calendar.timegm(beg.datetime().utctimetuple())
if beg_ts < end_civil_twilight_ts:
beg_civil_twilight_ts = beg_ts
beg_civil_twilight = beg
daycivil = 0 daycivil = 0
if now > beg_civil_twilight_ts and now < end_civil_twilight_ts: if now > beg_civil_twilight_ts and now < end_civil_twilight_ts:
daycivil = 1 daycivil = 1
...@@ -81,6 +110,14 @@ class DMSun(object): ...@@ -81,6 +110,14 @@ class DMSun(object):
beg_astro_twilight_ts=calendar.timegm(beg_astro_twilight.datetime().utctimetuple()) beg_astro_twilight_ts=calendar.timegm(beg_astro_twilight.datetime().utctimetuple())
end_astro_twilight=self.obs.next_setting(ephem.Sun(), use_center=True) #End civil twilight end_astro_twilight=self.obs.next_setting(ephem.Sun(), use_center=True) #End civil twilight
end_astro_twilight_ts=calendar.timegm(end_astro_twilight.datetime().utctimetuple()) end_astro_twilight_ts=calendar.timegm(end_astro_twilight.datetime().utctimetuple())
beg=self.obs.next_rising(ephem.Sun(), use_center=True)
beg_ts = calendar.timegm(beg.datetime().utctimetuple())
if beg_ts < end_astro_twilight_ts:
beg_astro_twilight_ts = beg_ts
beg_astro_twilight = beg
dayastro = 0 dayastro = 0
if now > beg_astro_twilight_ts and now < end_astro_twilight_ts: if now > beg_astro_twilight_ts and now < end_astro_twilight_ts:
dayastro = 1 dayastro = 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment