mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Fix lint issues for 0.33 (#4451)
* Fix PEP257 issues * Fix ident * Fix lint issues * Update docstrings * Fix indent * Fix indent * Fix lint issues * Fix lint issue * Again lint
This commit is contained in:
parent
c86e1b31b3
commit
e6c4113c5b
@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Support for ZWave climate devices.
|
Support for Z-Wave climate devices.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/climate.zwave/
|
https://home-assistant.io/components/climate.zwave/
|
||||||
@ -17,7 +17,7 @@ from homeassistant.const import (
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_NAME = 'name'
|
CONF_NAME = 'name'
|
||||||
DEFAULT_NAME = 'ZWave Climate'
|
DEFAULT_NAME = 'Z-Wave Climate'
|
||||||
|
|
||||||
REMOTEC = 0x5254
|
REMOTEC = 0x5254
|
||||||
REMOTEC_ZXT_120 = 0x8377
|
REMOTEC_ZXT_120 = 0x8377
|
||||||
@ -33,7 +33,7 @@ DEVICE_MAPPINGS = {
|
|||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the ZWave Climate devices."""
|
"""Set up the Z-Wave Climate devices."""
|
||||||
if discovery_info is None or zwave.NETWORK is None:
|
if discovery_info is None or zwave.NETWORK is None:
|
||||||
_LOGGER.debug("No discovery_info=%s or no NETWORK=%s",
|
_LOGGER.debug("No discovery_info=%s or no NETWORK=%s",
|
||||||
discovery_info, zwave.NETWORK)
|
discovery_info, zwave.NETWORK)
|
||||||
@ -48,10 +48,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
|
|
||||||
class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
|
class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
|
||||||
"""Represents a ZWave Climate device."""
|
"""Representation of a Z-Wave Climate device."""
|
||||||
|
|
||||||
def __init__(self, value, temp_unit):
|
def __init__(self, value, temp_unit):
|
||||||
"""Initialize the zwave climate device."""
|
"""Initialize the Z-Wave climate device."""
|
||||||
from openzwave.network import ZWaveNetwork
|
from openzwave.network import ZWaveNetwork
|
||||||
from pydispatch import dispatcher
|
from pydispatch import dispatcher
|
||||||
ZWaveDeviceEntity.__init__(self, value, DOMAIN)
|
ZWaveDeviceEntity.__init__(self, value, DOMAIN)
|
||||||
@ -162,7 +162,7 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
"""No polling on ZWave."""
|
"""No polling on Z-Wave."""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -86,14 +86,13 @@ class SwisscomDeviceScanner(object):
|
|||||||
|
|
||||||
def get_swisscom_data(self):
|
def get_swisscom_data(self):
|
||||||
"""Retrieve data from Swisscom and return parsed result."""
|
"""Retrieve data from Swisscom and return parsed result."""
|
||||||
request = requests.post('http://' + self.host + '/ws', headers={
|
url = 'http://{}/ws'.format(self.host)
|
||||||
'Content-Type': 'application/x-sah-ws-4-call+json'
|
headers = {'Content-Type': 'application/x-sah-ws-4-call+json'}
|
||||||
},
|
data = """
|
||||||
data="""{"service":"Devices",
|
{"service":"Devices", "method":"get",
|
||||||
"method":"get",
|
"parameters":{"expression":"lan and not self"}}"""
|
||||||
"parameters":
|
|
||||||
{"expression":"lan and not self"}}""",
|
request = requests.post(url, headers=headers, data=data, timeout=10)
|
||||||
timeout=10)
|
|
||||||
|
|
||||||
devices = {}
|
devices = {}
|
||||||
for device in request.json()['status']:
|
for device in request.json()['status']:
|
||||||
|
@ -125,8 +125,8 @@ class WUndergroundSensor(Entity):
|
|||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self.rest.data:
|
if self.rest.data:
|
||||||
|
|
||||||
if self._condition == 'elevation' and \
|
if self._condition == 'elevation' and self._condition in \
|
||||||
self._condition in self.rest.data['observation_location']:
|
self.rest.data['observation_location']:
|
||||||
return self.rest.data['observation_location'][self._condition]\
|
return self.rest.data['observation_location'][self._condition]\
|
||||||
.split()[0]
|
.split()[0]
|
||||||
|
|
||||||
|
@ -29,11 +29,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def get_test_config_dir(*add_path):
|
def get_test_config_dir(*add_path):
|
||||||
"""Return a path to a test config dir."""
|
"""Return a path to a test config dir."""
|
||||||
return os.path.join(os.path.dirname(__file__), "testing_config", *add_path)
|
return os.path.join(os.path.dirname(__file__), 'testing_config', *add_path)
|
||||||
|
|
||||||
|
|
||||||
def get_test_home_assistant():
|
def get_test_home_assistant():
|
||||||
"""Return a Home Assistant object pointing at test config dir."""
|
"""Return a Home Assistant object pointing at test config directory."""
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
loop = asyncio.ProactorEventLoop()
|
loop = asyncio.ProactorEventLoop()
|
||||||
else:
|
else:
|
||||||
@ -75,6 +75,7 @@ def get_test_home_assistant():
|
|||||||
return hass
|
return hass
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=protected-access
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_test_home_assistant(loop):
|
def async_test_home_assistant(loop):
|
||||||
"""Return a Home Assistant object pointing at test config dir."""
|
"""Return a Home Assistant object pointing at test config dir."""
|
||||||
@ -101,9 +102,10 @@ def async_test_home_assistant(loop):
|
|||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def mock_async_start():
|
def mock_async_start():
|
||||||
with patch.object(loop, 'add_signal_handler'), \
|
"""Start the mocking."""
|
||||||
patch('homeassistant.core._async_create_timer'), \
|
with patch.object(loop, 'add_signal_handler'),\
|
||||||
patch.object(hass, '_async_tasks_cleanup', return_value=None):
|
patch('homeassistant.core._async_create_timer'),\
|
||||||
|
patch.object(hass, '_async_tasks_cleanup', return_value=None):
|
||||||
yield from orig_start()
|
yield from orig_start()
|
||||||
|
|
||||||
hass.async_start = mock_async_start
|
hass.async_start = mock_async_start
|
||||||
@ -130,8 +132,10 @@ def mock_service(hass, domain, service):
|
|||||||
"""
|
"""
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
|
# pylint: disable=redefined-outer-name
|
||||||
@ha.callback
|
@ha.callback
|
||||||
def mock_service(call):
|
def mock_service(call):
|
||||||
|
""""Mocked service call."""
|
||||||
calls.append(call)
|
calls.append(call)
|
||||||
|
|
||||||
# pylint: disable=unnecessary-lambda
|
# pylint: disable=unnecessary-lambda
|
||||||
|
@ -8,8 +8,8 @@ import rxv
|
|||||||
def sample_content(name):
|
def sample_content(name):
|
||||||
"""Read content into a string from a file."""
|
"""Read content into a string from a file."""
|
||||||
with open('tests/components/media_player/yamaha_samples/%s' % name,
|
with open('tests/components/media_player/yamaha_samples/%s' % name,
|
||||||
encoding='utf-8') as f:
|
encoding='utf-8') as content:
|
||||||
return f.read()
|
return content.read()
|
||||||
|
|
||||||
|
|
||||||
class FakeYamaha(rxv.rxv.RXV):
|
class FakeYamaha(rxv.rxv.RXV):
|
||||||
@ -20,21 +20,25 @@ class FakeYamaha(rxv.rxv.RXV):
|
|||||||
ensure that usage of the rxv library by HomeAssistant is as we'd
|
ensure that usage of the rxv library by HomeAssistant is as we'd
|
||||||
expect.
|
expect.
|
||||||
"""
|
"""
|
||||||
_fake_input = "HDMI1"
|
_fake_input = 'HDMI1'
|
||||||
|
|
||||||
def _discover_features(self):
|
def _discover_features(self):
|
||||||
self._desc_xml = ET.fromstring(sample_content("desc.xml"))
|
"""Fake the discovery feature."""
|
||||||
|
self._desc_xml = ET.fromstring(sample_content('desc.xml'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def input(self):
|
def input(self):
|
||||||
|
"""A fake input for the reciever."""
|
||||||
return self._fake_input
|
return self._fake_input
|
||||||
|
|
||||||
@input.setter
|
@input.setter
|
||||||
def input(self, input_name):
|
def input(self, input_name):
|
||||||
|
"""Set the input for the fake receiver."""
|
||||||
assert input_name in self.inputs()
|
assert input_name in self.inputs()
|
||||||
self._fake_input = input_name
|
self._fake_input = input_name
|
||||||
|
|
||||||
def inputs(self):
|
def inputs(self):
|
||||||
|
"""All inputs of the the fake receiver."""
|
||||||
return {'AUDIO1': None,
|
return {'AUDIO1': None,
|
||||||
'AUDIO2': None,
|
'AUDIO2': None,
|
||||||
'AV1': None,
|
'AV1': None,
|
||||||
@ -61,15 +65,17 @@ class FakeYamaha(rxv.rxv.RXV):
|
|||||||
'iPod (USB)': 'iPod_USB'}
|
'iPod (USB)': 'iPod_USB'}
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=no-member, invalid-name
|
||||||
class TestYamaha(unittest.TestCase):
|
class TestYamaha(unittest.TestCase):
|
||||||
"""Test the media_player yamaha module."""
|
"""Test the media_player yamaha module."""
|
||||||
|
|
||||||
def setUp(self): # pylint: disable=invalid-name
|
def setUp(self):
|
||||||
"""Setup things to be run when tests are started."""
|
"""Setup things to be run when tests are started."""
|
||||||
super(TestYamaha, self).setUp()
|
super(TestYamaha, self).setUp()
|
||||||
self.rec = FakeYamaha('10.0.0.0')
|
self.rec = FakeYamaha('10.0.0.0')
|
||||||
|
|
||||||
def test_get_playback_support(self):
|
def test_get_playback_support(self):
|
||||||
|
"""Test the playback"""
|
||||||
rec = self.rec
|
rec = self.rec
|
||||||
support = rec.get_playback_support()
|
support = rec.get_playback_support()
|
||||||
self.assertFalse(support.play)
|
self.assertFalse(support.play)
|
||||||
@ -78,7 +84,7 @@ class TestYamaha(unittest.TestCase):
|
|||||||
self.assertFalse(support.skip_f)
|
self.assertFalse(support.skip_f)
|
||||||
self.assertFalse(support.skip_r)
|
self.assertFalse(support.skip_r)
|
||||||
|
|
||||||
rec.input = "NET RADIO"
|
rec.input = 'NET RADIO'
|
||||||
support = rec.get_playback_support()
|
support = rec.get_playback_support()
|
||||||
self.assertTrue(support.play)
|
self.assertTrue(support.play)
|
||||||
self.assertFalse(support.pause)
|
self.assertFalse(support.pause)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"""the tests for the Command line switch platform."""
|
"""The tests for the Command line switch platform."""
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -12,14 +12,15 @@ import homeassistant.components.switch.command_line as command_line
|
|||||||
from tests.common import get_test_home_assistant
|
from tests.common import get_test_home_assistant
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=invalid-name
|
||||||
class TestCommandSwitch(unittest.TestCase):
|
class TestCommandSwitch(unittest.TestCase):
|
||||||
"""Test the command switch."""
|
"""Test the command switch."""
|
||||||
|
|
||||||
def setUp(self): # pylint: disable=invalid-name
|
def setUp(self):
|
||||||
"""Setup things to be run when tests are started."""
|
"""Setup things to be run when tests are started."""
|
||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self):
|
||||||
"""Stop everything that was started."""
|
"""Stop everything that was started."""
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
@ -165,13 +166,13 @@ class TestCommandSwitch(unittest.TestCase):
|
|||||||
# args: hass, device_name, friendly_name, command_on, command_off,
|
# args: hass, device_name, friendly_name, command_on, command_off,
|
||||||
# command_state, value_template
|
# command_state, value_template
|
||||||
init_args = [
|
init_args = [
|
||||||
self.hass,
|
self.hass,
|
||||||
"test_device_name",
|
"test_device_name",
|
||||||
"Test friendly name!",
|
"Test friendly name!",
|
||||||
"echo 'on command'",
|
"echo 'on command'",
|
||||||
"echo 'off command'",
|
"echo 'off command'",
|
||||||
False,
|
False,
|
||||||
None
|
None,
|
||||||
]
|
]
|
||||||
|
|
||||||
no_state_device = command_line.CommandSwitch(*init_args)
|
no_state_device = command_line.CommandSwitch(*init_args)
|
||||||
@ -188,13 +189,13 @@ class TestCommandSwitch(unittest.TestCase):
|
|||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
|
|
||||||
init_args = [
|
init_args = [
|
||||||
self.hass,
|
self.hass,
|
||||||
"test_device_name",
|
"test_device_name",
|
||||||
"Test friendly name!",
|
"Test friendly name!",
|
||||||
"echo 'on command'",
|
"echo 'on command'",
|
||||||
"echo 'off command'",
|
"echo 'off command'",
|
||||||
False,
|
False,
|
||||||
None
|
None,
|
||||||
]
|
]
|
||||||
|
|
||||||
test_switch = command_line.CommandSwitch(*init_args)
|
test_switch = command_line.CommandSwitch(*init_args)
|
||||||
|
@ -17,12 +17,12 @@ from tests.common import get_test_instance_port, get_test_home_assistant
|
|||||||
HTTP_SERVER_PORT = get_test_instance_port()
|
HTTP_SERVER_PORT = get_test_instance_port()
|
||||||
BRIDGE_SERVER_PORT = get_test_instance_port()
|
BRIDGE_SERVER_PORT = get_test_instance_port()
|
||||||
|
|
||||||
BRIDGE_URL_BASE = "http://127.0.0.1:{}".format(BRIDGE_SERVER_PORT) + "{}"
|
BRIDGE_URL_BASE = 'http://127.0.0.1:{}'.format(BRIDGE_SERVER_PORT) + '{}'
|
||||||
JSON_HEADERS = {const.HTTP_HEADER_CONTENT_TYPE: const.CONTENT_TYPE_JSON}
|
JSON_HEADERS = {const.HTTP_HEADER_CONTENT_TYPE: const.CONTENT_TYPE_JSON}
|
||||||
|
|
||||||
|
|
||||||
def setup_hass_instance(emulated_hue_config):
|
def setup_hass_instance(emulated_hue_config):
|
||||||
"""Setup the Home Assistant instance to test."""
|
"""Set up the Home Assistant instance to test."""
|
||||||
hass = get_test_home_assistant()
|
hass = get_test_home_assistant()
|
||||||
|
|
||||||
# We need to do this to get access to homeassistant/turn_(on,off)
|
# We need to do this to get access to homeassistant/turn_(on,off)
|
||||||
@ -75,6 +75,7 @@ class TestEmulatedHue(unittest.TestCase):
|
|||||||
self.assertTrue('text/xml' in result.headers['content-type'])
|
self.assertTrue('text/xml' in result.headers['content-type'])
|
||||||
|
|
||||||
# Make sure the XML is parsable
|
# Make sure the XML is parsable
|
||||||
|
# pylint: disable=bare-except
|
||||||
try:
|
try:
|
||||||
ET.fromstring(result.text)
|
ET.fromstring(result.text)
|
||||||
except:
|
except:
|
||||||
@ -130,19 +131,20 @@ class TestEmulatedHueExposedByDefault(unittest.TestCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
bootstrap.setup_component(cls.hass, script.DOMAIN, {
|
bootstrap.setup_component(cls.hass, script.DOMAIN, {
|
||||||
'script': {
|
'script': {
|
||||||
'set_kitchen_light': {
|
'set_kitchen_light': {
|
||||||
'sequence': [
|
'sequence': [
|
||||||
{
|
{
|
||||||
'service_template': "light.turn_{{ requested_state }}",
|
'service_template':
|
||||||
'data_template': {
|
"light.turn_{{ requested_state }}",
|
||||||
'entity_id': 'light.kitchen_lights',
|
'data_template': {
|
||||||
'brightness': "{{ requested_level }}"
|
'entity_id': 'light.kitchen_lights',
|
||||||
}
|
'brightness': "{{ requested_level }}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
start_hass_instance(cls.hass)
|
start_hass_instance(cls.hass)
|
||||||
@ -285,6 +287,7 @@ class TestEmulatedHueExposedByDefault(unittest.TestCase):
|
|||||||
kitchen_light.attributes[light.ATTR_BRIGHTNESS],
|
kitchen_light.attributes[light.ATTR_BRIGHTNESS],
|
||||||
level)
|
level)
|
||||||
|
|
||||||
|
# pylint: disable=invalid-name
|
||||||
def test_put_with_form_urlencoded_content_type(self):
|
def test_put_with_form_urlencoded_content_type(self):
|
||||||
"""Test the form with urlencoded content."""
|
"""Test the form with urlencoded content."""
|
||||||
# Needed for Alexa
|
# Needed for Alexa
|
||||||
@ -296,7 +299,7 @@ class TestEmulatedHueExposedByDefault(unittest.TestCase):
|
|||||||
result = requests.put(
|
result = requests.put(
|
||||||
BRIDGE_URL_BASE.format(
|
BRIDGE_URL_BASE.format(
|
||||||
'/api/username/lights/{}/state'.format(
|
'/api/username/lights/{}/state'.format(
|
||||||
"light.ceiling_lights")), data=data)
|
'light.ceiling_lights')), data=data)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
@ -344,8 +347,8 @@ class TestEmulatedHueExposedByDefault(unittest.TestCase):
|
|||||||
result = requests.put(
|
result = requests.put(
|
||||||
BRIDGE_URL_BASE.format(
|
BRIDGE_URL_BASE.format(
|
||||||
'/api/username/lights/{}/state'.format(
|
'/api/username/lights/{}/state'.format(
|
||||||
"light.ceiling_lights")),
|
'light.ceiling_lights')),
|
||||||
data=json.dumps({HUE_API_STATE_ON: 1234}))
|
data=json.dumps({HUE_API_STATE_ON: 1234}))
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
@ -353,13 +356,14 @@ class TestEmulatedHueExposedByDefault(unittest.TestCase):
|
|||||||
result = requests.put(
|
result = requests.put(
|
||||||
BRIDGE_URL_BASE.format(
|
BRIDGE_URL_BASE.format(
|
||||||
'/api/username/lights/{}/state'.format(
|
'/api/username/lights/{}/state'.format(
|
||||||
"light.ceiling_lights")), data=json.dumps({
|
'light.ceiling_lights')), data=json.dumps({
|
||||||
HUE_API_STATE_ON: True,
|
HUE_API_STATE_ON: True,
|
||||||
HUE_API_STATE_BRI: 'Hello world!'
|
HUE_API_STATE_BRI: 'Hello world!'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
|
# pylint: disable=invalid-name
|
||||||
def perform_put_test_on_ceiling_lights(self,
|
def perform_put_test_on_ceiling_lights(self,
|
||||||
content_type='application/json'):
|
content_type='application/json'):
|
||||||
"""Test the setting of a light."""
|
"""Test the setting of a light."""
|
||||||
@ -405,6 +409,7 @@ class TestEmulatedHueExposedByDefault(unittest.TestCase):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# pylint: disable=no-self-use
|
||||||
def perform_put_light_state(self, entity_id, is_on, brightness=None,
|
def perform_put_light_state(self, entity_id, is_on, brightness=None,
|
||||||
content_type='application/json'):
|
content_type='application/json'):
|
||||||
"""Test the setting of a light state."""
|
"""Test the setting of a light state."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user