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
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the blink binary sensors."""
"""Set up the blink binary sensors."""
if discovery_info is None:
return

Expand Down
32 changes: 11 additions & 21 deletions homeassistant/components/binary_sensor/workday.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
"""Sensor to indicate whether the current day is a workday."""
"""
Sensor to indicate whether the current day is a workday.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.workday/
"""
import asyncio
import logging
import datetime

import voluptuous as vol

from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (STATE_ON, STATE_OFF, STATE_UNKNOWN,
CONF_NAME, WEEKDAYS)
from homeassistant.const import (
STATE_ON, STATE_OFF, STATE_UNKNOWN, CONF_NAME, WEEKDAYS)
import homeassistant.util.dt as dt_util
from homeassistant.helpers.entity import Entity
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -48,29 +53,18 @@


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Workday sensor."""
"""Set up the Workday sensor."""
import holidays

# Get the Sensor name from the config
sensor_name = config.get(CONF_NAME)

# Get the country code from the config
country = config.get(CONF_COUNTRY)

# Get the province from the config
province = config.get(CONF_PROVINCE)

# Get the list of workdays from the config
workdays = config.get(CONF_WORKDAYS)

# Get the list of excludes from the config
excludes = config.get(CONF_EXCLUDES)

# Instantiate the holidays module for the current year
year = datetime.datetime.now().year
obj_holidays = getattr(holidays, country)(years=year)

# Also apply the provience, if available for the configured country
if province:
if province not in obj_holidays.PROVINCES:
_LOGGER.error('There is no province/state %s in country %s',
Expand All @@ -81,14 +75,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
obj_holidays = getattr(holidays, country)(prov=province,
years=year)

# Output found public holidays via the debug channel
_LOGGER.debug("Found the following holidays for your configuration:")
for date, name in sorted(obj_holidays.items()):
_LOGGER.debug("%s %s", date, name)

# Add ourselves as device
add_devices([IsWorkdaySensor(obj_holidays, workdays,
excludes, sensor_name)], True)
add_devices([IsWorkdaySensor(
obj_holidays, workdays, excludes, sensor_name)], True)


def day_to_string(day):
Expand Down Expand Up @@ -122,7 +114,6 @@ def state(self):

def is_include(self, day, now):
"""Check if given day is in the includes list."""
# Check includes
if day in self._workdays:
return True
elif 'holiday' in self._workdays and now in self._obj_holidays:
Expand All @@ -132,7 +123,6 @@ def is_include(self, day, now):

def is_exclude(self, day, now):
"""Check if given day is in the excludes list."""
# Check excludes
if day in self._excludes:
return True
elif 'holiday' in self._excludes and now in self._obj_holidays:
Expand Down
26 changes: 14 additions & 12 deletions homeassistant/components/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
https://home-assistant.io/components/blink/
"""
import logging

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.const import (CONF_USERNAME,
CONF_PASSWORD,
ATTR_FRIENDLY_NAME,
ATTR_ARMED)
from homeassistant.const import (
CONF_USERNAME, CONF_PASSWORD, ATTR_FRIENDLY_NAME, ATTR_ARMED)
from homeassistant.helpers import discovery

REQUIREMENTS = ['blinkpy==0.5.2']

_LOGGER = logging.getLogger(__name__)

DOMAIN = 'blink'
REQUIREMENTS = ['blinkpy==0.5.2']

CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
Expand Down Expand Up @@ -50,7 +52,7 @@ def __init__(self, config_info):


def setup(hass, config):
"""Setup Blink System."""
"""Set up Blink System."""
hass.data[DOMAIN] = BlinkSystem(config)
discovery.load_platform(hass, 'camera', DOMAIN, {}, config)
discovery.load_platform(hass, 'sensor', DOMAIN, {}, config)
Expand All @@ -77,11 +79,11 @@ def arm_system(call):
hass.data[DOMAIN].blink.arm = value
hass.data[DOMAIN].blink.refresh()

hass.services.register(DOMAIN, 'snap_picture', snap_picture,
schema=SNAP_PICTURE_SCHEMA)
hass.services.register(DOMAIN, 'arm_camera', arm_camera,
schema=ARM_CAMERA_SCHEMA)
hass.services.register(DOMAIN, 'arm_system', arm_system,
schema=ARM_SYSTEM_SCHEMA)
hass.services.register(
DOMAIN, 'snap_picture', snap_picture, schema=SNAP_PICTURE_SCHEMA)
hass.services.register(
DOMAIN, 'arm_camera', arm_camera, schema=ARM_CAMERA_SCHEMA)
hass.services.register(
DOMAIN, 'arm_system', arm_system, schema=ARM_SYSTEM_SCHEMA)

return True
104 changes: 50 additions & 54 deletions homeassistant/components/climate/tado.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
"""tado component to create a climate device for each zone."""
"""
Tado component to create a climate device for each zone.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/climate.tado/
"""
import logging

from homeassistant.const import TEMP_CELSIUS
from homeassistant.components.climate import ClimateDevice
from homeassistant.const import ATTR_TEMPERATURE
from homeassistant.components.tado import DATA_TADO

from homeassistant.components.climate import (
ClimateDevice)
from homeassistant.const import (
ATTR_TEMPERATURE)
from homeassistant.components.tado import (
DATA_TADO)
_LOGGER = logging.getLogger(__name__)

CONST_MODE_SMART_SCHEDULE = "SMART_SCHEDULE" # Default mytado mode
CONST_MODE_OFF = "OFF" # Switch off heating in a zone
CONST_MODE_SMART_SCHEDULE = 'SMART_SCHEDULE' # Default mytado mode
CONST_MODE_OFF = 'OFF' # Switch off heating in a zone

# When we change the temperature setting, we need an overlay mode
# wait until tado changes the mode automatic
CONST_OVERLAY_TADO_MODE = "TADO_MODE"
CONST_OVERLAY_TADO_MODE = 'TADO_MODE'
# the user has change the temperature or mode manually
CONST_OVERLAY_MANUAL = "MANUAL"
CONST_OVERLAY_MANUAL = 'MANUAL'
# the temperature will be reset after a timespan
CONST_OVERLAY_TIMER = "TIMER"
CONST_OVERLAY_TIMER = 'TIMER'

OPERATION_LIST = {
CONST_OVERLAY_MANUAL: "Manual",
CONST_OVERLAY_TIMER: "Timer",
CONST_OVERLAY_TADO_MODE: "Tado mode",
CONST_MODE_SMART_SCHEDULE: "Smart schedule",
CONST_MODE_OFF: "Off"}

_LOGGER = logging.getLogger(__name__)
CONST_OVERLAY_MANUAL: 'Manual',
CONST_OVERLAY_TIMER: 'Timer',
CONST_OVERLAY_TADO_MODE: 'Tado mode',
CONST_MODE_SMART_SCHEDULE: 'Smart schedule',
CONST_MODE_OFF: 'Off',
}


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the climate platform."""
# get the PyTado object from the hub component
"""Set up the Tado climate platform."""
tado = hass.data[DATA_TADO]

try:
Expand All @@ -45,10 +45,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):

