mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-11 22:34:04 +02:00
more simplifications
This commit is contained in:
parent
d9deee9e52
commit
1f8324c065
4 changed files with 15 additions and 28 deletions
|
|
@ -30,8 +30,10 @@ Technical notes: I had to make a lot of assumptions when writing this app
|
|||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
|
||||
import astral
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.light import ATTR_TRANSITION, VALID_TRANSITION
|
||||
from homeassistant.const import (
|
||||
CONF_ELEVATION,
|
||||
|
|
@ -51,8 +53,7 @@ from homeassistant.util.color import (
|
|||
)
|
||||
from homeassistant.util.dt import get_time_zone
|
||||
from homeassistant.util.dt import now as dt_now
|
||||
|
||||
VERSION = "1.0.13"
|
||||
from timezonefinder import TimezoneFinder
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -61,16 +62,13 @@ CIRCADIAN_LIGHTING_UPDATE_TOPIC = f"{DOMAIN}_update"
|
|||
SUN_EVENT_NOON = "solar_noon"
|
||||
SUN_EVENT_MIDNIGHT = "solar_midnight"
|
||||
|
||||
CONF_MIN_CT = "min_colortemp"
|
||||
DEFAULT_MIN_CT = 2500
|
||||
CONF_MAX_CT = "max_colortemp"
|
||||
DEFAULT_MAX_CT = 5500
|
||||
CONF_MIN_CT, DEFAULT_MIN_CT = "min_colortemp", 2500
|
||||
CONF_MAX_CT, DEFAULT_MAX_CT = "max_colortemp", 5500
|
||||
CONF_INTERVAL, DEFAULT_INTERVAL = "interval", 300
|
||||
CONF_SUNRISE_OFFSET = "sunrise_offset"
|
||||
CONF_SUNSET_OFFSET = "sunset_offset"
|
||||
CONF_SUNRISE_TIME = "sunrise_time"
|
||||
CONF_SUNSET_TIME = "sunset_time"
|
||||
CONF_INTERVAL = "interval"
|
||||
DEFAULT_INTERVAL = 300
|
||||
DEFAULT_TRANSITION = 60
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
|
|
@ -181,8 +179,6 @@ class CircadianLighting:
|
|||
track_sunset(self.hass, self._update, self._sunset_offset)
|
||||
|
||||
def get_timezone(self):
|
||||
from timezonefinder import TimezoneFinder
|
||||
|
||||
tf = TimezoneFinder()
|
||||
timezone_string = tf.timezone_at(lng=self._longitude, lat=self._latitude)
|
||||
timezone = get_time_zone(timezone_string)
|
||||
|
|
@ -201,13 +197,13 @@ class CircadianLighting:
|
|||
if self._time["sunrise"] is not None and self._time["sunset"] is not None:
|
||||
if date is None:
|
||||
date = dt_now(self._timezone)
|
||||
sunrise = date.replace(**self._time_dict("sunrise"))
|
||||
sunrise = date.replace(
|
||||
**self._time_dict("sunrise")
|
||||
) # XXX: redefine _time_dict to do the replace!
|
||||
sunset = date.replace(**self._time_dict("sunset"))
|
||||
solar_noon = sunrise + (sunset - sunrise) / 2
|
||||
solar_midnight = sunset + ((sunrise + timedelta(days=1)) - sunset) / 2
|
||||
else:
|
||||
import astral
|
||||
|
||||
location = astral.Location()
|
||||
location.name = "name"
|
||||
location.region = "region"
|
||||
|
|
@ -291,7 +287,7 @@ class CircadianLighting:
|
|||
# We're also (obviously) generating a different parabola for sunrise-sunset
|
||||
|
||||
# sunrise-sunset parabola
|
||||
if now_ts > today[SUN_EVENT_SUNRISE] and now_ts < today[SUN_EVENT_SUNSET]:
|
||||
if today[SUN_EVENT_SUNRISE] < now_ts < today[SUN_EVENT_SUNSET]:
|
||||
h = today[SUN_EVENT_NOON]
|
||||
k = 100
|
||||
# parabola before solar_noon else after solar_noon
|
||||
|
|
@ -303,7 +299,7 @@ class CircadianLighting:
|
|||
y = 0
|
||||
|
||||
# sunset_sunrise parabola
|
||||
elif now_ts > today[SUN_EVENT_SUNSET] and now_ts < today[SUN_EVENT_SUNRISE]:
|
||||
elif today[SUN_EVENT_SUNSET] < now_ts < today[SUN_EVENT_SUNRISE]:
|
||||
h = today[SUN_EVENT_MIDNIGHT]
|
||||
k = -100
|
||||
# parabola before solar_midnight else after solar_midnight
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@
|
|||
"documentation": "https://github.com/claytonjn/hass-circadian_lighting",
|
||||
"dependencies": [],
|
||||
"codeowners": ["@claytonjn"],
|
||||
"requirements": ["timezonefinder==4.2.0"]
|
||||
"requirements": ["timezonefinder==4.2.0", "astral==1.10.1"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
Circadian Lighting Sensor for Home-Assistant.
|
||||
"""
|
||||
|
||||
DEPENDENCIES = ["circadian_lighting"]
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers.dispatcher import dispatcher_connect
|
||||
|
|
|
|||
|
|
@ -2,10 +2,7 @@
|
|||
Circadian Lighting Switch for Home-Assistant.
|
||||
"""
|
||||
|
||||
DEPENDENCIES = ["circadian_lighting", "light"]
|
||||
|
||||
import logging
|
||||
from contextlib import suppress
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
|
|
@ -365,11 +362,8 @@ class CircadianSwitch(SwitchEntity, RestoreEntity):
|
|||
|
||||
def sleep_state_changed(self, entity_id, from_state, to_state):
|
||||
_LOGGER.debug(f"{entity_id} change from {from_state} to {to_state}")
|
||||
if (
|
||||
to_state.state == self._sleep_state
|
||||
or from_state.state == self._sleep_state
|
||||
):
|
||||
self._update_switch(self._initial_transition, force=True)
|
||||
if to_state.state == self._sleep_state or from_state.state == self._sleep_state:
|
||||
self._update_switch(self._initial_transition, force=True)
|
||||
|
||||
def disable_state_changed(self, entity_id, from_state, to_state):
|
||||
_LOGGER.debug("{entity_id} change from {from_state} to {to_state}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue