mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Schedule component
Can read schedule json config file Can load custom rule_types
This commit is contained in:
parent
2478656622
commit
aab52ca686
50
homeassistant/components/scheduler/__init__.py
Normal file
50
homeassistant/components/scheduler/__init__.py
Normal file
@ -0,0 +1,50 @@
|
||||
"""
|
||||
homeassistant.components.scheduler
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
"""
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
from pprint import pprint
|
||||
import importlib
|
||||
|
||||
from homeassistant.components import switch, sun
|
||||
from homeassistant.loader import get_component
|
||||
|
||||
# The domain of your component. Should be equal to the name of your component
|
||||
DOMAIN = 'scheduler'
|
||||
|
||||
# List of component names (string) your component depends upon
|
||||
# If you are setting up a group but not using a group for anything,
|
||||
# don't depend on group
|
||||
DEPENDENCIES = ['sun']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
_SCHEDULE_FILE = 'schedule.json'
|
||||
_RULE_TYPE_CACHE = {}
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup(hass, config):
|
||||
""" Register services or listen for events that your component needs. """
|
||||
|
||||
def setup_schedule(description):
|
||||
|
||||
for rule in description['rules']:
|
||||
rule_init = get_component('scheduler.{}'.format(rule['type']))
|
||||
|
||||
if rule_init is None:
|
||||
_LOGGER.error('Error loading schedule rule %s', rule['type'])
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
with open(hass.get_config_path(_SCHEDULE_FILE)) as schedule_file:
|
||||
schedule_descriptions = json.load(schedule_file)
|
||||
|
||||
for schedule_description in schedule_descriptions:
|
||||
if not setup_schedule(schedule_description):
|
||||
return False
|
||||
|
||||
return True
|
5
homeassistant/components/scheduler/sun.py
Normal file
5
homeassistant/components/scheduler/sun.py
Normal file
@ -0,0 +1,5 @@
|
||||
"""asd"""
|
||||
|
||||
|
||||
def hej():
|
||||
print('wut sun wut')
|
5
homeassistant/components/scheduler/time.py
Normal file
5
homeassistant/components/scheduler/time.py
Normal file
@ -0,0 +1,5 @@
|
||||
"""asd"""
|
||||
|
||||
|
||||
def hej():
|
||||
print('wut wut')
|
Loading…
x
Reference in New Issue
Block a user