Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
Conflicts:
	homeassistant/components/http/frontend.py
	homeassistant/components/http/www_static/frontend.html
  • Loading branch information
kangaroo committed Jan 22, 2015
2 parents ead5d99 + 4f910be commit 8b947e2
Show file tree
Hide file tree
Showing 59 changed files with 798 additions and 200 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "homeassistant/external/netdisco"]
path = homeassistant/external/netdisco
url = https://github.com/balloob/netdisco.git
[submodule "homeassistant/external/noop"]
path = homeassistant/external/noop
url = https://github.com/balloob/noop.git
1 change: 0 additions & 1 deletion config/custom_components/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
_LOGGER = logging.getLogger(__name__)


# pylint: disable=unused-argument
def setup(hass, config):
""" Setup example component. """

Expand Down
12 changes: 6 additions & 6 deletions homeassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,11 @@ class State(object):
state: the state of the entity
attributes: extra information on entity and state
last_changed: last time the state was changed, not the attributes.
last_updated: last time this object was updated.
"""

__slots__ = ['entity_id', 'state', 'attributes', 'last_changed']
__slots__ = ['entity_id', 'state', 'attributes',
'last_changed', 'last_updated']

def __init__(self, entity_id, state, attributes=None, last_changed=None):
if not ENTITY_ID_PATTERN.match(entity_id):
Expand All @@ -439,13 +441,14 @@ def __init__(self, entity_id, state, attributes=None, last_changed=None):
self.entity_id = entity_id
self.state = state
self.attributes = attributes or {}
self.last_updated = dt.datetime.now()

# Strip microsecond from last_changed else we cannot guarantee
# state == State.from_dict(state.as_dict())
# This behavior occurs because to_dict uses datetime_to_str
# which does not preserve microseconds
self.last_changed = util.strip_microseconds(
last_changed or dt.datetime.now())
last_changed or self.last_updated)

def copy(self):
""" Creates a copy of itself. """
Expand Down Expand Up @@ -527,15 +530,12 @@ def get(self, entity_id):
def get_since(self, point_in_time):
"""
Returns all states that have been changed since point_in_time.
Note: States keep track of last_changed -without- microseconds.
Therefore your point_in_time will also be stripped of microseconds.
"""
point_in_time = util.strip_microseconds(point_in_time)

with self._lock:
return [state for state in self._states.values()
if state.last_changed >= point_in_time]
if state.last_updated >= point_in_time]

def is_state(self, entity_id, state):
""" Returns True if entity exists and is specified state. """
Expand Down
70 changes: 52 additions & 18 deletions homeassistant/__main__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
""" Starts home assistant. """
from __future__ import print_function

import sys
import os
import argparse
import importlib

try:
from homeassistant import bootstrap

except ImportError:
# This is to add support to load Home Assistant using
# `python3 homeassistant` instead of `python3 -m homeassistant`
def validate_python():
""" Validate we're running the right Python version. """
major, minor = sys.version_info[:2]

# Insert the parent directory of this file into the module search path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from homeassistant import bootstrap

from homeassistant.const import EVENT_HOMEASSISTANT_START
from homeassistant.components import http, demo
if major < 3 or (major == 3 and minor < 4):
print("Home Assistant requires atleast Python 3.4")
sys.exit()


def validate_dependencies():
Expand All @@ -39,6 +34,34 @@ def validate_dependencies():
sys.exit()


def ensure_path_and_load_bootstrap():
""" Ensure sys load path is correct and load Home Assistant bootstrap. """
try:
from homeassistant import bootstrap

except ImportError:
# This is to add support to load Home Assistant using
# `python3 homeassistant` instead of `python3 -m homeassistant`

# Insert the parent directory of this file into the module search path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from homeassistant import bootstrap

return bootstrap


def validate_git_submodules():
""" Validate the git submodules are cloned. """
try:
# pylint: disable=no-name-in-module, unused-variable
from homeassistant.external.noop import WORKING # noqa
except ImportError:
print("Repository submodules have not been initialized")
print("Please run: git submodule update --init --recursive")
sys.exit()


def ensure_config_path(config_dir):
""" Gets the path to the configuration file.
Creates one if it not exists. """
Expand All @@ -65,9 +88,8 @@ def ensure_config_path(config_dir):
return config_path


def main():
""" Starts Home Assistant. Will create demo config if no config found. """

def get_arguments():
""" Get parsed passed in arguments. """
parser = argparse.ArgumentParser()
parser.add_argument(
'-c', '--config',
Expand All @@ -83,15 +105,26 @@ def main():
action='store_true',
help='Open the webinterface in a browser')

args = parser.parse_args()
return parser.parse_args()


def main():
""" Starts Home Assistant. """
validate_python()
validate_dependencies()

config_dir = os.path.join(os.getcwd(), args.config)
bootstrap = ensure_path_and_load_bootstrap()

validate_git_submodules()

args = get_arguments()

config_dir = os.path.join(os.getcwd(), args.config)
config_path = ensure_config_path(config_dir)

if args.demo_mode:
from homeassistant.components import http, demo

# Demo mode only requires http and demo components.
hass = bootstrap.from_config_dict({
http.DOMAIN: {},
Expand All @@ -101,7 +134,8 @@ def main():
hass = bootstrap.from_config_file(config_path)

if args.open_ui:
# pylint: disable=unused-argument
from homeassistant.const import EVENT_HOMEASSISTANT_START

def open_browser(event):
""" Open the webinterface in a browser. """
if hass.local_api is not None:
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def turn_off(hass, entity_id=None, **service_data):
hass.services.call(ha.DOMAIN, SERVICE_TURN_OFF, service_data)


# pylint: disable=unused-argument
def setup(hass, config):
""" Setup general services related to homeassistant. """

Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/automation/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def register(hass, config, action):
from_state = config.get(CONF_FROM, MATCH_ALL)
to_state = config.get(CONF_TO, MATCH_ALL)

# pylint: disable=unused-argument
def state_automation_listener(entity, from_s, to_s):
""" Listens for state changes and calls action. """
action()
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/automation/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def register(hass, config, action):
minutes = convert(config.get(CONF_MINUTES), int)
seconds = convert(config.get(CONF_SECONDS), int)

# pylint: disable=unused-argument
def time_automation_listener(now):
""" Listens for time changes and calls action. """
action()
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
SERVICE_BROWSE_URL = "browse_url"


# pylint: disable=unused-argument
def setup(hass, config):
""" Listen for browse_url events and open
the url in the default webbrowser. """
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/chromecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def setup(hass, config):
for host in hosts:
setup_chromecast(casts, host)

# pylint: disable=unused-argument
def chromecast_discovered(service, info):
""" Called when a Chromecast has been discovered. """
logger.info("New Chromecast discovered: %s", info[0])
Expand Down Expand Up @@ -212,7 +211,7 @@ def update_chromecast_state(entity_id, chromecast):

hass.states.set(entity_id, state, state_attr)

def update_chromecast_states(time): # pylint: disable=unused-argument
def update_chromecast_states(time):
""" Updates all chromecast states. """
if casts:
logger.info("Updating Chromecast status")
Expand Down Expand Up @@ -298,7 +297,7 @@ def play_youtube_video_service(service, video_id):
pychromecast.play_youtube_video(video_id, cast.host)
update_chromecast_state(entity_id, cast)

hass.track_time_change(update_chromecast_states)
hass.track_time_change(update_chromecast_states, second=[0, 15, 30, 45])

hass.services.register(DOMAIN, SERVICE_TURN_OFF,
turn_off_service)
Expand Down
Loading

0 comments on commit 8b947e2

Please sign in to comment.