mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-11 22:34:04 +02:00
Merge branch 'dev' into master
This commit is contained in:
commit
976a35e109
3 changed files with 22 additions and 17 deletions
|
|
@ -44,11 +44,11 @@ from homeassistant.helpers.event import track_sunrise, track_sunset, track_time_
|
|||
from homeassistant.util.color import (
|
||||
color_temperature_to_rgb, color_RGB_to_xy,
|
||||
color_xy_to_hs)
|
||||
from homeassistant.util.dt import utcnow as dt_utcnow, as_local
|
||||
from homeassistant.util.dt import now as dt_now, get_time_zone
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
VERSION = '1.0.11'
|
||||
VERSION = '1.0.13b'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -135,6 +135,7 @@ class CircadianLighting(object):
|
|||
self.data['elevation'] = elevation
|
||||
self.data['interval'] = interval
|
||||
self.data['transition'] = transition
|
||||
self.data['timezone'] = self.get_timezone()
|
||||
self.data['percent'] = self.calc_percent()
|
||||
self.data['colortemp'] = self.calc_colortemp()
|
||||
self.data['rgb_color'] = self.calc_rgb()
|
||||
|
|
@ -152,11 +153,18 @@ class CircadianLighting(object):
|
|||
else:
|
||||
track_sunset(self.hass, self._update, self.data['sunset_offset'])
|
||||
|
||||
def get_timezone(self):
|
||||
from timezonefinder import TimezoneFinder
|
||||
tf = TimezoneFinder()
|
||||
timezone_string = tf.timezone_at(lng=self.data['longitude'], lat=self.data['latitude'])
|
||||
timezone = get_time_zone(timezone_string)
|
||||
_LOGGER.debug("Timezone: " + str(timezone))
|
||||
return timezone
|
||||
|
||||
def get_sunrise_sunset(self, date = None):
|
||||
if self.data['sunrise_time'] is not None and self.data['sunset_time'] is not None:
|
||||
if date is None:
|
||||
utcdate = dt_utcnow()
|
||||
date = as_local(utcdate)
|
||||
date = dt_now(self.data['timezone'])
|
||||
sunrise = date.replace(hour=int(self.data['sunrise_time'].strftime("%H")), minute=int(self.data['sunrise_time'].strftime("%M")), second=int(self.data['sunrise_time'].strftime("%S")), microsecond=int(self.data['sunrise_time'].strftime("%f")))
|
||||
sunset = date.replace(hour=int(self.data['sunset_time'].strftime("%H")), minute=int(self.data['sunset_time'].strftime("%M")), second=int(self.data['sunset_time'].strftime("%S")), microsecond=int(self.data['sunset_time'].strftime("%f")))
|
||||
solar_noon = sunrise + (sunset - sunrise)/2
|
||||
|
|
@ -172,15 +180,13 @@ class CircadianLighting(object):
|
|||
_LOGGER.debug("Astral location: " + str(location))
|
||||
if self.data['sunrise_time'] is not None:
|
||||
if date is None:
|
||||
utcdate = dt_utcnow()
|
||||
date = as_local(utcdate)
|
||||
date = dt_now(self.data['timezone'])
|
||||
sunrise = date.replace(hour=int(self.data['sunrise_time'].strftime("%H")), minute=int(self.data['sunrise_time'].strftime("%M")), second=int(self.data['sunrise_time'].strftime("%S")), microsecond=int(self.data['sunrise_time'].strftime("%f")))
|
||||
else:
|
||||
sunrise = location.sunrise(date)
|
||||
if self.data['sunset_time'] is not None:
|
||||
if date is None:
|
||||
utcdate = dt_utcnow()
|
||||
date = as_local(utcdate)
|
||||
date = dt_now(self.data['timezone'])
|
||||
sunset = date.replace(hour=int(self.data['sunset_time'].strftime("%H")), minute=int(self.data['sunset_time'].strftime("%M")), second=int(self.data['sunset_time'].strftime("%S")), microsecond=int(self.data['sunset_time'].strftime("%f")))
|
||||
else:
|
||||
sunset = location.sunset(date)
|
||||
|
|
@ -191,15 +197,14 @@ class CircadianLighting(object):
|
|||
if self.data['sunset_offset'] is not None:
|
||||
sunset = sunset + self.data['sunset_offset']
|
||||
return {
|
||||
SUN_EVENT_SUNRISE: sunrise,
|
||||
SUN_EVENT_SUNSET: sunset,
|
||||
'solar_noon': solar_noon,
|
||||
'solar_midnight': solar_midnight
|
||||
SUN_EVENT_SUNRISE: sunrise.astimezone(self.data['timezone']),
|
||||
SUN_EVENT_SUNSET: sunset.astimezone(self.data['timezone']),
|
||||
'solar_noon': solar_noon.astimezone(self.data['timezone']),
|
||||
'solar_midnight': solar_midnight.astimezone(self.data['timezone'])
|
||||
}
|
||||
|
||||
def calc_percent(self):
|
||||
utcnow = dt_utcnow()
|
||||
now = as_local(utcnow)
|
||||
now = dt_now(self.data['timezone'])
|
||||
_LOGGER.debug("now: " + str(now))
|
||||
|
||||
today_sun_times = self.get_sunrise_sunset(now)
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@
|
|||
"documentation": "https://github.com/claytonjn/hass-circadian_lighting",
|
||||
"dependencies": [],
|
||||
"codeowners": ["@claytonjn"],
|
||||
"requirements": []
|
||||
"requirements": ["timezonefinder==4.2.0"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"circadian_lighting": {
|
||||
"updated_at": "2020-03-07",
|
||||
"version": "1.0.11",
|
||||
"updated_at": "2020-06-03",
|
||||
"version": "1.0.13b",
|
||||
"local_location": "/custom_components/circadian_lighting/__init__.py",
|
||||
"remote_location": "https://raw.githubusercontent.com/claytonjn/hass-circadian_lighting/master/custom_components/circadian_lighting/__init__.py",
|
||||
"visit_repo": "https://github.com/claytonjn/hass-circadian_lighting",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue