Merge of nested IF-IF cases - O-R (#48371)

pull/48400/head
Franck Nijhof 2021-03-27 10:38:57 +01:00 committed by GitHub
parent 3cd52b695d
commit 3aed84560f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 77 additions and 79 deletions

View File

@ -146,8 +146,7 @@ class ObihaiServiceSensors(SensorEntity):
services = self._pyobihai.get_line_state()
if services is not None:
if self._service_name in services:
if services is not None and self._service_name in services:
self._state = services.get(self._service_name)
call_direction = self._pyobihai.get_call_direction()

View File

@ -212,13 +212,11 @@ class OctoPrintAPI:
now = time.time()
if endpoint == "job":
last_time = self.job_last_reading[1]
if last_time is not None:
if now - last_time < 30.0:
if last_time is not None and now - last_time < 30.0:
return self.job_last_reading[0]
elif endpoint == "printer":
last_time = self.printer_last_reading[1]
if last_time is not None:
if now - last_time < 30.0:
if last_time is not None and now - last_time < 30.0:
return self.printer_last_reading[0]
url = self.api_url + endpoint
@ -300,8 +298,7 @@ def get_value_from_json(json_dict, sensor_type, group, tool):
return json_dict[group][sensor_type]
if tool is not None:
if sensor_type in json_dict[group][tool]:
if tool is not None and sensor_type in json_dict[group][tool]:
return json_dict[group][tool][sensor_type]
return None

View File

@ -25,8 +25,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
octoprint_api = hass.data[COMPONENT_DOMAIN][base_url]
tools = octoprint_api.get_tools()
if "Temperatures" in monitored_conditions:
if not tools:
if "Temperatures" in monitored_conditions and not tools:
hass.components.persistent_notification.create(
"Your printer appears to be offline.<br />"
"If you do not want to have your printer on <br />"

View File

@ -266,8 +266,7 @@ def get_entities(onewirehub: OneWireHub, config):
"""Get a list of entities."""
entities = []
device_names = {}
if CONF_NAMES in config:
if isinstance(config[CONF_NAMES], dict):
if CONF_NAMES in config and isinstance(config[CONF_NAMES], dict):
device_names = config[CONF_NAMES]
conf_type = config[CONF_TYPE]

View File

@ -267,8 +267,7 @@ async def filter_yaml_data(hass: HomeAssistantType, persons: list[dict]) -> list
for person_conf in persons:
user_id = person_conf.get(CONF_USER_ID)
if user_id is not None:
if await hass.auth.async_get_user(user_id) is None:
if user_id is not None and await hass.auth.async_get_user(user_id) is None:
_LOGGER.error(
"Invalid user_id detected for person %s",
person_conf[collection.CONF_ID],

View File

@ -170,8 +170,7 @@ class PhilipsTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
@property
def state(self):
"""Get the device state. An exception means OFF state."""
if self._tv.on:
if self._tv.powerstate == "On" or self._tv.powerstate is None:
if self._tv.on and (self._tv.powerstate == "On" or self._tv.powerstate is None):
return STATE_ON
return STATE_OFF

View File

@ -52,10 +52,9 @@ class PhilipsTVRemote(RemoteEntity):
@property
def is_on(self):
"""Return true if device is on."""
if self._tv.on:
if self._tv.powerstate == "On" or self._tv.powerstate is None:
return True
return False
return bool(
self._tv.on and (self._tv.powerstate == "On" or self._tv.powerstate is None)
)
@property
def should_poll(self):

View File

@ -65,8 +65,10 @@ class PlaatoSensor(PlaatoEntity, SensorEntity):
@property
def device_class(self) -> str | None:
"""Return the class of this device, from component DEVICE_CLASSES."""
if self._coordinator is not None:
if self._sensor_type == PlaatoKeg.Pins.TEMPERATURE:
if (
self._coordinator is not None
and self._sensor_type == PlaatoKeg.Pins.TEMPERATURE
):
return DEVICE_CLASS_TEMPERATURE
if self._sensor_type == ATTR_TEMP:
return DEVICE_CLASS_TEMPERATURE

View File

@ -365,8 +365,11 @@ class PlexServer:
PLAYER_SOURCE, source
)
if device.machineIdentifier not in ignored_clients:
if self.option_ignore_plexweb_clients and device.product == "Plex Web":
if (
device.machineIdentifier not in ignored_clients
and self.option_ignore_plexweb_clients
and device.product == "Plex Web"
):
ignored_clients.add(device.machineIdentifier)
if device.machineIdentifier not in self._known_clients:
_LOGGER.debug(

View File

@ -110,8 +110,7 @@ async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool:
api.get_all_devices()
if entry.unique_id is None:
if api.smile_version[0] != "1.8.0":
if entry.unique_id is None and api.smile_version[0] != "1.8.0":
hass.config_entries.async_update_entry(entry, unique_id=api.smile_hostname)
undo_listener = entry.add_update_listener(_update_listener)

View File

@ -55,13 +55,17 @@ def hwtest(cloud_id, install_code, ip_address):
response = reader.get_network_info()
# Branch to test if target is Legacy Model
if "NetworkInfo" in response:
if response["NetworkInfo"].get("ModelId", None) == "Z109-EAGLE":
if (
"NetworkInfo" in response
and response["NetworkInfo"].get("ModelId", None) == "Z109-EAGLE"
):
return reader
# Branch to test if target is Eagle-200 Model
if "Response" in response:
if response["Response"].get("Command", None) == "get_network_info":
if (
"Response" in response
and response["Response"].get("Command", None) == "get_network_info"
):
return EagleReader(ip_address, cloud_id, install_code)
# Catch-all if hardware ID tests fail

View File

@ -304,11 +304,7 @@ class Recorder(threading.Thread):
return False
entity_id = event.data.get(ATTR_ENTITY_ID)
if entity_id is not None:
if not self.entity_filter(entity_id):
return False
return True
return bool(entity_id is None or self.entity_filter(entity_id))
def do_adhoc_purge(self, **kwargs):
"""Trigger an adhoc purge retaining keep_days worth of data."""

View File

@ -67,8 +67,11 @@ def restore_entities(registry, coordinator, entry, async_add_entities, tracked):
missing = []
for entity in registry.entities.values():
if entity.config_entry_id == entry.entry_id and entity.platform == DOMAIN:
if entity.unique_id not in coordinator.data[API_CLIENTS]:
if (
entity.config_entry_id == entry.entry_id
and entity.platform == DOMAIN
and entity.unique_id not in coordinator.data[API_CLIENTS]
):
missing.append(
RuckusUnleashedDevice(
coordinator, entity.unique_id, entity.original_name