Style 0.34 (#4689)
* Minor style updates * Minor style updates * Update validation and logger messages * Update ordering * Fix lint issue * Fix line too long * Update ordering * update logger messages
This commit is contained in:
parent
9a6c9cff30
commit
dddf4d1460
6 changed files with 92 additions and 101 deletions
|
@ -5,13 +5,14 @@ For more details about this platform, please refer to the documentation at
|
|||
https://home-assistant.io/components/camera.amcrest/
|
||||
"""
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.loader as loader
|
||||
from homeassistant.components.camera import (Camera, PLATFORM_SCHEMA)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_NAME, CONF_USERNAME, CONF_PASSWORD, CONF_PORT)
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
import homeassistant.loader as loader
|
||||
|
||||
REQUIREMENTS = ['amcrest==1.0.0']
|
||||
|
||||
|
@ -33,19 +34,18 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup an Amcrest IP Camera."""
|
||||
"""Set up an Amcrest IP Camera."""
|
||||
from amcrest import AmcrestCamera
|
||||
data = AmcrestCamera(config.get(CONF_HOST),
|
||||
config.get(CONF_PORT),
|
||||
config.get(CONF_USERNAME),
|
||||
config.get(CONF_PASSWORD))
|
||||
data = AmcrestCamera(
|
||||
config.get(CONF_HOST), config.get(CONF_PORT),
|
||||
config.get(CONF_USERNAME), config.get(CONF_PASSWORD))
|
||||
|
||||
persistent_notification = loader.get_component('persistent_notification')
|
||||
try:
|
||||
data.camera.current_time
|
||||
# pylint: disable=broad-except
|
||||
except Exception as ex:
|
||||
_LOGGER.error('Unable to connect to Amcrest camera: %s', str(ex))
|
||||
_LOGGER.error("Unable to connect to Amcrest camera: %s", str(ex))
|
||||
persistent_notification.create(
|
||||
hass, 'Error: {}<br />'
|
||||
'You will need to restart hass after fixing.'
|
||||
|
|
|
@ -4,25 +4,26 @@ Support for Nest Cameras.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/camera.nest/
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
import requests
|
||||
from homeassistant.components.camera import (PLATFORM_SCHEMA, Camera)
|
||||
|
||||
import homeassistant.components.nest as nest
|
||||
from homeassistant.components.camera import (PLATFORM_SCHEMA, Camera)
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['nest']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
NEST_BRAND = 'Nest'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({})
|
||||
|
||||
NEST_BRAND = "Nest"
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup a Nest Cam."""
|
||||
"""Set up a Nest Cam."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
camera_devices = hass.data[nest.DATA_NEST].camera_devices()
|
||||
|
@ -39,14 +40,12 @@ class NestCamera(Camera):
|
|||
super(NestCamera, self).__init__()
|
||||
self.structure = structure
|
||||
self.device = device
|
||||
|
||||
# data attributes
|
||||
self._location = None
|
||||
self._name = None
|
||||
self._is_online = None
|
||||
self._is_streaming = None
|
||||
self._is_video_history_enabled = False
|
||||
# default to non-NestAware subscribed, but will be fixed during update
|
||||
# Default to non-NestAware subscribed, but will be fixed during update
|
||||
self._time_between_snapshots = timedelta(seconds=30)
|
||||
self._last_image = None
|
||||
self._next_snapshot_at = None
|
||||
|
@ -68,10 +67,10 @@ class NestCamera(Camera):
|
|||
|
||||
@property
|
||||
def brand(self):
|
||||
"""Camera Brand."""
|
||||
"""Return the brand of the camera."""
|
||||
return NEST_BRAND
|
||||
|
||||
# this doesn't seem to be getting called regularly, for some reason
|
||||
# This doesn't seem to be getting called regularly, for some reason
|
||||
def update(self):
|
||||
"""Cache value from Python-nest."""
|
||||
self._location = self.device.where
|
||||
|
@ -84,7 +83,7 @@ class NestCamera(Camera):
|
|||
# NestAware allowed 10/min
|
||||
self._time_between_snapshots = timedelta(seconds=6)
|
||||
else:
|
||||
# otherwise, 2/min
|
||||
# Otherwise, 2/min
|
||||
self._time_between_snapshots = timedelta(seconds=30)
|
||||
|
||||
def _ready_for_snapshot(self, now):
|
||||
|
@ -100,7 +99,7 @@ class NestCamera(Camera):
|
|||
try:
|
||||
response = requests.get(url)
|
||||
except requests.exceptions.RequestException as error:
|
||||
_LOGGER.error('Error getting camera image: %s', error)
|
||||
_LOGGER.error("Error getting camera image: %s", error)
|
||||
return None
|
||||
|
||||
self._next_snapshot_at = now + self._time_between_snapshots
|
||||
|
|
|
@ -2,23 +2,23 @@
|
|||
DuneHD implementation of the media player.
|
||||
|
||||
For more details about this platform, please refer to the documentation
|
||||
https://home-assistant.io/components/dunehd/
|
||||
https://home-assistant.io/components/media_player.dunehd/
|
||||
"""
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.media_player import (
|
||||
SUPPORT_PAUSE, SUPPORT_TURN_OFF, SUPPORT_TURN_ON,
|
||||
SUPPORT_NEXT_TRACK, SUPPORT_PREVIOUS_TRACK,
|
||||
SUPPORT_SELECT_SOURCE, PLATFORM_SCHEMA, MediaPlayerDevice)
|
||||
SUPPORT_PAUSE, SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_NEXT_TRACK,
|
||||
SUPPORT_PREVIOUS_TRACK, SUPPORT_SELECT_SOURCE, PLATFORM_SCHEMA,
|
||||
MediaPlayerDevice)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_NAME, STATE_OFF, STATE_PAUSED, STATE_ON, STATE_PLAYING)
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
|
||||
REQUIREMENTS = ['pdunehd==1.3']
|
||||
|
||||
DEFAULT_NAME = "DuneHD"
|
||||
DEFAULT_NAME = 'DuneHD'
|
||||
|
||||
CONF_SOURCES = "sources"
|
||||
CONF_SOURCES = 'sources'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
|
@ -33,7 +33,7 @@ DUNEHD_PLAYER_SUPPORT = \
|
|||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the media player demo platform."""
|
||||
"""Set up the media player demo platform."""
|
||||
sources = config.get(CONF_SOURCES, {})
|
||||
|
||||
from pdunehd import DuneHDPlayer
|
||||
|
|
|
@ -9,6 +9,7 @@ import logging
|
|||
import os
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
|
@ -18,22 +19,25 @@ from homeassistant.const import (
|
|||
from homeassistant.components import group
|
||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||
|
||||
ATTR_DEVICE = 'device'
|
||||
ATTR_COMMAND = 'command'
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_ACTIVITY = 'activity'
|
||||
SERVICE_SEND_COMMAND = 'send_command'
|
||||
SERVICE_SYNC = 'sync'
|
||||
ATTR_COMMAND = 'command'
|
||||
ATTR_DEVICE = 'device'
|
||||
|
||||
DOMAIN = 'remote'
|
||||
SCAN_INTERVAL = 30
|
||||
|
||||
GROUP_NAME_ALL_REMOTES = 'all remotes'
|
||||
ENTITY_ID_ALL_REMOTES = group.ENTITY_ID_FORMAT.format('all_remotes')
|
||||
|
||||
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
||||
|
||||
GROUP_NAME_ALL_REMOTES = 'all remotes'
|
||||
|
||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||
|
||||
SCAN_INTERVAL = 30
|
||||
SERVICE_SEND_COMMAND = 'send_command'
|
||||
SERVICE_SYNC = 'sync'
|
||||
|
||||
REMOTE_SERVICE_SCHEMA = vol.Schema({
|
||||
vol.Required(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
})
|
||||
|
@ -47,8 +51,6 @@ REMOTE_SERVICE_SEND_COMMAND_SCHEMA = REMOTE_SERVICE_SCHEMA.extend({
|
|||
vol.Required(ATTR_COMMAND): cv.string,
|
||||
})
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def is_on(hass, entity_id=None):
|
||||
"""Return if the remote is on based on the statemachine."""
|
||||
|
|
|
@ -3,35 +3,38 @@ Support for Harmony Hub devices.
|
|||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/remote.harmony/
|
||||
|
||||
"""
|
||||
|
||||
import logging
|
||||
from os import path
|
||||
import urllib.parse
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.components.remote as remote
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import (
|
||||
CONF_NAME, CONF_HOST, CONF_PORT, ATTR_ENTITY_ID)
|
||||
from homeassistant.components.remote import PLATFORM_SCHEMA, DOMAIN
|
||||
from homeassistant.util import slugify
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
import homeassistant.components.remote as remote
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
|
||||
|
||||
REQUIREMENTS = ['pyharmony==1.0.12']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_DEVICE = 'device'
|
||||
ATTR_COMMAND = 'command'
|
||||
ATTR_ACTIVITY = 'activity'
|
||||
|
||||
DEFAULT_PORT = 5222
|
||||
DEVICES = []
|
||||
|
||||
SERVICE_SYNC = 'harmony_sync'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_NAME): cv.string,
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_PORT): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||
vol.Required(ATTR_ACTIVITY, default=None): cv.string,
|
||||
})
|
||||
|
||||
|
@ -39,37 +42,32 @@ HARMONY_SYNC_SCHEMA = vol.Schema({
|
|||
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
})
|
||||
|
||||
# List of devices that have been registered
|
||||
DEVICES = []
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup Harmony platform."""
|
||||
"""Set up the Harmony platform."""
|
||||
import pyharmony
|
||||
global DEVICES
|
||||
|
||||
name = config.get(CONF_NAME)
|
||||
host = config.get(CONF_HOST)
|
||||
port = config.get(CONF_PORT)
|
||||
_LOGGER.info('Loading Harmony platform: ' + name)
|
||||
_LOGGER.debug("Loading Harmony platform: %s", name)
|
||||
|
||||
harmony_conf_file = hass.config.path('harmony_' + slugify(name) + '.conf')
|
||||
harmony_conf_file = hass.config.path(
|
||||
'{}{}{}'.format('harmony_', slugify(name), '.conf'))
|
||||
|
||||
try:
|
||||
_LOGGER.debug('calling pyharmony.ha_get_token for remote at: ' +
|
||||
host + ':' + port)
|
||||
_LOGGER.debug("Calling pyharmony.ha_get_token for remote at: %s:%s",
|
||||
host, port)
|
||||
token = urllib.parse.quote_plus(pyharmony.ha_get_token(host, port))
|
||||
except ValueError as err:
|
||||
_LOGGER.critical(err.args[0] + ' for remote: ' + name)
|
||||
_LOGGER.warning("%s for remote: %s", err.args[0], name)
|
||||
return False
|
||||
|
||||
_LOGGER.debug('received token: ' + token)
|
||||
DEVICES = [HarmonyRemote(config.get(CONF_NAME),
|
||||
config.get(CONF_HOST),
|
||||
config.get(CONF_PORT),
|
||||
config.get(ATTR_ACTIVITY),
|
||||
harmony_conf_file,
|
||||
token)]
|
||||
_LOGGER.debug("Received token: %s", token)
|
||||
DEVICES = [HarmonyRemote(
|
||||
config.get(CONF_NAME), config.get(CONF_HOST), config.get(CONF_PORT),
|
||||
config.get(ATTR_ACTIVITY), harmony_conf_file, token)]
|
||||
add_devices(DEVICES, True)
|
||||
register_services(hass)
|
||||
return True
|
||||
|
@ -80,9 +78,8 @@ def register_services(hass):
|
|||
descriptions = load_yaml_config_file(
|
||||
path.join(path.dirname(__file__), 'services.yaml'))
|
||||
|
||||
hass.services.register(DOMAIN, SERVICE_SYNC,
|
||||
_sync_service,
|
||||
descriptions.get(SERVICE_SYNC),
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_SYNC, _sync_service, descriptions.get(SERVICE_SYNC),
|
||||
schema=HARMONY_SYNC_SCHEMA)
|
||||
|
||||
|
||||
|
@ -113,7 +110,7 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
import pyharmony
|
||||
from pathlib import Path
|
||||
|
||||
_LOGGER.debug('HarmonyRemote device init started for: ' + name)
|
||||
_LOGGER.debug("HarmonyRemote device init started for: %s", name)
|
||||
self._name = name
|
||||
self._ip = host
|
||||
self._port = port
|
||||
|
@ -122,10 +119,11 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
self._default_activity = activity
|
||||
self._token = token
|
||||
self._config_path = out_path
|
||||
_LOGGER.debug('retrieving harmony config using token: ' + token)
|
||||
_LOGGER.debug("Retrieving harmony config using token: %s", token)
|
||||
self._config = pyharmony.ha_get_config(self._token, host, port)
|
||||
if not Path(self._config_path).is_file():
|
||||
_LOGGER.debug('writing harmony configuration to file: ' + out_path)
|
||||
_LOGGER.debug("Writing harmony configuration to file: %s",
|
||||
out_path)
|
||||
pyharmony.ha_write_config_file(self._config, self._config_path)
|
||||
|
||||
@property
|
||||
|
@ -147,12 +145,10 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
"""Return current activity."""
|
||||
import pyharmony
|
||||
name = self._name
|
||||
_LOGGER.debug('polling ' + name + ' for current activity')
|
||||
state = pyharmony.ha_get_current_activity(self._token,
|
||||
self._config,
|
||||
self._ip,
|
||||
self._port)
|
||||
_LOGGER.debug(name + '\'s current activity reported as: ' + state)
|
||||
_LOGGER.debug("Polling %s for current activity", name)
|
||||
state = pyharmony.ha_get_current_activity(
|
||||
self._token, self._config, self._ip, self._port)
|
||||
_LOGGER.debug("%s current activity reported as: %s", name, state)
|
||||
self._current_activity = state
|
||||
self._state = bool(state != 'PowerOff')
|
||||
|
||||
|
@ -165,14 +161,11 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
activity = self._default_activity
|
||||
|
||||
if activity:
|
||||
pyharmony.ha_start_activity(self._token,
|
||||
self._ip,
|
||||
self._port,
|
||||
self._config,
|
||||
activity)
|
||||
pyharmony.ha_start_activity(
|
||||
self._token, self._ip, self._port, self._config, activity)
|
||||
self._state = True
|
||||
else:
|
||||
_LOGGER.error('No activity specified with turn_on service')
|
||||
_LOGGER.error("No activity specified with turn_on service")
|
||||
|
||||
def turn_off(self):
|
||||
"""Start the PowerOff activity."""
|
||||
|
@ -182,17 +175,16 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
def send_command(self, **kwargs):
|
||||
"""Send a command to one device."""
|
||||
import pyharmony
|
||||
pyharmony.ha_send_command(self._token, self._ip,
|
||||
self._port, kwargs[ATTR_DEVICE],
|
||||
pyharmony.ha_send_command(
|
||||
self._token, self._ip, self._port, kwargs[ATTR_DEVICE],
|
||||
kwargs[ATTR_COMMAND])
|
||||
|
||||
def sync(self):
|
||||
"""Sync the Harmony device with the web service."""
|
||||
import pyharmony
|
||||
_LOGGER.debug('syncing hub with Harmony servers')
|
||||
_LOGGER.debug("Syncing hub with Harmony servers")
|
||||
pyharmony.ha_sync(self._token, self._ip, self._port)
|
||||
self._config = pyharmony.ha_get_config(self._token,
|
||||
self._ip,
|
||||
self._port)
|
||||
_LOGGER.debug('writing hub config to file: ' + self._config_path)
|
||||
self._config = pyharmony.ha_get_config(
|
||||
self._token, self._ip, self._port)
|
||||
_LOGGER.debug("Writing hub config to file: %s", self._config_path)
|
||||
pyharmony.ha_write_config_file(self._config, self._config_path)
|
||||
|
|
|
@ -9,10 +9,9 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, ATTR_BATTERY_LEVEL, \
|
||||
CONF_EMAIL, CONF_PASSWORD, \
|
||||
EVENT_HOMEASSISTANT_START, \
|
||||
EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.const import (
|
||||
CONF_ACCESS_TOKEN, ATTR_BATTERY_LEVEL, CONF_EMAIL, CONF_PASSWORD,
|
||||
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
|
@ -56,7 +55,7 @@ WINK_COMPONENTS = [
|
|||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Setup the Wink component."""
|
||||
"""Set up the Wink component."""
|
||||
import pywink
|
||||
from pubnubsubhandler import PubNubSubscriptionHandler
|
||||
|
||||
|
@ -95,7 +94,7 @@ def setup(hass, config):
|
|||
|
||||
def force_update(call):
|
||||
"""Force all devices to poll the Wink API."""
|
||||
_LOGGER.info("Refreshing Wink states from API.")
|
||||
_LOGGER.info("Refreshing Wink states from API")
|
||||
for entity in hass.data[DOMAIN]['entities']:
|
||||
entity.update_ha_state(True)
|
||||
hass.services.register(DOMAIN, 'Refresh state from Wink', force_update)
|
||||
|
@ -115,22 +114,21 @@ class WinkDevice(Entity):
|
|||
self.wink = wink
|
||||
self._battery = self.wink.battery_level
|
||||
hass.data[DOMAIN]['pubnub'].add_subscription(
|
||||
self.wink.pubnub_channel,
|
||||
self._pubnub_update)
|
||||
self.wink.pubnub_channel, self._pubnub_update)
|
||||
hass.data[DOMAIN]['entities'].append(self)
|
||||
|
||||
def _pubnub_update(self, message):
|
||||
try:
|
||||
if message is None:
|
||||
_LOGGER.error("Error on pubnub update for " + self.name +
|
||||
" pollin API for current state")
|
||||
_LOGGER.error("Error on pubnub update for %s "
|
||||
"polling API for current state", self.name)
|
||||
self.update_ha_state(True)
|
||||
else:
|
||||
self.wink.pubnub_update(message)
|
||||
self.update_ha_state()
|
||||
except (ValueError, KeyError, AttributeError):
|
||||
_LOGGER.error("Error in pubnub JSON for " + self.name +
|
||||
" pollin API for current state")
|
||||
_LOGGER.error("Error in pubnub JSON for %s "
|
||||
"polling API for current state", self.name)
|
||||
self.update_ha_state(True)
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue