Merge of nested IF-IF cases - O-R (#48371)
parent
3cd52b695d
commit
3aed84560f
|
@ -146,9 +146,8 @@ class ObihaiServiceSensors(SensorEntity):
|
|||
|
||||
services = self._pyobihai.get_line_state()
|
||||
|
||||
if services is not None:
|
||||
if self._service_name in services:
|
||||
self._state = services.get(self._service_name)
|
||||
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()
|
||||
|
||||
|
|
|
@ -212,14 +212,12 @@ 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:
|
||||
return self.job_last_reading[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:
|
||||
return self.printer_last_reading[0]
|
||||
if last_time is not None and now - last_time < 30.0:
|
||||
return self.printer_last_reading[0]
|
||||
|
||||
url = self.api_url + endpoint
|
||||
try:
|
||||
|
@ -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]:
|
||||
return json_dict[group][tool][sensor_type]
|
||||
if tool is not None and sensor_type in json_dict[group][tool]:
|
||||
return json_dict[group][tool][sensor_type]
|
||||
|
||||
return None
|
||||
|
|
|
@ -25,18 +25,17 @@ 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:
|
||||
hass.components.persistent_notification.create(
|
||||
"Your printer appears to be offline.<br />"
|
||||
"If you do not want to have your printer on <br />"
|
||||
" at all times, and you would like to monitor <br /> "
|
||||
"temperatures, please add <br />"
|
||||
"bed and/or number_of_tools to your configuration <br />"
|
||||
"and restart.",
|
||||
title=NOTIFICATION_TITLE,
|
||||
notification_id=NOTIFICATION_ID,
|
||||
)
|
||||
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 />"
|
||||
" at all times, and you would like to monitor <br /> "
|
||||
"temperatures, please add <br />"
|
||||
"bed and/or number_of_tools to your configuration <br />"
|
||||
"and restart.",
|
||||
title=NOTIFICATION_TITLE,
|
||||
notification_id=NOTIFICATION_ID,
|
||||
)
|
||||
|
||||
devices = []
|
||||
types = ["actual", "target"]
|
||||
|
|
|
@ -266,9 +266,8 @@ 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):
|
||||
device_names = config[CONF_NAMES]
|
||||
if CONF_NAMES in config and isinstance(config[CONF_NAMES], dict):
|
||||
device_names = config[CONF_NAMES]
|
||||
|
||||
conf_type = config[CONF_TYPE]
|
||||
# We have an owserver on a remote(or local) host/port
|
||||
|
|
|
@ -267,16 +267,15 @@ 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:
|
||||
_LOGGER.error(
|
||||
"Invalid user_id detected for person %s",
|
||||
person_conf[collection.CONF_ID],
|
||||
)
|
||||
person_invalid_user.append(
|
||||
f"- Person {person_conf[CONF_NAME]} (id: {person_conf[collection.CONF_ID]}) points at invalid user {user_id}"
|
||||
)
|
||||
continue
|
||||
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],
|
||||
)
|
||||
person_invalid_user.append(
|
||||
f"- Person {person_conf[CONF_NAME]} (id: {person_conf[collection.CONF_ID]}) points at invalid user {user_id}"
|
||||
)
|
||||
continue
|
||||
|
||||
filtered.append(person_conf)
|
||||
|
||||
|
|
|
@ -170,9 +170,8 @@ 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:
|
||||
return STATE_ON
|
||||
if self._tv.on and (self._tv.powerstate == "On" or self._tv.powerstate is None):
|
||||
return STATE_ON
|
||||
return STATE_OFF
|
||||
|
||||
@property
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -65,9 +65,11 @@ 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:
|
||||
return DEVICE_CLASS_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
|
||||
return None
|
||||
|
|
|
@ -365,17 +365,20 @@ class PlexServer:
|
|||
PLAYER_SOURCE, source
|
||||
)
|
||||
|
||||
if device.machineIdentifier not in ignored_clients:
|
||||
if 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(
|
||||
"Ignoring %s %s: %s",
|
||||
"Plex Web",
|
||||
source,
|
||||
device.machineIdentifier,
|
||||
)
|
||||
return
|
||||
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(
|
||||
"Ignoring %s %s: %s",
|
||||
"Plex Web",
|
||||
source,
|
||||
device.machineIdentifier,
|
||||
)
|
||||
return
|
||||
|
||||
if device.machineIdentifier not in (
|
||||
self._created_clients | ignored_clients | new_clients
|
||||
|
|
|
@ -110,9 +110,8 @@ 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":
|
||||
hass.config_entries.async_update_entry(entry, unique_id=api.smile_hostname)
|
||||
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)
|
||||
|
||||
|
|
|
@ -55,14 +55,18 @@ 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":
|
||||
return reader
|
||||
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":
|
||||
return EagleReader(ip_address, cloud_id, install_code)
|
||||
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
|
||||
raise ValueError("Couldn't determine device model.")
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -67,14 +67,17 @@ 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]:
|
||||
missing.append(
|
||||
RuckusUnleashedDevice(
|
||||
coordinator, entity.unique_id, entity.original_name
|
||||
)
|
||||
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
|
||||
)
|
||||
tracked.add(entity.unique_id)
|
||||
)
|
||||
tracked.add(entity.unique_id)
|
||||
|
||||
if missing:
|
||||
async_add_entities(missing)
|
||||
|
|
Loading…
Reference in New Issue