Skip to content

Commit

Permalink
Merge remote-tracking branch 'balloob/dev' into automation-decorator
Browse files Browse the repository at this point in the history
# Conflicts:
#	homeassistant/helpers/service.py
#	tests/helpers/test_service.py
  • Loading branch information
rmkraus committed Jan 25, 2016
2 parents 5830da6 + e7865c1 commit 60dd2d4
Show file tree
Hide file tree
Showing 28 changed files with 374 additions and 191 deletions.
2 changes: 1 addition & 1 deletion homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def from_config_file(config_path, hass=None, verbose=False, daemon=False,

enable_logging(hass, verbose, daemon, log_rotate_days)

config_dict = config_util.load_config_file(config_path)
config_dict = config_util.load_yaml_config_file(config_path)

return from_config_dict(config_dict, hass, enable_log=False,
skip_pip=skip_pip)
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import logging

import homeassistant.core as ha
import homeassistant.util as util
from homeassistant.helpers import extract_entity_ids
from homeassistant.helpers.entity import split_entity_id
from homeassistant.helpers.service import extract_entity_ids
from homeassistant.loader import get_component
from homeassistant.const import (
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE)
Expand All @@ -36,7 +36,7 @@ def is_on(hass, entity_id=None):
entity_ids = hass.states.entity_ids()

for entity_id in entity_ids:
domain = util.split_entity_id(entity_id)[0]
domain = split_entity_id(entity_id)[0]

module = get_component(domain)

Expand Down Expand Up @@ -92,7 +92,7 @@ def handle_turn_service(service):

# Group entity_ids by domain. groupby requires sorted data.
by_domain = it.groupby(sorted(entity_ids),
lambda item: util.split_entity_id(item)[0])
lambda item: split_entity_id(item)[0])

for domain, ent_ids in by_domain:
# We want to block for all calls and only return when all calls
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""
import logging

from homeassistant.helpers import generate_entity_id
from homeassistant.helpers.entity import generate_entity_id
from homeassistant.const import EVENT_TIME_CHANGED

DOMAIN = "configurator"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/device_tracker/netgear.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)

_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['pynetgear==0.3.1']
REQUIREMENTS = ['pynetgear==0.3.2']


