Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions homeassistant/components/cover/opengarage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,31 @@

_LOGGER = logging.getLogger(__name__)

ATTR_DISTANCE_SENSOR = "distance_sensor"
ATTR_DOOR_STATE = "door_state"
ATTR_SIGNAL_STRENGTH = "wifi_signal"
ATTR_DISTANCE_SENSOR = 'distance_sensor'
ATTR_DOOR_STATE = 'door_state'
ATTR_SIGNAL_STRENGTH = 'wifi_signal'

CONF_DEVICEKEY = "device_key"
CONF_DEVICE_ID = 'device_id'
CONF_DEVICE_KEY = 'device_key'

DEFAULT_NAME = 'OpenGarage'
DEFAULT_PORT = 80

STATE_CLOSING = "closing"
STATE_OFFLINE = "offline"
STATE_OPENING = "opening"
STATE_STOPPED = "stopped"
STATE_CLOSING = 'closing'
STATE_OFFLINE = 'offline'
STATE_OPENING = 'opening'
STATE_STOPPED = 'stopped'

STATES_MAP = {
0: STATE_CLOSED,
1: STATE_OPEN
1: STATE_OPEN,
}

COVER_SCHEMA = vol.Schema({
vol.Required(CONF_DEVICEKEY): cv.string,
vol.Required(CONF_DEVICE_KEY): cv.string,
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_NAME): cv.string
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand All @@ -50,7 +51,7 @@


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up OpenGarage covers."""
"""Set up the OpenGarage covers."""
covers = []
devices = config.get(CONF_COVERS)

Expand All @@ -59,8 +60,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
CONF_NAME: device_config.get(CONF_NAME),
CONF_HOST: device_config.get(CONF_HOST),
CONF_PORT: device_config.get(CONF_PORT),
"device_id": device_config.get(CONF_DEVICE, device_id),
CONF_DEVICEKEY: device_config.get(CONF_DEVICEKEY)
CONF_DEVICE_ID: device_config.get(CONF_DEVICE, device_id),
CONF_DEVICE_KEY: device_config.get(CONF_DEVICE_KEY)
}

covers.append(OpenGarageCover(hass, args))
Expand All @@ -79,8 +80,8 @@ def __init__(self, hass, args):
self.hass = hass
self._name = args[CONF_NAME]
self.device_id = args['device_id']
self._devicekey = args[CONF_DEVICEKEY]
self._state = STATE_UNKNOWN
self._device_key = args[CONF_DEVICE_KEY]
self._state = None
self._state_before_move = None
self.dist = None
self.signal = None
Expand Down Expand Up @@ -138,8 +139,8 @@ def update(self):
try:
status = self._get_status()
if self._name is None:
if status["name"] is not None:
self._name = status["name"]
if status['name'] is not None:
self._name = status['name']
state = STATES_MAP.get(status.get('door'), STATE_UNKNOWN)
if self._state_before_move is not None:
if self._state_before_move != state:
Expand All @@ -152,7 +153,7 @@ def update(self):
self.signal = status.get('rssi')
self.dist = status.get('dist')
self._available = True
except (requests.exceptions.RequestException) as ex:
except requests.exceptions.RequestException as ex:
_LOGGER.error("Unable to connect to OpenGarage device: %(reason)s",
dict(reason=ex))
self._state = STATE_OFFLINE
Expand All @@ -166,15 +167,15 @@ def _get_status(self):
def _push_button(self):
"""Send commands to API."""
url = '{}/cc?dkey={}&click=1'.format(
self.opengarage_url, self._devicekey)
self.opengarage_url, self._device_key)
try:
response = requests.get(url, timeout=10).json()
if response["result"] == 2:
_LOGGER.error("Unable to control %s: device_key is incorrect.",
if response['result'] == 2:
_LOGGER.error("Unable to control %s: Device key is incorrect",
self._name)
self._state = self._state_before_move
self._state_before_move = None
except (requests.exceptions.RequestException) as ex:
except requests.exceptions.RequestException as ex:
_LOGGER.error("Unable to connect to OpenGarage device: %(reason)s",
dict(reason=ex))
self._state = self._state_before_move
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/cover/tahoma.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up Tahoma covers."""
"""Set up the Tahoma covers."""
controller = hass.data[TAHOMA_DOMAIN]['controller']
devices = []
for device in hass.data[TAHOMA_DOMAIN]['devices']['cover']:
Expand Down
29 changes: 15 additions & 14 deletions homeassistant/components/ihc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
"""IHC component.
"""
Support for IHC devices.

For more details about this component, please refer to the documentation at
https://home-assistant.io/components/ihc/
"""
import logging
import os.path
import xml.etree.ElementTree

import voluptuous as vol

from homeassistant.components.ihc.const import (
ATTR_IHC_ID, ATTR_VALUE, CONF_INFO, CONF_AUTOSETUP,
CONF_BINARY_SENSOR, CONF_LIGHT, CONF_SENSOR, CONF_SWITCH,
CONF_XPATH, CONF_NODE, CONF_DIMMABLE, CONF_INVERTING,
SERVICE_SET_RUNTIME_VALUE_BOOL, SERVICE_SET_RUNTIME_VALUE_INT,
SERVICE_SET_RUNTIME_VALUE_FLOAT)
ATTR_IHC_ID, ATTR_VALUE, CONF_AUTOSETUP, CONF_BINARY_SENSOR, CONF_DIMMABLE,
CONF_INFO, CONF_INVERTING, CONF_LIGHT, CONF_NODE, CONF_SENSOR, CONF_SWITCH,
CONF_XPATH, SERVICE_SET_RUNTIME_VALUE_BOOL,
SERVICE_SET_RUNTIME_VALUE_FLOAT, SERVICE_SET_RUNTIME_VALUE_INT)
from homeassistant.config import load_yaml_config_file
from homeassistant.const import (
CONF_URL, CONF_USERNAME, CONF_PASSWORD, CONF_ID, CONF_NAME,
CONF_UNIT_OF_MEASUREMENT, CONF_TYPE, TEMP_CELSIUS)
CONF_ID, CONF_NAME, CONF_PASSWORD, CONF_TYPE, CONF_UNIT_OF_MEASUREMENT,
CONF_URL, CONF_USERNAME, TEMP_CELSIUS)
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import HomeAssistantType
Expand All @@ -36,7 +37,7 @@
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_AUTOSETUP, default=True): cv.boolean,
vol.Optional(CONF_INFO, default=True): cv.boolean
vol.Optional(CONF_INFO, default=True): cv.boolean,
}),
}, extra=vol.ALLOW_EXTRA)

Expand Down Expand Up @@ -97,7 +98,7 @@


def setup(hass, config):
"""Setup the IHC component."""
"""Set up the IHC component."""
from ihcsdk.ihccontroller import IHCController
conf = config[DOMAIN]
url = conf[CONF_URL]
Expand All @@ -106,7 +107,7 @@ def setup(hass, config):
ihc_controller = IHCController(url, username, password)

if not ihc_controller.authenticate():
_LOGGER.error("Unable to authenticate on ihc controller.")
_LOGGER.error("Unable to authenticate on IHC controller")
return False

if (conf[CONF_AUTOSETUP] and
Expand All @@ -125,7 +126,7 @@ def autosetup_ihc_products(hass: HomeAssistantType, config, ihc_controller):
"""Auto setup of IHC products from the ihc project file."""
project_xml = ihc_controller.get_project()
if not project_xml:
_LOGGER.error("Unable to read project from ihc controller.")
_LOGGER.error("Unable to read project from ICH controller")
return False
project = xml.etree.ElementTree.fromstring(project_xml)

Expand All @@ -150,7 +151,7 @@ def autosetup_ihc_products(hass: HomeAssistantType, config, ihc_controller):


def get_discovery_info(component_setup, groups):
"""Get discovery info for specified component."""
"""Get discovery info for specified IHC component."""
discovery_data = {}
for group in groups:
groupname = group.attrib['name']
Expand All @@ -173,7 +174,7 @@ def get_discovery_info(component_setup, groups):


def setup_service_functions(hass: HomeAssistantType, ihc_controller):
"""Setup the ihc service functions."""
"""Setup the IHC service functions."""
def set_runtime_value_bool(call):
"""Set a IHC runtime bool value service function."""
ihc_id = call.data[ATTR_IHC_ID]
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/ihc/ihcdevice.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Implements a base class for all IHC devices."""
"""Implementation of a base class for all IHC devices."""
import asyncio
from xml.etree.ElementTree import Element

from homeassistant.helpers.entity import Entity


class IHCDevice(Entity):
"""Base class for all ihc devices.
"""Base class for all IHC devices.

All IHC devices have an associated IHC resource. IHCDevice handled the
registration of the IHC controller callback when the IHC resource changes.
Expand All @@ -31,13 +31,13 @@ def __init__(self, ihc_controller, name, ihc_id: int, info: bool,

@asyncio.coroutine
def async_added_to_hass(self):
"""Add callback for ihc changes."""
"""Add callback for IHC changes."""
self.ihc_controller.add_notify_event(
self.ihc_id, self.on_ihc_change, True)

@property
def should_poll(self) -> bool:
"""No polling needed for ihc devices."""
"""No polling needed for IHC devices."""
return False

@property
Expand All @@ -58,7 +58,7 @@ def device_state_attributes(self):
}

def on_ihc_change(self, ihc_id, value):
"""Callback when ihc resource changes.
"""Callback when IHC resource changes.

Derived classes must overwrite this to do device specific stuff.
"""
Expand Down
38 changes: 18 additions & 20 deletions homeassistant/components/light/aurora.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
"""
Support for Nanoleaf Aurora platform.

Based in large parts upon Software-2's ha-aurora and fully
reliant on Software-2's nanoleaf-aurora Python Library, see
https://github.com/software-2/ha-aurora as well as
https://github.com/software-2/nanoleaf

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.nanoleaf_aurora/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still wrong.

"""
Expand All @@ -15,30 +10,34 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_HS_COLOR,
SUPPORT_EFFECT, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP,
SUPPORT_COLOR, PLATFORM_SCHEMA, Light)
from homeassistant.const import CONF_HOST, CONF_TOKEN, CONF_NAME
PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT, Light)
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_TOKEN
import homeassistant.helpers.config_validation as cv
from homeassistant.util import color as color_util
from homeassistant.util.color import \
color_temperature_mired_to_kelvin as mired_to_kelvin

REQUIREMENTS = ['nanoleaf==0.4.1']

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'Aurora'

ICON = 'mdi:triangle-outline'

SUPPORT_AURORA = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT |
SUPPORT_COLOR)

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_TOKEN): cv.string,
vol.Optional(CONF_NAME, default='Aurora'): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup Nanoleaf Aurora device."""
"""Set up the Nanoleaf Aurora device."""
import nanoleaf
host = config.get(CONF_HOST)
name = config.get(CONF_NAME)
Expand All @@ -47,16 +46,18 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
aurora_light.hass_name = name

if aurora_light.on is None:
_LOGGER.error("Could not connect to \
Nanoleaf Aurora: %s on %s", name, host)
_LOGGER.error(
"Could not connect to Nanoleaf Aurora: %s on %s", name, host)
return

add_devices([AuroraLight(aurora_light)], True)


class AuroraLight(Light):
"""Representation of a Nanoleaf Aurora."""

def __init__(self, light):
"""Initialize an Aurora."""
"""Initialize an Aurora light."""
self._brightness = None
self._color_temp = None
self._effect = None
Expand Down Expand Up @@ -99,7 +100,7 @@ def name(self):
@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
return "mdi:triangle-outline"
return ICON

@property
def is_on(self):
Expand Down Expand Up @@ -141,10 +142,7 @@ def turn_off(self, **kwargs):
self._light.on = False

def update(self):
"""Fetch new state data for this light.

This is the only method that should fetch new data for Home Assistant.
"""
"""Fetch new state data for this light."""
self._brightness = self._light.brightness
self._color_temp = self._light.color_temperature
self._effect = self._light.effect
Expand Down
Loading