Pylint cleanups (#15626)
* Pylint 2 no-else-return fixes * Remove unneeded abstract-class-not-used pylint disable
This commit is contained in:
1 parent
a38c0d6d15
commit
b7c336a687
166 files changed
+425
-490
No files matched your search
@@ -67,9 +67,9 @@ class AbodeSensor(AbodeDevice):
|
||||
"""Return the state of the sensor."""
|
||||
if self._sensor_type == 'temp':
|
||||
return self._device.temp
|
||||
elif self._sensor_type == 'humidity':
|
||||
if self._sensor_type == 'humidity':
|
||||
return self._device.humidity
|
||||
elif self._sensor_type == 'lux':
|
||||
if self._sensor_type == 'lux':
|
||||
return self._device.lux
|
||||
|
||||
@property
|
||||
@@ -77,7 +77,7 @@ class AbodeSensor(AbodeDevice):
|
||||
"""Return the units of measurement."""
|
||||
if self._sensor_type == 'temp':
|
||||
return self._device.temp_unit
|
||||
elif self._sensor_type == 'humidity':
|
||||
if self._sensor_type == 'humidity':
|
||||
return self._device.humidity_unit
|
||||
elif self._sensor_type == 'lux':
|
||||
if self._sensor_type == 'lux':
|
||||
return self._device.lux_unit
|
||||
@@ -38,9 +38,9 @@ class StreamHandler(logging.Handler):
|
||||
else:
|
||||
if not record.msg.startswith('WS'):
|
||||
return
|
||||
elif len(record.args) < 2:
|
||||
if len(record.args) < 2:
|
||||
return
|
||||
elif record.args[1] == 'Connected':
|
||||
if record.args[1] == 'Connected':
|
||||
self.entity.count += 1
|
||||
elif record.args[1] == 'Closed connection':
|
||||
self.entity.count -= 1
|
||||
|
||||
@@ -123,7 +123,7 @@ class ArloSensor(Entity):
|
||||
"""Return the device class of the sensor."""
|
||||
if self._sensor_type == 'temperature':
|
||||
return DEVICE_CLASS_TEMPERATURE
|
||||
elif self._sensor_type == 'humidity':
|
||||
if self._sensor_type == 'humidity':
|
||||
return DEVICE_CLASS_HUMIDITY
|
||||
return None
|
||||
|
||||
|
||||
@@ -262,13 +262,13 @@ class BrSensor(Entity):
|
||||
self._entity_picture = img
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
self._state = data.get(FORECAST)[fcday].get(self.type[:-3])
|
||||
return True
|
||||
except IndexError:
|
||||
_LOGGER.warning("No forecast for fcday=%s...", fcday)
|
||||
return False
|
||||
|
||||
try:
|
||||
self._state = data.get(FORECAST)[fcday].get(self.type[:-3])
|
||||
return True
|
||||
except IndexError:
|
||||
_LOGGER.warning("No forecast for fcday=%s...", fcday)
|
||||
return False
|
||||
|
||||
if self.type == SYMBOL or self.type.startswith(CONDITION):
|
||||
# update weather symbol & status text
|
||||
|
||||
@@ -54,8 +54,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
sensors.append(CurrencylayerSensor(rest, base, variable))
|
||||
if 'error' in response.json():
|
||||
return False
|
||||
else:
|
||||
add_devices(sensors, True)
|
||||
add_devices(sensors, True)
|
||||
|
||||
|
||||
class CurrencylayerSensor(Entity):
|
||||
|
||||
@@ -352,12 +352,12 @@ class DarkSkySensor(Entity):
|
||||
# percentages
|
||||
if self.type in ['precip_probability', 'cloud_cover', 'humidity']:
|
||||
return round(state * 100, 1)
|
||||
elif (self.type in ['dew_point', 'temperature', 'apparent_temperature',
|
||||
'temperature_min', 'temperature_max',
|
||||
'apparent_temperature_min',
|
||||
'apparent_temperature_max',
|
||||
'precip_accumulation',
|
||||
'pressure', 'ozone', 'uvIndex']):
|
||||
if self.type in ['dew_point', 'temperature', 'apparent_temperature',
|
||||
'temperature_min', 'temperature_max',
|
||||
'apparent_temperature_min',
|
||||
'apparent_temperature_max',
|
||||
'precip_accumulation',
|
||||
'pressure', 'ozone', 'uvIndex']:
|
||||
return round(state, 1)
|
||||
return state
|
||||
|
||||
|
||||
@@ -129,17 +129,16 @@ class DovadoSensor(Entity):
|
||||
if self._sensor == SENSOR_NETWORK:
|
||||
match = re.search(r"\((.+)\)", state)
|
||||
return match.group(1) if match else None
|
||||
elif self._sensor == SENSOR_SIGNAL:
|
||||
if self._sensor == SENSOR_SIGNAL:
|
||||
try:
|
||||
return int(state.split()[0])
|
||||
except ValueError:
|
||||
return 0
|
||||
elif self._sensor == SENSOR_SMS_UNREAD:
|
||||
if self._sensor == SENSOR_SMS_UNREAD:
|
||||
return int(state)
|
||||
elif self._sensor in [SENSOR_UPLOAD, SENSOR_DOWNLOAD]:
|
||||
if self._sensor in [SENSOR_UPLOAD, SENSOR_DOWNLOAD]:
|
||||
return round(float(state) / 1e6, 1)
|
||||
else:
|
||||
return state
|
||||
return state
|
||||
|
||||
def update(self):
|
||||
"""Update sensor values."""
|
||||
|
||||
@@ -255,7 +255,7 @@ class DSMREntity(Entity):
|
||||
return ICON_POWER_FAILURE
|
||||
if 'Power' in self._name:
|
||||
return ICON_POWER
|
||||
elif 'Gas' in self._name:
|
||||
if 'Gas' in self._name:
|
||||
return ICON_GAS
|
||||
|
||||
@property
|
||||
@@ -285,7 +285,7 @@ class DSMREntity(Entity):
|
||||
# used for normal rate.
|
||||
if value == '0002':
|
||||
return 'normal'
|
||||
elif value == '0001':
|
||||
if value == '0001':
|
||||
return 'low'
|
||||
|
||||
return STATE_UNKNOWN
|
||||
|
||||
@@ -149,7 +149,7 @@ class EightUserSensor(EightSleepUserEntity):
|
||||
"""Return the unit the value is expressed in."""
|
||||
if 'current_sleep' in self._sensor or 'last_sleep' in self._sensor:
|
||||
return 'Score'
|
||||
elif 'bed_temp' in self._sensor:
|
||||
if 'bed_temp' in self._sensor:
|
||||
if self._units == 'si':
|
||||
return '°C'
|
||||
return '°F'
|
||||
|
||||
@@ -65,8 +65,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
if fstatus is None:
|
||||
_LOGGER.error("Failed to establish connection to FRITZ!Box: %s", host)
|
||||
return 1
|
||||
else:
|
||||
_LOGGER.info("Successfully connected to FRITZ!Box")
|
||||
_LOGGER.info("Successfully connected to FRITZ!Box")
|
||||
|
||||
add_devices([FritzboxMonitorSensor(name, fstatus)], True)
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ class GpsdSensor(Entity):
|
||||
"""Return the state of GPSD."""
|
||||
if self.agps_thread.data_stream.mode == 3:
|
||||
return "3D Fix"
|
||||
elif self.agps_thread.data_stream.mode == 2:
|
||||
if self.agps_thread.data_stream.mode == 2:
|
||||
return "2D Fix"
|
||||
return STATE_UNKNOWN
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ class HistoryStatsHelper:
|
||||
minutes, seconds = divmod(seconds, 60)
|
||||
if days > 0:
|
||||
return '%dd %dh %dm' % (days, hours, minutes)
|
||||
elif hours > 0:
|
||||
if hours > 0:
|
||||
return '%dh %dm' % (hours, minutes)
|
||||
return '%dm' % minutes
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class HiveSensorEntity(Entity):
|
||||
"""Return the state of the sensor."""
|
||||
if self.device_type == "Hub_OnlineStatus":
|
||||
return self.session.sensor.hub_online_status(self.node_id)
|
||||
elif self.device_type == "Hive_OutsideTemperature":
|
||||
if self.device_type == "Hive_OutsideTemperature":
|
||||
return self.session.weather.temperature()
|
||||
|
||||
@property
|
||||
|
||||
@@ -262,10 +262,8 @@ class ISYSensorDevice(ISYDevice):
|
||||
if friendly_name in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
|
||||
friendly_name = self.hass.config.units.temperature_unit
|
||||
return friendly_name
|
||||
else:
|
||||
return self._node.uom[0]
|
||||
else:
|
||||
return None
|
||||
return self._node.uom[0]
|
||||
return None
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
|
||||
@@ -96,7 +96,7 @@ class MfiSensor(Entity):
|
||||
tag = None
|
||||
if tag is None:
|
||||
return STATE_OFF
|
||||
elif self._port.model == 'Input Digital':
|
||||
if self._port.model == 'Input Digital':
|
||||
return STATE_ON if self._port.value > 0 else STATE_OFF
|
||||
digits = DIGITS.get(self._port.tag, 0)
|
||||
return round(self._port.value, digits)
|
||||
@@ -111,9 +111,9 @@ class MfiSensor(Entity):
|
||||
|
||||
if tag == 'temperature':
|
||||
return TEMP_CELSIUS
|
||||
elif tag == 'active_pwr':
|
||||
if tag == 'active_pwr':
|
||||
return 'Watts'
|
||||
elif self._port.model == 'Input Digital':
|
||||
if self._port.model == 'Input Digital':
|
||||
return 'State'
|
||||
return tag
|
||||
|
||||
|
||||
@@ -107,11 +107,10 @@ class MoldIndicator(Entity):
|
||||
# convert to celsius if necessary
|
||||
if unit == TEMP_FAHRENHEIT:
|
||||
return util.temperature.fahrenheit_to_celsius(temp)
|
||||
elif unit == TEMP_CELSIUS:
|
||||
if unit == TEMP_CELSIUS:
|
||||
return temp
|
||||
else:
|
||||
_LOGGER.error("Temp sensor has unsupported unit: %s (allowed: %s, "
|
||||
"%s)", unit, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||
_LOGGER.error("Temp sensor has unsupported unit: %s (allowed: %s, "
|
||||
"%s)", unit, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@@ -51,17 +51,17 @@ class MoonSensor(Entity):
|
||||
"""Return the state of the device."""
|
||||
if self._state == 0:
|
||||
return 'new_moon'
|
||||
elif self._state < 7:
|
||||
if self._state < 7:
|
||||
return 'waxing_crescent'
|
||||
elif self._state == 7:
|
||||
if self._state == 7:
|
||||
return 'first_quarter'
|
||||
elif self._state < 14:
|
||||
if self._state < 14:
|
||||
return 'waxing_gibbous'
|
||||
elif self._state == 14:
|
||||
if self._state == 14:
|
||||
return 'full_moon'
|
||||
elif self._state < 21:
|
||||
if self._state < 21:
|
||||
return 'waning_gibbous'
|
||||
elif self._state == 21:
|
||||
if self._state == 21:
|
||||
return 'last_quarter'
|
||||
return 'waning_crescent'
|
||||
|
||||
|
||||
@@ -236,13 +236,12 @@ class NUTSensor(Entity):
|
||||
"""Return UPS display state."""
|
||||
if self._data.status is None:
|
||||
return STATE_TYPES['OFF']
|
||||
else:
|
||||
try:
|
||||
return " ".join(
|
||||
STATE_TYPES[state]
|
||||
for state in self._data.status[KEY_STATUS].split())
|
||||
except KeyError:
|
||||
return STATE_UNKNOWN
|
||||
try:
|
||||
return " ".join(
|
||||
STATE_TYPES[state]
|
||||
for state in self._data.status[KEY_STATUS].split())
|
||||
except KeyError:
|
||||
return STATE_UNKNOWN
|
||||
|
||||
def update(self):
|
||||
"""Get the latest status and use it to update our sensor state."""
|
||||
|
||||
@@ -112,8 +112,7 @@ class OctoPrintSensor(Entity):
|
||||
if self._state is None:
|
||||
self._state = 0
|
||||
return round(self._state, 2)
|
||||
else:
|
||||
return self._state
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
||||
@@ -101,11 +101,10 @@ class OpenHardwareMonitorDevice(Entity):
|
||||
|
||||
self.attributes = _attributes
|
||||
return
|
||||
else:
|
||||
array = array[path_number][OHM_CHILDREN]
|
||||
_attributes.update({
|
||||
'level_%s' % path_index: values[OHM_NAME]
|
||||
})
|
||||
array = array[path_number][OHM_CHILDREN]
|
||||
_attributes.update({
|
||||
'level_%s' % path_index: values[OHM_NAME]
|
||||
})
|
||||
|
||||
|
||||
class OpenHardwareMonitorData:
|
||||
|
||||
@@ -241,7 +241,7 @@ class QNAPCPUSensor(QNAPSensor):
|
||||
"""Return the state of the sensor."""
|
||||
if self.var_id == 'cpu_temp':
|
||||
return self._api.data['system_stats']['cpu']['temp_c']
|
||||
elif self.var_id == 'cpu_usage':
|
||||
if self.var_id == 'cpu_usage':
|
||||
return self._api.data['system_stats']['cpu']['usage_percent']
|
||||
|
||||
|
||||
|
||||
@@ -83,11 +83,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
if errindication and not accept_errors:
|
||||
_LOGGER.error("Please check the details in the configuration file")
|
||||
return False
|
||||
else:
|
||||
data = SnmpData(
|
||||
host, port, community, baseoid, version, accept_errors,
|
||||
default_value)
|
||||
add_devices([SnmpSensor(data, name, unit, value_template)], True)
|
||||
data = SnmpData(
|
||||
host, port, community, baseoid, version, accept_errors,
|
||||
default_value)
|
||||
add_devices([SnmpSensor(data, name, unit, value_template)], True)
|
||||
|
||||
|
||||
class SnmpSensor(Entity):
|
||||
|
||||
@@ -214,7 +214,7 @@ class SynoNasUtilSensor(SynoNasSensor):
|
||||
|
||||
if self.var_id in network_sensors:
|
||||
return round(attr / 1024.0, 1)
|
||||
elif self.var_id in memory_sensors:
|
||||
if self.var_id in memory_sensors:
|
||||
return round(attr / 1024.0 / 1024.0, 1)
|
||||
else:
|
||||
return getattr(self._api.utilisation, self.var_id)
|
||||
|
||||
@@ -122,9 +122,9 @@ class TadoSensor(Entity):
|
||||
"""Return the unit of measurement."""
|
||||
if self.zone_variable == "temperature":
|
||||
return self.hass.config.units.temperature_unit
|
||||
elif self.zone_variable == "humidity":
|
||||
if self.zone_variable == "humidity":
|
||||
return '%'
|
||||
elif self.zone_variable == "heating":
|
||||
if self.zone_variable == "heating":
|
||||
return '%'
|
||||
|
||||
@property
|
||||
@@ -132,7 +132,7 @@ class TadoSensor(Entity):
|
||||
"""Icon for the sensor."""
|
||||
if self.zone_variable == "temperature":
|
||||
return 'mdi:thermometer'
|
||||
elif self.zone_variable == "humidity":
|
||||
if self.zone_variable == "humidity":
|
||||
return 'mdi:water-percent'
|
||||
|
||||
def update(self):
|
||||
|
||||
@@ -46,11 +46,11 @@ class TahomaSensor(TahomaDevice, Entity):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
if self.tahoma_device.type == 'Temperature Sensor':
|
||||
return None
|
||||
elif self.tahoma_device.type == 'io:SomfyContactIOSystemSensor':
|
||||
if self.tahoma_device.type == 'io:SomfyContactIOSystemSensor':
|
||||
return None
|
||||
elif self.tahoma_device.type == 'io:LightIOSystemSensor':
|
||||
if self.tahoma_device.type == 'io:LightIOSystemSensor':
|
||||
return 'lx'
|
||||
elif self.tahoma_device.type == 'Humidity Sensor':
|
||||
if self.tahoma_device.type == 'Humidity Sensor':
|
||||
return '%'
|
||||
|
||||
def update(self):
|
||||
|
||||
@@ -96,11 +96,11 @@ class TelldusLiveSensor(TelldusLiveEntity):
|
||||
"""Return the state of the sensor."""
|
||||
if not self.available:
|
||||
return None
|
||||
elif self._type == SENSOR_TYPE_TEMPERATURE:
|
||||
if self._type == SENSOR_TYPE_TEMPERATURE:
|
||||
return self._value_as_temperature
|
||||
elif self._type == SENSOR_TYPE_HUMIDITY:
|
||||
if self._type == SENSOR_TYPE_HUMIDITY:
|
||||
return self._value_as_humidity
|
||||
elif self._type == SENSOR_TYPE_LUMINANCE:
|
||||
if self._type == SENSOR_TYPE_LUMINANCE:
|
||||
return self._value_as_luminance
|
||||
return self._value
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ class TimeDateSensor(Entity):
|
||||
"""Icon to use in the frontend, if any."""
|
||||
if 'date' in self.type and 'time' in self.type:
|
||||
return 'mdi:calendar-clock'
|
||||
elif 'date' in self.type:
|
||||
if 'date' in self.type:
|
||||
return 'mdi:calendar'
|
||||
return 'mdi:clock'
|
||||
|
||||
@@ -92,7 +92,7 @@ class TimeDateSensor(Entity):
|
||||
if self.type == 'date':
|
||||
now = dt_util.start_of_local_day(dt_util.as_local(now))
|
||||
return now + timedelta(seconds=86400)
|
||||
elif self.type == 'beat':
|
||||
if self.type == 'beat':
|
||||
interval = 86.4
|
||||
else:
|
||||
interval = 60
|
||||
|
||||
@@ -51,13 +51,13 @@ class VeraSensor(VeraDevice, Entity):
|
||||
import pyvera as veraApi
|
||||
if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:
|
||||
return self._temperature_units
|
||||
elif self.vera_device.category == veraApi.CATEGORY_LIGHT_SENSOR:
|
||||
if self.vera_device.category == veraApi.CATEGORY_LIGHT_SENSOR:
|
||||
return 'lx'
|
||||
elif self.vera_device.category == veraApi.CATEGORY_UV_SENSOR:
|
||||
if self.vera_device.category == veraApi.CATEGORY_UV_SENSOR:
|
||||
return 'level'
|
||||
elif self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
|
||||
if self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
|
||||
return '%'
|
||||
elif self.vera_device.category == veraApi.CATEGORY_POWER_METER:
|
||||
if self.vera_device.category == veraApi.CATEGORY_POWER_METER:
|
||||
return 'watts'
|
||||
|
||||
def update(self):
|
||||
|
||||
@@ -43,7 +43,7 @@ class VolvoSensor(VolvoEntity):
|
||||
if 'mil' in self.unit_of_measurement:
|
||||
return round(val, 2)
|
||||
return round(val, 1)
|
||||
elif self._attribute == 'distance_to_empty':
|
||||
if self._attribute == 'distance_to_empty':
|
||||
return int(floor(val))
|
||||
return int(round(val))
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class WorldTidesInfoSensor(Entity):
|
||||
tidetime = time.strftime('%I:%M %p', time.localtime(
|
||||
self.data['extremes'][0]['dt']))
|
||||
return "High tide at %s" % (tidetime)
|
||||
elif "Low" in str(self.data['extremes'][0]['type']):
|
||||
if "Low" in str(self.data['extremes'][0]['type']):
|
||||
tidetime = time.strftime('%I:%M %p', time.localtime(
|
||||
self.data['extremes'][0]['dt']))
|
||||
return "Low tide at %s" % (tidetime)
|
||||
|
||||
@@ -152,11 +152,11 @@ class WorxLandroidSensor(Entity):
|
||||
|
||||
if state_obj[14] == 1:
|
||||
return 'manual-stop'
|
||||
elif state_obj[5] == 1 and state_obj[13] == 0:
|
||||
if state_obj[5] == 1 and state_obj[13] == 0:
|
||||
return 'charging'
|
||||
elif state_obj[5] == 1 and state_obj[13] == 1:
|
||||
if state_obj[5] == 1 and state_obj[13] == 1:
|
||||
return 'charging-complete'
|
||||
elif state_obj[15] == 1:
|
||||
if state_obj[15] == 1:
|
||||
return 'going-home'
|
||||
return 'mowing'
|
||||
|
||||
|
||||
@@ -91,9 +91,9 @@ class XiaomiSensor(XiaomiDevice):
|
||||
value = max(value - 300, 0)
|
||||
if self._data_key == 'temperature' and (value < -50 or value > 60):
|
||||
return False
|
||||
elif self._data_key == 'humidity' and (value <= 0 or value > 100):
|
||||
if self._data_key == 'humidity' and (value <= 0 or value > 100):
|
||||
return False
|
||||
elif self._data_key == 'pressure' and value == 0:
|
||||
if self._data_key == 'pressure' and value == 0:
|
||||
return False
|
||||
self._state = round(value, 1)
|
||||
return True
|
||||
@@ -64,7 +64,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
|
||||
"""Return the state of the sensor."""
|
||||
if self._units in ('C', 'F'):
|
||||
return round(self._state, 1)
|
||||
elif isinstance(self._state, float):
|
||||
if isinstance(self._state, float):
|
||||
return round(self._state, 2)
|
||||
|
||||
return self._state
|
||||
@@ -74,7 +74,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
|
||||
"""Return the unit the value is expressed in."""
|
||||
if self._units == 'C':
|
||||
return TEMP_CELSIUS
|
||||
elif self._units == 'F':
|
||||
if self._units == 'F':
|
||||
return TEMP_FAHRENHEIT
|
||||
return self._units
|
||||
|
||||
|
||||
Reference in new issue
Block a user