def get_scanner(hass, config):
Expand Down
9 changes: 4 additions & 5 deletions homeassistant/components/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
https://home-assistant.io/components/group/
"""
import homeassistant.core as ha
from homeassistant.helpers import generate_entity_id
from homeassistant.helpers.event import track_state_change
from homeassistant.helpers.entity import Entity
import homeassistant.util as util
from homeassistant.helpers.entity import (
Entity, split_entity_id, generate_entity_id)
from homeassistant.const import (
ATTR_ENTITY_ID, STATE_ON, STATE_OFF,
STATE_HOME, STATE_NOT_HOME, STATE_OPEN, STATE_CLOSED,
Expand Down Expand Up @@ -62,7 +61,7 @@ def expand_entity_ids(hass, entity_ids):

try:
# If entity_id points at a group, expand it
domain, _ = util.split_entity_id(entity_id)
domain, _ = split_entity_id(entity_id)

if domain == DOMAIN:
found_ids.extend(
Expand All @@ -75,7 +74,7 @@ def expand_entity_ids(hass, entity_ids):
found_ids.append(entity_id)

except AttributeError:
# Raised by util.split_entity_id if entity_id is not a string
# Raised by split_entity_id if entity_id is not a string
pass

return found_ids
Expand Down
19 changes: 17 additions & 2 deletions homeassistant/components/light/rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import logging
import homeassistant.components.rfxtrx as rfxtrx

from homeassistant.components.light import Light
from homeassistant.components.light import Light, ATTR_BRIGHTNESS
from homeassistant.util import slugify

from homeassistant.const import ATTR_ENTITY_ID
Expand Down Expand Up @@ -112,6 +112,7 @@ def __init__(self, name, event, datas):
self._event = event
self._state = datas[ATTR_STATE]
self._should_fire_event = datas[ATTR_FIREEVENT]
self._brightness = 0

@property
def should_poll(self):
Expand All @@ -133,12 +134,25 @@ def is_on(self):
""" True if light is on. """
return self._state

@property
def brightness(self):
""" Brightness of this light between 0..255. """
return self._brightness

def turn_on(self, **kwargs):
""" Turn the light on. """
brightness = kwargs.get(ATTR_BRIGHTNESS)

if brightness is None:
self._brightness = 100
else:
self._brightness = ((brightness + 4) * 100 // 255 - 1)

if hasattr(self, '_event') and self._event:
self._event.device.send_on(rfxtrx.RFXOBJECT.transport)
self._event.device.send_dim(rfxtrx.RFXOBJECT.transport,
self._brightness)

self._brightness = (self._brightness * 255 // 100)
self._state = True
self.update_ha_state()

Expand All @@ -148,5 +162,6 @@ def turn_off(self, **kwargs):
if hasattr(self, '_event') and self._event:
self._event.device.send_off(rfxtrx.RFXOBJECT.transport)

self._brightness = 0
self._state = False
self.update_ha_state()
5 changes: 2 additions & 3 deletions homeassistant/components/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
from homeassistant.const import (
EVENT_STATE_CHANGED, STATE_NOT_HOME, STATE_ON, STATE_OFF,
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, HTTP_BAD_REQUEST)
from homeassistant import util
import homeassistant.util.dt as dt_util
from homeassistant.components import recorder, sun

from homeassistant.helpers.entity import split_entity_id

DOMAIN = "logbook"
DEPENDENCIES = ['recorder', 'http']
Expand Down Expand Up @@ -209,7 +208,7 @@ def humanify(events):
entity_id = event.data.get(ATTR_ENTITY_ID)
if domain is None and entity_id is not None:
try:
domain = util.split_entity_id(str(entity_id))[0]
domain = split_entity_id(str(entity_id))[0]
except IndexError:
pass

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/media_player/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK,
MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_VIDEO)

REQUIREMENTS = ['pychromecast==0.6.14']
REQUIREMENTS = ['pychromecast==0.7.1']
CONF_IGNORE_CEC = 'ignore_cec'
CAST_SPLASH = 'https://home-assistant.io/images/cast/splash.png'
SUPPORT_CAST = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/media_player/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def setup_plexserver(host, token, hass, add_devices_callback):
{host: {'token': token}}):
_LOGGER.error('failed to save config file')

_LOGGER.info('Connected to: htts://%s', host)
_LOGGER.info('Connected to: http://%s', host)

plex_clients = {}
plex_sessions = {}
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/media_player/squeezebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,12 @@ def media_image_url(self):
""" Image url of current playing media. """
if 'artwork_url' in self._status:
media_url = self._status['artwork_url']
else:
elif 'id' in self._status:
media_url = ('/music/{track_id}/cover.jpg').format(
track_id=self._status["id"])
track_id=self._status['id'])
else:
media_url = ('/music/current/cover.jpg?player={player}').format(
player=self._id)

base_url = 'http://{server}:{port}/'.format(
server=self._lms.host,
Expand Down
66 changes: 36 additions & 30 deletions homeassistant/components/notify/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,38 @@ def get_service(hass, config):
""" Get the mail notification service. """

if not validate_config({DOMAIN: config},
{DOMAIN: ['server', 'port', 'sender', 'username',
'password', 'recipient']},
{DOMAIN: ['recipient']},
_LOGGER):
return None

smtp_server = config['server']
port = int(config['port'])
username = config['username']
password = config['password']
starttls = int(config['starttls'])
smtp_server = config.get('server', 'localhost')
port = int(config.get('port', '25'))
username = config.get('username', None)
password = config.get('password', None)
starttls = int(config.get('starttls', 0))
debug = config.get('debug', 0)

server = None
try:
server = smtplib.SMTP(smtp_server, port)
server = smtplib.SMTP(smtp_server, port, timeout=5)
server.set_debuglevel(debug)
server.ehlo()
if starttls == 1:
server.starttls()
server.ehlo()
if username and password:
try:
server.login(username, password)

try:
server.login(username, password)

except (smtplib.SMTPException, smtplib.SMTPSenderRefused):
_LOGGER.exception("Please check your settings.")

return None
except (smtplib.SMTPException, smtplib.SMTPSenderRefused):
_LOGGER.exception("Please check your settings.")
return None

except smtplib.socket.gaierror:
_LOGGER.exception(
"SMTP server not found. "
"Please check the IP address or hostname of your SMTP server.")
"SMTP server not found (%s:%s). "
"Please check the IP address or hostname of your SMTP server.",
smtp_server, port)

return None

Expand All @@ -68,7 +69,7 @@ def get_service(hass, config):

return MailNotificationService(
smtp_server, port, config['sender'], starttls, username, password,
config['recipient'])
config['recipient'], debug)


# pylint: disable=too-few-public-methods, too-many-instance-attributes
Expand All @@ -77,32 +78,34 @@ class MailNotificationService(BaseNotificationService):

# pylint: disable=too-many-arguments
def __init__(self, server, port, sender, starttls, username,
password, recipient):
password, recipient, debug):
self._server = server
self._port = port
self._sender = sender
self.starttls = starttls
self.username = username
self.password = password
self.recipient = recipient
self.debug = debug
self.tries = 2
self.mail = None

self.connect()

def connect(self):
""" Connect/Authenticate to SMTP Server """

self.mail = smtplib.SMTP(self._server, self._port)
self.mail.ehlo_or_helo_if_needed()
mail = smtplib.SMTP(self._server, self._port, timeout=5)
mail.set_debuglevel(self.debug)
mail.ehlo_or_helo_if_needed()
if self.starttls == 1:
self.mail.starttls()
self.mail.ehlo()
self.mail.login(self.username, self.password)
mail.starttls()
mail.ehlo()
if self.username and self.password:
mail.login(self.username, self.password)
return mail

def send_message(self, message="", **kwargs):
""" Send a message to a user. """

mail = self.connect()
subject = kwargs.get(ATTR_TITLE)

msg = MIMEText(message)
Expand All @@ -113,10 +116,13 @@ def send_message(self, message="", **kwargs):

for _ in range(self.tries):
try:
self.mail.sendmail(self._sender, self.recipient,
msg.as_string())
mail.sendmail(self._sender, self.recipient,
msg.as_string())
break
except smtplib.SMTPException:
_LOGGER.warning('SMTPException sending mail: '
'retrying connection')
self.connect()
mail.quit()
mail = self.connect()

mail.quit()
4 changes: 2 additions & 2 deletions homeassistant/components/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import threading

from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity import ToggleEntity, split_entity_id
from homeassistant.helpers.event import track_point_in_utc_time
from homeassistant.helpers.service import call_from_config
from homeassistant.util import slugify, split_entity_id
from homeassistant.util import slugify
import homeassistant.util.dt as date_util
from homeassistant.const import (
ATTR_ENTITY_ID, EVENT_TIME_CHANGED, STATE_ON, SERVICE_TURN_ON,
Expand Down
Loading

0 comments on commit 60dd2d4

Please sign in to comment.