Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def sunPosFromCoord(latitude, longitude, time_):
"""
Find azimuth annd elevation of the sun using the pysolar library.
Takes latitude(deg), longitude(deg) and a datetime object.
Return tuple conaining (elevation, azimuth)
TODO verify if timezone influences the results.
"""
azim = solar.get_azimuth(latitude, longitude, time_)
alti = solar.get_altitude(latitude, longitude, time_)
# Convert to radians
azim = (azim + 360)*np.pi/180
elev = (90 - alti)*np.pi/180
return elev, azim
d = datetime.now()
if self.timeaddr:
self.tunnel.group_write(self.timeaddr,
time_to_knx(d))
if self.dateaddr:
self.tunnel.group_write(self.dateaddr,
date_to_knx(d))
if self.datetimeaddr:
self.tunnel.group_write(self.datetimeaddr,
datetime_to_knx(d))
if self.daynightaddr:
from pysolar.solar import get_altitude
alt = get_altitude(self.lat, self.long, d)
if alt > 0:
self.tunnel.group_write(self.daynightaddr, 1)
else:
self.tunnel.group_write(self.daynightaddr, 0)
return res
elif svname==SysVars[27]: #sun radiation
try:
from pytz import reference
from pysolar.solar import get_altitude
from pysolar.radiation import get_radiation_direct
pysolarsupported = 1
except:
pysolarsupported = 0
res = "-1"
if pysolarsupported==1:
try:
localtime = reference.LocalTimezone()
today = datetime.now(localtime)
altitude_deg = get_altitude(Settings.AdvSettings["Latitude"],Settings.AdvSettings["Longitude"], today)
res = get_radiation_direct(today, altitude_deg)
except Exception as e:
print(e)
return res
return res
res = "00:00"
return res
elif svname==SysVars[25]: #sun altitude
try:
from pytz import reference
from pysolar.solar import get_altitude
pysolarsupported = 1
except:
pysolarsupported = 0
res = "0"
if pysolarsupported==1:
try:
localtime = reference.LocalTimezone()
today = datetime.now(localtime)
res = get_altitude(Settings.AdvSettings["Latitude"],Settings.AdvSettings["Longitude"], today)
except Exception as e:
print(e)
res = "0"
return res
elif svname==SysVars[26]: #sun azimuth
try:
from pytz import reference
from pysolar.solar import get_azimuth
pysolarsupported = 1
except:
pysolarsupported = 0
res = "0"
if pysolarsupported==1:
try:
localtime = reference.LocalTimezone()