climate_devices = []
for zone in zones:
climate_devices.append(create_climate_device(tado, hass,
zone,
zone['name'],
zone['id']))
climate_devices.append(create_climate_device(
tado, hass, zone, zone['name'], zone['id']))

if len(climate_devices) > 0:
add_devices(climate_devices, True)
Expand All @@ -58,13 +56,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):


def create_climate_device(tado, hass, zone, name, zone_id):
"""Create a climate device."""
"""Create a Tado climate device."""
capabilities = tado.get_capabilities(zone_id)

unit = TEMP_CELSIUS
min_temp = float(capabilities["temperatures"]["celsius"]["min"])
max_temp = float(capabilities["temperatures"]["celsius"]["max"])
ac_mode = capabilities["type"] != "HEATING"
min_temp = float(capabilities['temperatures']['celsius']['min'])
max_temp = float(capabilities['temperatures']['celsius']['max'])
ac_mode = capabilities['type'] != 'HEATING'

data_id = 'zone {} {}'.format(name, zone_id)
device = TadoClimate(tado,
Expand All @@ -74,10 +72,10 @@ def create_climate_device(tado, hass, zone, name, zone_id):
ac_mode)

tado.add_sensor(data_id, {
"id": zone_id,
"zone": zone,
"name": name,
"climate": device
'id': zone_id,
'zone': zone,
'name': name,
'climate': device
})

