Merge of nested IF-IF cases - O-R (#48371)
This commit is contained in:
parent
3cd52b695d
commit
3aed84560f
13 changed files with 77 additions and 79 deletions
|
@ -146,9 +146,8 @@ class ObihaiServiceSensors(SensorEntity):
|
||||||
|
|
||||||
services = self._pyobihai.get_line_state()
|
services = self._pyobihai.get_line_state()
|
||||||
|
|
||||||
if services is not None:
|
if services is not None and self._service_name in services:
|
||||||
if self._service_name in services:
|
self._state = services.get(self._service_name)
|
||||||
self._state = services.get(self._service_name)
|
|
||||||
|
|
||||||
call_direction = self._pyobihai.get_call_direction()
|
call_direction = self._pyobihai.get_call_direction()
|
||||||
|
|
||||||
|
|
|
@ -212,14 +212,12 @@ class OctoPrintAPI:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if endpoint == "job":
|
if endpoint == "job":
|
||||||
last_time = self.job_last_reading[1]
|
last_time = self.job_last_reading[1]
|
||||||
if last_time is not None:
|
if last_time is not None and now - last_time < 30.0:
|
||||||
if now - last_time < 30.0:
|
return self.job_last_reading[0]
|
||||||
return self.job_last_reading[0]
|
|
||||||
elif endpoint == "printer":
|
elif endpoint == "printer":
|
||||||
last_time = self.printer_last_reading[1]
|
last_time = self.printer_last_reading[1]
|
||||||
if last_time is not None:
|
if last_time is not None and now - last_time < 30.0:
|
||||||
if now - last_time < 30.0:
|
return self.printer_last_reading[0]
|
||||||
return self.printer_last_reading[0]
|
|
||||||
|
|
||||||
url = self.api_url + endpoint
|
url = self.api_url + endpoint
|
||||||
try:
|
try:
|
||||||
|
@ -300,8 +298,7 @@ def get_value_from_json(json_dict, sensor_type, group, tool):
|
||||||
|
|
||||||
return json_dict[group][sensor_type]
|
return json_dict[group][sensor_type]
|
||||||
|
|
||||||
if tool is not None:
|
if tool is not None and sensor_type in json_dict[group][tool]:
|
||||||
if sensor_type in json_dict[group][tool]:
|
return json_dict[group][tool][sensor_type]
|
||||||
return json_dict[group][tool][sensor_type]
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -25,18 +25,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
octoprint_api = hass.data[COMPONENT_DOMAIN][base_url]
|
octoprint_api = hass.data[COMPONENT_DOMAIN][base_url]
|
||||||
tools = octoprint_api.get_tools()
|
tools = octoprint_api.get_tools()
|
||||||
|
|
||||||
if "Temperatures" in monitored_conditions:
|
if "Temperatures" in monitored_conditions and not tools:
|
||||||
if not tools:
|
hass.components.persistent_notification.create(
|
||||||
hass.components.persistent_notification.create(
|
"Your printer appears to be offline.<br />"
|
||||||
"Your printer appears to be offline.<br />"
|
"If you do not want to have your printer on <br />"
|
||||||
"If you do not want to have your printer on <br />"
|
" at all times, and you would like to monitor <br /> "
|
||||||
" at all times, and you would like to monitor <br /> "
|
"temperatures, please add <br />"
|
||||||
"temperatures, please add <br />"
|
"bed and/or number_of_tools to your configuration <br />"
|
||||||
"bed and/or number_of_tools to your configuration <br />"
|
"and restart.",
|
||||||
"and restart.",
|
title=NOTIFICATION_TITLE,
|
||||||
title=NOTIFICATION_TITLE,
|
notification_id=NOTIFICATION_ID,
|
||||||
notification_id=NOTIFICATION_ID,
|
)
|
||||||
)
|
|
||||||
|
|
||||||
devices = []
|
devices = []
|
||||||
types = ["actual", "target"]
|
types = ["actual", "target"]
|
||||||
|
|
|
@ -266,9 +266,8 @@ def get_entities(onewirehub: OneWireHub, config):
|
||||||
"""Get a list of entities."""
|
"""Get a list of entities."""
|
||||||
entities = []
|
entities = []
|
||||||
device_names = {}
|
device_names = {}
|
||||||
if CONF_NAMES in config:
|
if CONF_NAMES in config and isinstance(config[CONF_NAMES], dict):
|
||||||
if isinstance(config[CONF_NAMES], dict):
|
device_names = config[CONF_NAMES]
|
||||||
device_names = config[CONF_NAMES]
|
|
||||||
|
|
||||||
conf_type = config[CONF_TYPE]
|
conf_type = config[CONF_TYPE]
|
||||||
# We have an owserver on a remote(or local) host/port
|
# 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:
|
for person_conf in persons:
|
||||||
user_id = person_conf.get(CONF_USER_ID)
|
user_id = person_conf.get(CONF_USER_ID)
|
||||||
|
|
||||||
if user_id is not None:
|
if user_id is not None and await hass.auth.async_get_user(user_id) is None:
|
||||||
if await hass.auth.async_get_user(user_id) is None:
|
_LOGGER.error(
|
||||||
_LOGGER.error(
|
"Invalid user_id detected for person %s",
|
||||||
"Invalid user_id detected for person %s",
|
person_conf[collection.CONF_ID],
|
||||||
person_conf[collection.CONF_ID],
|
)
|
||||||
)
|
person_invalid_user.append(
|
||||||
person_invalid_user.append(
|
f"- Person {person_conf[CONF_NAME]} (id: {person_conf[collection.CONF_ID]}) points at invalid user {user_id}"
|
||||||
f"- Person {person_conf[CONF_NAME]} (id: {person_conf[collection.CONF_ID]}) points at invalid user {user_id}"
|
)
|
||||||
)
|
continue
|
||||||
continue
|
|
||||||
|
|
||||||
filtered.append(person_conf)
|
filtered.append(person_conf)
|
||||||
|
|
||||||
|
|
|
@ -170,9 +170,8 @@ class PhilipsTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Get the device state. An exception means OFF state."""
|
"""Get the device state. An exception means OFF state."""
|
||||||
if self._tv.on:
|
if self._tv.on and (self._tv.powerstate == "On" or self._tv.powerstate is None):
|
||||||
if self._tv.powerstate == "On" or self._tv.powerstate is None:
|
return STATE_ON
|
||||||
return STATE_ON
|
|
||||||
return STATE_OFF
|
return STATE_OFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -52,10 +52,9 @@ class PhilipsTVRemote(RemoteEntity):
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
if self._tv.on:
|
return bool(
|
||||||
if self._tv.powerstate == "On" or self._tv.powerstate is None:
|
self._tv.on and (self._tv.powerstate == "On" or self._tv.powerstate is None)
|
||||||
return True
|
)
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
|
|
|
@ -65,9 +65,11 @@ class PlaatoSensor(PlaatoEntity, SensorEntity):
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str | None:
|
def device_class(self) -> str | None:
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||||
if self._coordinator is not None:
|
if (
|
||||||
if self._sensor_type == PlaatoKeg.Pins.TEMPERATURE:
|
self._coordinator is not None
|
||||||
return DEVICE_CLASS_TEMPERATURE
|
and self._sensor_type == PlaatoKeg.Pins.TEMPERATURE
|
||||||
|
):
|
||||||
|
return DEVICE_CLASS_TEMPERATURE
|
||||||
if self._sensor_type == ATTR_TEMP:
|
if self._sensor_type == ATTR_TEMP:
|
||||||
return DEVICE_CLASS_TEMPERATURE
|
return DEVICE_CLASS_TEMPERATURE
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -365,17 +365,20 @@ class PlexServer:
|
||||||
PLAYER_SOURCE, source
|
PLAYER_SOURCE, source
|
||||||
)
|
)
|
||||||
|
|
||||||
if device.machineIdentifier not in ignored_clients:
|
if (
|
||||||
if self.option_ignore_plexweb_clients and device.product == "Plex Web":
|
device.machineIdentifier not in ignored_clients
|
||||||
ignored_clients.add(device.machineIdentifier)
|
and self.option_ignore_plexweb_clients
|
||||||
if device.machineIdentifier not in self._known_clients:
|
and device.product == "Plex Web"
|
||||||
_LOGGER.debug(
|
):
|
||||||
"Ignoring %s %s: %s",
|
ignored_clients.add(device.machineIdentifier)
|
||||||
"Plex Web",
|
if device.machineIdentifier not in self._known_clients:
|
||||||
source,
|
_LOGGER.debug(
|
||||||
device.machineIdentifier,
|
"Ignoring %s %s: %s",
|
||||||
)
|
"Plex Web",
|
||||||
return
|
source,
|
||||||
|
device.machineIdentifier,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
if device.machineIdentifier not in (
|
if device.machineIdentifier not in (
|
||||||
self._created_clients | ignored_clients | new_clients
|
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()
|
api.get_all_devices()
|
||||||
|
|
||||||
if entry.unique_id is None:
|
if entry.unique_id is None and api.smile_version[0] != "1.8.0":
|
||||||
if api.smile_version[0] != "1.8.0":
|
hass.config_entries.async_update_entry(entry, unique_id=api.smile_hostname)
|
||||||
hass.config_entries.async_update_entry(entry, unique_id=api.smile_hostname)
|
|
||||||
|
|
||||||
undo_listener = entry.add_update_listener(_update_listener)
|
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()
|
response = reader.get_network_info()
|
||||||
|
|
||||||
# Branch to test if target is Legacy Model
|
# Branch to test if target is Legacy Model
|
||||||
if "NetworkInfo" in response:
|
if (
|
||||||
if response["NetworkInfo"].get("ModelId", None) == "Z109-EAGLE":
|
"NetworkInfo" in response
|
||||||
return reader
|
and response["NetworkInfo"].get("ModelId", None) == "Z109-EAGLE"
|
||||||
|
):
|
||||||
|
return reader
|
||||||
|
|
||||||
# Branch to test if target is Eagle-200 Model
|
# Branch to test if target is Eagle-200 Model
|
||||||
if "Response" in response:
|
if (
|
||||||
if response["Response"].get("Command", None) == "get_network_info":
|
"Response" in response
|
||||||
return EagleReader(ip_address, cloud_id, install_code)
|
and response["Response"].get("Command", None) == "get_network_info"
|
||||||
|
):
|
||||||
|
return EagleReader(ip_address, cloud_id, install_code)
|
||||||
|
|
||||||
# Catch-all if hardware ID tests fail
|
# Catch-all if hardware ID tests fail
|
||||||
raise ValueError("Couldn't determine device model.")
|
raise ValueError("Couldn't determine device model.")
|
||||||
|
|
|
@ -304,11 +304,7 @@ class Recorder(threading.Thread):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
entity_id = event.data.get(ATTR_ENTITY_ID)
|
entity_id = event.data.get(ATTR_ENTITY_ID)
|
||||||
if entity_id is not None:
|
return bool(entity_id is None or self.entity_filter(entity_id))
|
||||||
if not self.entity_filter(entity_id):
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def do_adhoc_purge(self, **kwargs):
|
def do_adhoc_purge(self, **kwargs):
|
||||||
"""Trigger an adhoc purge retaining keep_days worth of data."""
|
"""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 = []
|
missing = []
|
||||||
|
|
||||||
for entity in registry.entities.values():
|
for entity in registry.entities.values():
|
||||||
if entity.config_entry_id == entry.entry_id and entity.platform == DOMAIN:
|
if (
|
||||||
if entity.unique_id not in coordinator.data[API_CLIENTS]:
|
entity.config_entry_id == entry.entry_id
|
||||||
missing.append(
|
and entity.platform == DOMAIN
|
||||||
RuckusUnleashedDevice(
|
and entity.unique_id not in coordinator.data[API_CLIENTS]
|
||||||
coordinator, entity.unique_id, entity.original_name
|
):
|
||||||
)
|
missing.append(
|
||||||
|
RuckusUnleashedDevice(
|
||||||
|
coordinator, entity.unique_id, entity.original_name
|
||||||
)
|
)
|
||||||
tracked.add(entity.unique_id)
|
)
|
||||||
|
tracked.add(entity.unique_id)
|
||||||
|
|
||||||
if missing:
|
if missing:
|
||||||
async_add_entities(missing)
|
async_add_entities(missing)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue