Fix some warnings found by quantifiedcode (#8027)
* Cleanup of warnings by quantifiedcode * Fix lint * Fix test * Delete insteon_hub component * Also update .coveragerc
This commit is contained in:
parent
afb9cba806
commit
1fde234c78
7 changed files with 20 additions and 159 deletions
|
@ -50,9 +50,6 @@ omit =
|
|||
homeassistant/components/google.py
|
||||
homeassistant/components/*/google.py
|
||||
|
||||
homeassistant/components/insteon_hub.py
|
||||
homeassistant/components/*/insteon_hub.py
|
||||
|
||||
homeassistant/components/insteon_local.py
|
||||
homeassistant/components/*/insteon_local.py
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ def setup_platform(hass, config, add_devices, disc_info=None):
|
|||
if disc_info is None:
|
||||
return
|
||||
|
||||
if not any([data[CONF_TRACK] for data in disc_info[CONF_ENTITIES]]):
|
||||
if not any(data[CONF_TRACK] for data in disc_info[CONF_ENTITIES]):
|
||||
return
|
||||
|
||||
calendar_service = GoogleCalendarService(hass.config.path(TOKEN_FILE))
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
"""
|
||||
Support for Insteon Hub.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/insteon_hub/
|
||||
"""
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (CONF_API_KEY, CONF_PASSWORD, CONF_USERNAME)
|
||||
from homeassistant.helpers import discovery
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['insteon_hub==0.4.5']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = 'insteon_hub'
|
||||
INSTEON = None
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Insteon Hub component.
|
||||
|
||||
This will automatically import associated lights.
|
||||
"""
|
||||
_LOGGER.warning("Component disabled at request from Insteon. "
|
||||
"For more information: https://goo.gl/zLJaic")
|
||||
return False
|
||||
# pylint: disable=unreachable
|
||||
import insteon
|
||||
|
||||
username = config[DOMAIN][CONF_USERNAME]
|
||||
password = config[DOMAIN][CONF_PASSWORD]
|
||||
api_key = config[DOMAIN][CONF_API_KEY]
|
||||
|
||||
global INSTEON
|
||||
INSTEON = insteon.Insteon(username, password, api_key)
|
||||
|
||||
if INSTEON is None:
|
||||
_LOGGER.error("Could not connect to Insteon service")
|
||||
return False
|
||||
|
||||
discovery.load_platform(hass, 'light', DOMAIN, {}, config)
|
||||
|
||||
return True
|
|
@ -1,79 +0,0 @@
|
|||
"""
|
||||
Support for Insteon Hub lights.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/insteon_hub/
|
||||
"""
|
||||
from homeassistant.components.insteon_hub import INSTEON
|
||||
from homeassistant.components.light import (ATTR_BRIGHTNESS,
|
||||
SUPPORT_BRIGHTNESS, Light)
|
||||
|
||||
DEPENDENCIES = ['insteon_hub']
|
||||
|
||||
SUPPORT_INSTEON_HUB = SUPPORT_BRIGHTNESS
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the Insteon Hub light platform."""
|
||||
devs = []
|
||||
for device in INSTEON.devices:
|
||||
if device.DeviceCategory == "Switched Lighting Control":
|
||||
devs.append(InsteonToggleDevice(device))
|
||||
if device.DeviceCategory == "Dimmable Lighting Control":
|
||||
devs.append(InsteonToggleDevice(device))
|
||||
add_devices(devs)
|
||||
|
||||
|
||||
class InsteonToggleDevice(Light):
|
||||
"""An abstract Class for an Insteon node."""
|
||||
|
||||
def __init__(self, node):
|
||||
"""Initialize the device."""
|
||||
self.node = node
|
||||
self._value = 0
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the the name of the node."""
|
||||
return self.node.DeviceName
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the ID of this insteon node."""
|
||||
return self.node.DeviceID
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return self._value / 100 * 255
|
||||
|
||||
def update(self):
|
||||
"""Update state of the sensor."""
|
||||
resp = self.node.send_command('get_status', wait=True)
|
||||
try:
|
||||
self._value = resp['response']['level']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return the boolean response if the node is on."""
|
||||
return self._value != 0
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_INSTEON_HUB
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn device on."""
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
self._value = kwargs[ATTR_BRIGHTNESS] / 255 * 100
|
||||
self.node.send_command('on', self._value)
|
||||
else:
|
||||
self._value = 100
|
||||
self.node.send_command('on')
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn device off."""
|
||||
self.node.send_command('off')
|
|
@ -126,7 +126,7 @@ class TelldusLiveClient(object):
|
|||
discovery.load_platform(
|
||||
self._hass, component, DOMAIN, [device_id], self._config)
|
||||
|
||||
known_ids = set([entity.device_id for entity in self.entities])
|
||||
known_ids = {entity.device_id for entity in self.entities}
|
||||
for device in self._client.devices:
|
||||
if device.device_id in known_ids:
|
||||
continue
|
||||
|
|
|
@ -319,9 +319,6 @@ https://github.com/wokar/pylgnetcast/archive/v0.2.0.zip#pylgnetcast==0.2.0
|
|||
# homeassistant.components.sensor.influxdb
|
||||
influxdb==3.0.0
|
||||
|
||||
# homeassistant.components.insteon_hub
|
||||
insteon_hub==0.4.5
|
||||
|
||||
# homeassistant.components.insteon_local
|
||||
insteonlocal==0.52
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
from collections import defaultdict
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from tests.common import (assert_setup_component, fire_mqtt_message,
|
||||
|
@ -187,9 +187,9 @@ REGION_LEAVE_ZERO_MESSAGE = {
|
|||
BAD_JSON_PREFIX = '--$this is bad json#--'
|
||||
BAD_JSON_SUFFIX = '** and it ends here ^^'
|
||||
|
||||
SECRET_KEY = 's3cretkey'
|
||||
TEST_SECRET_KEY = 's3cretkey'
|
||||
ENCRYPTED_LOCATION_MESSAGE = {
|
||||
# Encrypted version of LOCATION_MESSAGE using libsodium and SECRET_KEY
|
||||
# Encrypted version of LOCATION_MESSAGE using libsodium and TEST_SECRET_KEY
|
||||
'_type': 'encrypted',
|
||||
'data': ('qm1A83I6TVFRmH5343xy+cbex8jBBxDFkHRuJhELVKVRA/DgXcyKtghw'
|
||||
'9pOw75Lo4gHcyy2wV5CmkjrpKEBR7Qhye4AR0y7hOvlx6U/a3GuY1+W8'
|
||||
|
@ -685,6 +685,18 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
|||
self.assertTrue(wayp == new_wayp)
|
||||
|
||||
|
||||
def mock_cipher():
|
||||
"""Return a dummy pickle-based cipher."""
|
||||
def mock_decrypt(ciphertext, key):
|
||||
"""Decrypt/unpickle."""
|
||||
import pickle
|
||||
(mkey, plaintext) = pickle.loads(ciphertext)
|
||||
if key != mkey:
|
||||
raise ValueError()
|
||||
return plaintext
|
||||
return (len(TEST_SECRET_KEY), mock_decrypt)
|
||||
|
||||
|
||||
class TestDeviceTrackerOwnTrackConfigs(BaseMQTT):
|
||||
"""Test the OwnTrack sensor."""
|
||||
|
||||
|
@ -699,17 +711,6 @@ class TestDeviceTrackerOwnTrackConfigs(BaseMQTT):
|
|||
"""Tear down resources."""
|
||||
self.hass.stop()
|
||||
|
||||
def mock_cipher(): # pylint: disable=no-method-argument
|
||||
"""Return a dummy pickle-based cipher."""
|
||||
def mock_decrypt(ciphertext, key):
|
||||
"""Decrypt/unpickle."""
|
||||
import pickle
|
||||
(mkey, plaintext) = pickle.loads(ciphertext)
|
||||
if key != mkey:
|
||||
raise ValueError()
|
||||
return plaintext
|
||||
return (len(SECRET_KEY), mock_decrypt)
|
||||
|
||||
@patch('homeassistant.components.device_tracker.owntracks.get_cipher',
|
||||
mock_cipher)
|
||||
def test_encrypted_payload(self):
|
||||
|
@ -718,7 +719,7 @@ class TestDeviceTrackerOwnTrackConfigs(BaseMQTT):
|
|||
assert setup_component(self.hass, device_tracker.DOMAIN, {
|
||||
device_tracker.DOMAIN: {
|
||||
CONF_PLATFORM: 'owntracks',
|
||||
CONF_SECRET: SECRET_KEY,
|
||||
CONF_SECRET: TEST_SECRET_KEY,
|
||||
}})
|
||||
self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE)
|
||||
self.assert_location_latitude(2.0)
|
||||
|
@ -732,7 +733,7 @@ class TestDeviceTrackerOwnTrackConfigs(BaseMQTT):
|
|||
device_tracker.DOMAIN: {
|
||||
CONF_PLATFORM: 'owntracks',
|
||||
CONF_SECRET: {
|
||||
LOCATION_TOPIC: SECRET_KEY,
|
||||
LOCATION_TOPIC: TEST_SECRET_KEY,
|
||||
}}})
|
||||
self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE)
|
||||
self.assert_location_latitude(2.0)
|
||||
|
@ -803,7 +804,7 @@ class TestDeviceTrackerOwnTrackConfigs(BaseMQTT):
|
|||
assert setup_component(self.hass, device_tracker.DOMAIN, {
|
||||
device_tracker.DOMAIN: {
|
||||
CONF_PLATFORM: 'owntracks',
|
||||
CONF_SECRET: SECRET_KEY,
|
||||
CONF_SECRET: TEST_SECRET_KEY,
|
||||
}})
|
||||
|
||||
self.send_message(LOCATION_TOPIC, ENCRYPTED_LOCATION_MESSAGE)
|
||||
|
|
Loading…
Add table
Reference in a new issue