return device
Expand All @@ -89,7 +87,7 @@ class TadoClimate(ClimateDevice):
def __init__(self, store, zone_name, zone_id, data_id,
min_temp, max_temp, ac_mode,
tolerance=0.3):
"""Initialization of TadoClimate device."""
"""Initialization of Tado climate device."""
self._store = store
self._data_id = data_id

Expand Down Expand Up @@ -202,8 +200,7 @@ def update(self):
data = self._store.get_data(self._data_id)

if data is None:
_LOGGER.debug('Recieved no data for zone %s',
self.zone_name)
_LOGGER.debug("Recieved no data for zone %s", self.zone_name)
return

if 'sensorDataPoints' in data:
Expand Down Expand Up @@ -232,11 +229,11 @@ def update(self):

if 'tadoMode' in data:
mode = data['tadoMode']
self._is_away = mode == "AWAY"
self._is_away = mode == 'AWAY'

if 'setting' in data:
power = data['setting']['power']
if power == "OFF":
if power == 'OFF':
self._current_operation = CONST_MODE_OFF
self._device_is_active = False
else:
Expand All @@ -249,48 +246,47 @@ def update(self):
overlay = False
termination = ""

# if you set mode manualy to off, there will be an overlay
# and a termination, but we want to see the mode "OFF"
# If you set mode manualy to off, there will be an overlay
# and a termination, but we want to see the mode "OFF"

if overlay and self._device_is_active:
# there is an overlay the device is on
# There is an overlay the device is on
self._overlay_mode = termination
self._current_operation = termination
else:
# there is no overlay, the mode will always be
# "SMART_SCHEDULE"
# There is no overlay, the mode will always be
# "SMART_SCHEDULE"
self._overlay_mode = CONST_MODE_SMART_SCHEDULE
self._current_operation = CONST_MODE_SMART_SCHEDULE

def _control_heating(self):
"""Send new target temperature to mytado."""
if not self._active and None not in (self._cur_temp,
self._target_temp):
if not self._active and None not in (
self._cur_temp, self._target_temp):
self._active = True
_LOGGER.info('Obtained current and target temperature. '
'tado thermostat active.')
_LOGGER.info("Obtained current and target temperature. "
"Tado thermostat active")

if not self._active or self._current_operation == self._overlay_mode:
return

if self._current_operation == CONST_MODE_SMART_SCHEDULE:
_LOGGER.info('Switching mytado.com to SCHEDULE (default) '
'for zone %s', self.zone_name)
_LOGGER.info("Switching mytado.com to SCHEDULE (default) "
"for zone %s", self.zone_name)
self._store.reset_zone_overlay(self.zone_id)
self._overlay_mode = self._current_operation
return

if self._current_operation == CONST_MODE_OFF:
_LOGGER.info('Switching mytado.com to OFF for zone %s',
_LOGGER.info("Switching mytado.com to OFF for zone %s",
self.zone_name)
self._store.set_zone_overlay(self.zone_id, CONST_OVERLAY_MANUAL)
self._overlay_mode = self._current_operation
return

_LOGGER.info('Switching mytado.com to %s mode for zone %s',
_LOGGER.info("Switching mytado.com to %s mode for zone %s",
self._current_operation, self.zone_name)
self._store.set_zone_overlay(self.zone_id,
self._current_operation,
self._target_temp)
self._store.set_zone_overlay(
self.zone_id, self._current_operation, self._target_temp)

self._overlay_mode = self._current_operation
10 changes: 3 additions & 7 deletions homeassistant/components/light/piglow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@

import voluptuous as vol

# Import the device class from the component that you want to support
import homeassistant.helpers.config_validation as cv
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS,
ATTR_RGB_COLOR, SUPPORT_RGB_COLOR,
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, ATTR_RGB_COLOR, SUPPORT_RGB_COLOR,
Light, PLATFORM_SCHEMA)
from homeassistant.const import CONF_NAME
import homeassistant.helpers.config_validation as cv

# Home Assistant depends on 3rd party packages for API specific code.
REQUIREMENTS = ['piglow==1.2.4']

_LOGGER = logging.getLogger(__name__)
Expand All @@ -32,7 +29,7 @@


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Piglow Light platform."""
"""Set up the Piglow Light platform."""
import piglow

if subprocess.getoutput("i2cdetect -q -y 1 | grep -o 54") != '54':
Expand All @@ -41,7 +38,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):

name = config.get(CONF_NAME)

# Add devices
add_devices([PiglowLight(piglow, name)])


Expand Down
Loading