mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Flake8 bugbear fixes (#12072)
* Don't use mutable argument defaults (bugbear B006) * Use callable(x) instead of hasattr(x, '__call__') (bugbear B004) * Remove/mark unused loop control variables (bugbear B007) * Fix stripping protocol from kodi host name (bugbear B005) * Fix plant daily history add default date (bugbear B008)
This commit is contained in:
parent
37034a7450
commit
cab6c694c5
@ -46,7 +46,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
serport = connection.connection(ipaddress, port)
|
||||
serport.open()
|
||||
|
||||
for thermostat, tstat in tstats.items():
|
||||
for tstat in tstats.values():
|
||||
add_devices([
|
||||
HeatmiserV3Thermostat(
|
||||
heatmiser, tstat.get(CONF_ID), tstat.get(CONF_NAME), serport)
|
||||
|
@ -182,7 +182,7 @@ def enabled_push_ids():
|
||||
"""Return a list of push enabled target push IDs."""
|
||||
push_ids = list()
|
||||
# pylint: disable=unused-variable
|
||||
for device_name, device in CONFIG_FILE[ATTR_DEVICES].items():
|
||||
for device in CONFIG_FILE[ATTR_DEVICES].values():
|
||||
if device.get(ATTR_PUSH_ID) is not None:
|
||||
push_ids.append(device.get(ATTR_PUSH_ID))
|
||||
return push_ids
|
||||
|
@ -175,7 +175,7 @@ def setup_plexserver(
|
||||
else:
|
||||
plex_clients[machine_identifier].refresh(None, session)
|
||||
|
||||
for machine_identifier, client in plex_clients.items():
|
||||
for client in plex_clients.values():
|
||||
# force devices to idle that do not have a valid session
|
||||
if client.session is None:
|
||||
client.force_idle()
|
||||
|
@ -51,7 +51,7 @@ def async_get_service(hass, config, discovery_info=None):
|
||||
encryption = config.get(CONF_PROXY_SSL)
|
||||
|
||||
if host.startswith('http://') or host.startswith('https://'):
|
||||
host = host.lstrip('http://').lstrip('https://')
|
||||
host = host[host.index('://') + 3:]
|
||||
_LOGGER.warning(
|
||||
"Kodi host name should no longer contain http:// See updated "
|
||||
"definitions here: "
|
||||
|
@ -336,9 +336,9 @@ class DailyHistory(object):
|
||||
self._max_dict = dict()
|
||||
self.max = None
|
||||
|
||||
def add_measurement(self, value, timestamp=datetime.now()):
|
||||
def add_measurement(self, value, timestamp=None):
|
||||
"""Add a new measurement for a certain day."""
|
||||
day = timestamp.date()
|
||||
day = (timestamp or datetime.now()).date()
|
||||
if value is None:
|
||||
return
|
||||
if self._days is None:
|
||||
|
@ -171,7 +171,7 @@ def get_pt2262_cmd(device_id, data_bits):
|
||||
# pylint: disable=unused-variable
|
||||
def get_pt2262_device(device_id):
|
||||
"""Look for the device which id matches the given device_id parameter."""
|
||||
for dev_id, device in RFX_DEVICES.items():
|
||||
for device in RFX_DEVICES.values():
|
||||
if (hasattr(device, 'is_lighting4') and
|
||||
device.masked_id == get_pt2262_deviceid(device_id,
|
||||
device.data_bits)):
|
||||
|
@ -170,7 +170,7 @@ def _obj_to_dict(obj):
|
||||
"""Convert an object into a hash for debug."""
|
||||
return {key: getattr(obj, key) for key
|
||||
in dir(obj)
|
||||
if key[0] != '_' and not hasattr(getattr(obj, key), '__call__')}
|
||||
if key[0] != '_' and not callable(getattr(obj, key))}
|
||||
|
||||
|
||||
def _value_name(value):
|
||||
|
@ -134,7 +134,7 @@ def run(script_args: List) -> int:
|
||||
|
||||
for sfn, sdict in res['secret_cache'].items():
|
||||
sss = []
|
||||
for skey, sval in sdict.items():
|
||||
for skey in sdict:
|
||||
if skey in flatsecret:
|
||||
_LOGGER.error('Duplicated secrets in files %s and %s',
|
||||
flatsecret[skey], sfn)
|
||||
|
@ -107,7 +107,7 @@ def vincenty(point1: Tuple[float, float], point2: Tuple[float, float],
|
||||
sinU2 = math.sin(U2)
|
||||
cosU2 = math.cos(U2)
|
||||
|
||||
for iteration in range(MAX_ITERATIONS):
|
||||
for _ in range(MAX_ITERATIONS):
|
||||
sinLambda = math.sin(Lambda)
|
||||
cosLambda = math.cos(Lambda)
|
||||
sinSigma = math.sqrt((cosU2 * sinLambda) ** 2 +
|
||||
|
@ -98,8 +98,9 @@ def alexa_client(loop, hass, test_client):
|
||||
return loop.run_until_complete(test_client(hass.http.app))
|
||||
|
||||
|
||||
def _intent_req(client, data={}):
|
||||
return client.post(intent.INTENTS_API_ENDPOINT, data=json.dumps(data),
|
||||
def _intent_req(client, data=None):
|
||||
return client.post(intent.INTENTS_API_ENDPOINT,
|
||||
data=json.dumps(data or {}),
|
||||
headers={'content-type': 'application/json'})
|
||||
|
||||
|
||||
|
@ -68,7 +68,7 @@ class TestSetup(unittest.TestCase):
|
||||
"""Return a dict suitable for mocking api.get('lights')."""
|
||||
mock_bridge_lights = lights
|
||||
|
||||
for light_id, info in mock_bridge_lights.items():
|
||||
for info in mock_bridge_lights.values():
|
||||
if 'state' not in info:
|
||||
info['state'] = {'on': False}
|
||||
|
||||
|
@ -17,12 +17,12 @@ def mock_device(device_id, name, is_online=True):
|
||||
return device
|
||||
|
||||
|
||||
def mock_location(name, is_celsius=True, devices=[]):
|
||||
def mock_location(name, is_celsius=True, devices=None):
|
||||
"""Mock Canary Location class."""
|
||||
location = MagicMock()
|
||||
type(location).name = PropertyMock(return_value=name)
|
||||
type(location).is_celsius = PropertyMock(return_value=is_celsius)
|
||||
type(location).devices = PropertyMock(return_value=devices)
|
||||
type(location).devices = PropertyMock(return_value=devices or [])
|
||||
return location
|
||||
|
||||
|
||||
|
@ -733,7 +733,7 @@ class TestRetryOnErrorDecorator(unittest.TestCase):
|
||||
self.assertEqual(mock_method.call_count, 2)
|
||||
mock_method.assert_called_with(1, 2, test=3)
|
||||
|
||||
for cnt in range(3):
|
||||
for _ in range(3):
|
||||
start = dt_util.utcnow()
|
||||
shifted_time = start + (timedelta(seconds=20 + 1))
|
||||
self.hass.bus.fire(ha.EVENT_TIME_CHANGED,
|
||||
|
@ -135,7 +135,7 @@ class TestHomeAssistant(unittest.TestCase):
|
||||
"""Test Coro."""
|
||||
call_count.append('call')
|
||||
|
||||
for i in range(3):
|
||||
for _ in range(3):
|
||||
self.hass.add_job(test_coro())
|
||||
|
||||
run_coroutine_threadsafe(
|
||||
@ -155,7 +155,7 @@ class TestHomeAssistant(unittest.TestCase):
|
||||
"""Test Coro."""
|
||||
call_count.append('call')
|
||||
|
||||
for i in range(2):
|
||||
for _ in range(2):
|
||||
self.hass.add_job(test_coro())
|
||||
|
||||
@asyncio.coroutine
|
||||
@ -185,7 +185,7 @@ class TestHomeAssistant(unittest.TestCase):
|
||||
yield from asyncio.sleep(0, loop=self.hass.loop)
|
||||
yield from asyncio.sleep(0, loop=self.hass.loop)
|
||||
|
||||
for i in range(2):
|
||||
for _ in range(2):
|
||||
self.hass.add_job(test_executor)
|
||||
|
||||
run_coroutine_threadsafe(
|
||||
@ -210,7 +210,7 @@ class TestHomeAssistant(unittest.TestCase):
|
||||
yield from asyncio.sleep(0, loop=self.hass.loop)
|
||||
yield from asyncio.sleep(0, loop=self.hass.loop)
|
||||
|
||||
for i in range(2):
|
||||
for _ in range(2):
|
||||
self.hass.add_job(test_callback)
|
||||
|
||||
run_coroutine_threadsafe(
|
||||
|
@ -97,7 +97,7 @@ class AiohttpClientMockResponse:
|
||||
"""Mock Aiohttp client response."""
|
||||
|
||||
def __init__(self, method, url, status, response, cookies=None, exc=None,
|
||||
headers={}):
|
||||
headers=None):
|
||||
"""Initialize a fake response."""
|
||||
self.method = method
|
||||
self._url = url
|
||||
@ -107,7 +107,7 @@ class AiohttpClientMockResponse:
|
||||
self.response = response
|
||||
self.exc = exc
|
||||
|
||||
self._headers = headers
|
||||
self._headers = headers or {}
|
||||
self._cookies = {}
|
||||
|
||||
if cookies:
|
||||
|
Loading…
x
Reference in New Issue
Block a user