Schedule component

Can read schedule json config file
Can load custom rule_types
This commit is contained in:
Gustav Ahlberg 2014-11-17 21:18:01 +01:00
parent 2478656622
commit aab52ca686
3 changed files with 60 additions and 0 deletions

View 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

View File

@ -0,0 +1,5 @@
"""asd"""
def hej():
print('wut sun wut')

View File

@ -0,0 +1,5 @@
"""asd"""
def hej():
print('wut wut')