Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
domotikad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
domotika
domotikad
Commits
91985a0e
Commit
91985a0e
authored
Oct 08, 2014
by
nextime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add +/-seconds option to DAY* commands
parent
311d2183
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
23 deletions
+47
-23
parsers.py
domotika/parsers.py
+16
-4
sky.py
domotika/sky.py
+31
-19
No files found.
domotika/parsers.py
View file @
91985a0e
...
@@ -464,13 +464,25 @@ def statusParser(trigger, sun, restype='string'):
...
@@ -464,13 +464,25 @@ def statusParser(trigger, sun, restype='string'):
except
:
except
:
pass
pass
elif
trigger
.
startswith
(
'DAYREAL'
):
elif
trigger
.
startswith
(
'DAYREAL'
):
ret
=
defer
.
succeed
(
sun
.
getReal
()[
'status'
])
.
addCallback
(
parseReturn
,
reverse
)
shift
=
0
if
'+'
in
trigger
or
'-'
in
trigger
:
shift
=
int
(
trigger
.
replace
(
'DAYREAL'
,
''
))
ret
=
defer
.
succeed
(
sun
.
getReal
(
shift
)[
'status'
])
.
addCallback
(
parseReturn
,
reverse
)
elif
trigger
.
startswith
(
'DAYMAX'
):
elif
trigger
.
startswith
(
'DAYMAX'
):
ret
=
defer
.
succeed
(
sun
.
getMax
()[
'status'
])
.
addCallback
(
parseReturn
,
reverse
)
shift
=
0
if
'+'
in
trigger
or
'-'
in
trigger
:
shift
=
int
(
trigger
.
replace
(
'DAYMAX'
,
''
))
ret
=
defer
.
succeed
(
sun
.
getMax
(
shift
)[
'status'
])
.
addCallback
(
parseReturn
,
reverse
)
elif
trigger
.
startswith
(
'DAYCIVIL'
):
elif
trigger
.
startswith
(
'DAYCIVIL'
):
ret
=
defer
.
succeed
(
sun
.
getCivil
()[
'status'
])
.
addCallback
(
parseReturn
,
reverse
)
shift
=
0
if
'+'
in
trigger
or
'-'
in
trigger
:
shift
=
int
(
trigger
.
replace
(
'DAYCIVIL'
,
''
))
ret
=
defer
.
succeed
(
sun
.
getCivil
(
shift
)[
'status'
])
.
addCallback
(
parseReturn
,
reverse
)
elif
trigger
.
startswith
(
'DAYASTRO'
):
elif
trigger
.
startswith
(
'DAYASTRO'
):
ret
=
defer
.
succeed
(
sun
.
getAstro
()[
'status'
])
.
addCallback
(
parseReturn
,
reverse
)
shift
=
0
if
'+'
in
trigger
or
'-'
in
trigger
:
shift
=
int
(
trigger
.
replace
(
'DAYASTRO'
,
''
))
ret
=
defer
.
succeed
(
sun
.
getAstro
(
shift
)[
'status'
])
.
addCallback
(
parseReturn
,
reverse
)
elif
trigger
==
"TRUE"
or
trigger
==
"1"
:
elif
trigger
==
"TRUE"
or
trigger
==
"1"
:
ret
=
defer
.
succeed
(
1
)
.
addCallback
(
parseReturn
,
reverse
)
ret
=
defer
.
succeed
(
1
)
.
addCallback
(
parseReturn
,
reverse
)
...
...
domotika/sky.py
View file @
91985a0e
...
@@ -17,19 +17,24 @@ class DMSun(object):
...
@@ -17,19 +17,24 @@ class DMSun(object):
#To get U.S. Naval Astronomical Almanac values, use these settings
#To get U.S. Naval Astronomical Almanac values, use these settings
self
.
obs
.
pressure
=
0
self
.
obs
.
pressure
=
0
self
.
shift
=
0
def
setObsDate
(
self
):
def
_checkDate
(
self
,
shift
=
0
):
if
self
.
today
!=
date
.
today
()
or
self
.
shift
!=
shift
:
self
.
setObsDate
(
shift
)
def
setObsDate
(
self
,
shift
=
0
):
# detect utf offset
# detect utf offset
diff
=
round
((
datetime
.
now
()
-
datetime
.
utcnow
())
.
total_seconds
())
diff
=
round
((
datetime
.
now
()
-
datetime
.
utcnow
())
.
total_seconds
())
self
.
shift
=
shift
self
.
today
=
date
.
today
()
self
.
today
=
date
.
today
()
# midnight of today
# midnight of today
utcmidnight
=
datetime
.
combine
(
date
.
today
(),
dtime
(
0
,
0
,
0
))
+
timedelta
(
seconds
=
int
(
diff
))
utcmidnight
=
datetime
.
combine
(
date
.
today
(),
dtime
(
0
,
0
,
0
))
+
timedelta
(
seconds
=
int
(
diff
))
+
timedelta
(
seconds
=
int
(
shift
))
self
.
obs
.
date
=
str
(
utcmidnight
)
self
.
obs
.
date
=
str
(
utcmidnight
)
def
getReal
(
self
):
def
getReal
(
self
,
shift
=
0
):
if
self
.
today
!=
date
.
today
():
self
.
_checkDate
(
shift
)
self
.
setObsDate
()
now
=
time
.
time
()
now
=
time
.
time
()
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
...
@@ -48,11 +53,12 @@ class DMSun(object):
...
@@ -48,11 +53,12 @@ class DMSun(object):
dayreal
=
0
dayreal
=
0
if
now
>
sunrise_ts
and
now
<
sunset_ts
:
if
now
>
sunrise_ts
and
now
<
sunset_ts
:
dayreal
=
1
dayreal
=
1
return
{
'status'
:
dayreal
,
'start'
:(
ephem
.
localtime
(
sunrise
),
sunrise_ts
),
'stop'
:(
ephem
.
localtime
(
sunset
),
sunset_ts
)}
r
=
{
'status'
:
dayreal
,
'start'
:(
ephem
.
localtime
(
sunrise
),
sunrise_ts
),
'stop'
:(
ephem
.
localtime
(
sunset
),
sunset_ts
)}
self
.
_checkDate
(
0
)
return
r
def
getMax
(
self
):
def
getMax
(
self
,
shift
=
0
):
if
self
.
today
!=
date
.
today
():
self
.
_checkDate
(
shift
)
self
.
setObsDate
()
now
=
time
.
time
()
now
=
time
.
time
()
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
...
@@ -72,12 +78,13 @@ class DMSun(object):
...
@@ -72,12 +78,13 @@ class DMSun(object):
daymax
=
0
daymax
=
0
if
now
>
daymax_ts
-
1800
and
now
<
daymax_ts
+
1800
:
if
now
>
daymax_ts
-
1800
and
now
<
daymax_ts
+
1800
:
daymax
=
1
daymax
=
1
r
eturn
{
'status'
:
daymax
,
'start'
:(
ephem
.
localtime
(
noon
)
-
timedelta
(
seconds
=
1800
),
daymax_ts
-
1800
),
r
=
{
'status'
:
daymax
,
'start'
:(
ephem
.
localtime
(
noon
)
-
timedelta
(
seconds
=
1800
),
daymax_ts
-
1800
),
'stop'
:(
ephem
.
localtime
(
noon
)
+
timedelta
(
seconds
=
1800
),
daymax_ts
+
1800
)}
'stop'
:(
ephem
.
localtime
(
noon
)
+
timedelta
(
seconds
=
1800
),
daymax_ts
+
1800
)}
self
.
_checkDate
(
0
)
return
r
def
getCivil
(
self
):
def
getCivil
(
self
,
shift
=
0
):
if
self
.
today
!=
date
.
today
():
self
.
_checkDate
(
shift
)
self
.
setObsDate
()
now
=
time
.
time
()
now
=
time
.
time
()
self
.
obs
.
horizon
=
'-6'
self
.
obs
.
horizon
=
'-6'
...
@@ -97,13 +104,15 @@ class DMSun(object):
...
@@ -97,13 +104,15 @@ class DMSun(object):
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
r
eturn
{
'status'
:
daycivil
,
'start'
:(
ephem
.
localtime
(
beg_civil_twilight
),
beg_civil_twilight_ts
),
r
=
{
'status'
:
daycivil
,
'start'
:(
ephem
.
localtime
(
beg_civil_twilight
),
beg_civil_twilight_ts
),
'stop'
:(
ephem
.
localtime
(
end_civil_twilight
),
end_civil_twilight_ts
)}
'stop'
:(
ephem
.
localtime
(
end_civil_twilight
),
end_civil_twilight_ts
)}
self
.
_checkDate
(
0
)
return
r
def
getAstro
(
self
):
if
self
.
today
!=
date
.
today
(
):
def
getAstro
(
self
,
shift
=
0
):
self
.
setObsDate
(
)
self
.
_checkDate
(
shift
)
now
=
time
.
time
()
now
=
time
.
time
()
self
.
obs
.
horizon
=
'-18'
self
.
obs
.
horizon
=
'-18'
beg_astro_twilight
=
self
.
obs
.
previous_rising
(
ephem
.
Sun
(),
use_center
=
True
)
#Begin civil twilight
beg_astro_twilight
=
self
.
obs
.
previous_rising
(
ephem
.
Sun
(),
use_center
=
True
)
#Begin civil twilight
...
@@ -122,8 +131,11 @@ class DMSun(object):
...
@@ -122,8 +131,11 @@ class DMSun(object):
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
r
eturn
{
'status'
:
dayastro
,
'start'
:(
ephem
.
localtime
(
beg_astro_twilight
),
beg_astro_twilight_ts
),
r
=
{
'status'
:
dayastro
,
'start'
:(
ephem
.
localtime
(
beg_astro_twilight
),
beg_astro_twilight_ts
),
'stop'
:(
ephem
.
localtime
(
end_astro_twilight
),
end_astro_twilight_ts
)}
'stop'
:(
ephem
.
localtime
(
end_astro_twilight
),
end_astro_twilight_ts
)}
self
.
_checkDate
(
0
)
return
r
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment