Merge of nested IF-IF cases - E-G (#48367)

This commit is contained in:
Franck Nijhof 2021-03-27 12:39:37 +01:00 committed by GitHub
parent 786023fce4
commit 0d595a2845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 257 additions and 246 deletions

View File

@ -115,8 +115,7 @@ class EbusdData:
try:
_LOGGER.debug("Opening socket to ebusd %s", name)
command_result = ebusdpy.write(self._address, self._circuit, name, value)
if command_result is not None:
if "done" not in command_result:
if command_result is not None and "done" not in command_result:
_LOGGER.warning("Write command failed: %s", name)
except RuntimeError as err:
_LOGGER.error(err)

View File

@ -170,8 +170,11 @@ class Monitor:
)
for dev in self.devices:
if dev.namespace == namespace and dev.instance == instance:
if dev.temperature != temperature:
if (
dev.namespace == namespace
and dev.instance == instance
and dev.temperature != temperature
):
dev.temperature = temperature
dev.schedule_update_ha_state()

View File

@ -96,8 +96,9 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
active_emby_devices[dev_id] = new
new_devices.append(new)
elif dev_id in inactive_emby_devices:
if emby.devices[dev_id].state != "Off":
elif (
dev_id in inactive_emby_devices and emby.devices[dev_id].state != "Off"
):
add = inactive_emby_devices.pop(dev_id)
active_emby_devices[dev_id] = add
_LOGGER.debug("Showing %s, item: %s", dev_id, add)

View File

@ -92,12 +92,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for elem in data.data:
if exclude_feeds is not None:
if int(elem["id"]) in exclude_feeds:
if exclude_feeds is not None and int(elem["id"]) in exclude_feeds:
continue
if include_only_feeds is not None:
if int(elem["id"]) not in include_only_feeds:
if include_only_feeds is not None and int(elem["id"]) not in include_only_feeds:
continue
name = None

View File

@ -439,8 +439,10 @@ class HueOneLightChangeView(HomeAssistantView):
# saturation and color temp
if entity.domain == light.DOMAIN:
if parsed[STATE_ON]:
if entity_features & SUPPORT_BRIGHTNESS:
if parsed[STATE_BRIGHTNESS] is not None:
if (
entity_features & SUPPORT_BRIGHTNESS
and parsed[STATE_BRIGHTNESS] is not None
):
data[ATTR_BRIGHTNESS] = hue_brightness_to_hass(
parsed[STATE_BRIGHTNESS]
)
@ -466,12 +468,16 @@ class HueOneLightChangeView(HomeAssistantView):
if parsed[STATE_XY] is not None:
data[ATTR_XY_COLOR] = parsed[STATE_XY]
if entity_features & SUPPORT_COLOR_TEMP:
if parsed[STATE_COLOR_TEMP] is not None:
if (
entity_features & SUPPORT_COLOR_TEMP
and parsed[STATE_COLOR_TEMP] is not None
):
data[ATTR_COLOR_TEMP] = parsed[STATE_COLOR_TEMP]
if entity_features & SUPPORT_TRANSITION:
if parsed[STATE_TRANSITON] is not None:
if (
entity_features & SUPPORT_TRANSITION
and parsed[STATE_TRANSITON] is not None
):
data[ATTR_TRANSITION] = parsed[STATE_TRANSITON] / 10
# If the requested entity is a script, add some variables
@ -489,8 +495,10 @@ class HueOneLightChangeView(HomeAssistantView):
# only setting the temperature
service = None
if entity_features & SUPPORT_TARGET_TEMPERATURE:
if parsed[STATE_BRIGHTNESS] is not None:
if (
entity_features & SUPPORT_TARGET_TEMPERATURE
and parsed[STATE_BRIGHTNESS] is not None
):
domain = entity.domain
service = SERVICE_SET_TEMPERATURE
data[ATTR_TEMPERATURE] = parsed[STATE_BRIGHTNESS]
@ -505,8 +513,10 @@ class HueOneLightChangeView(HomeAssistantView):
# If the requested entity is a media player, convert to volume
elif entity.domain == media_player.DOMAIN:
if entity_features & SUPPORT_VOLUME_SET:
if parsed[STATE_BRIGHTNESS] is not None:
if (
entity_features & SUPPORT_VOLUME_SET
and parsed[STATE_BRIGHTNESS] is not None
):
turn_on_needed = True
domain = entity.domain
service = SERVICE_VOLUME_SET
@ -516,21 +526,24 @@ class HueOneLightChangeView(HomeAssistantView):
# If the requested entity is a cover, convert to open_cover/close_cover
elif entity.domain == cover.DOMAIN:
domain = entity.domain
service = SERVICE_CLOSE_COVER
if service == SERVICE_TURN_ON:
service = SERVICE_OPEN_COVER
else:
service = SERVICE_CLOSE_COVER
if entity_features & SUPPORT_SET_POSITION:
if parsed[STATE_BRIGHTNESS] is not None:
if (
entity_features & SUPPORT_SET_POSITION
and parsed[STATE_BRIGHTNESS] is not None
):
domain = entity.domain
service = SERVICE_SET_COVER_POSITION
data[ATTR_POSITION] = parsed[STATE_BRIGHTNESS]
# If the requested entity is a fan, convert to speed
elif entity.domain == fan.DOMAIN:
if entity_features & SUPPORT_SET_SPEED:
if parsed[STATE_BRIGHTNESS] is not None:
elif (
entity.domain == fan.DOMAIN
and entity_features & SUPPORT_SET_SPEED
and parsed[STATE_BRIGHTNESS] is not None
):
domain = entity.domain
# Convert 0-100 to a fan speed
brightness = parsed[STATE_BRIGHTNESS]

View File

@ -90,8 +90,10 @@ class BanSensor(SensorEntity):
if len(self.ban_dict[STATE_ALL_BANS]) > 10:
self.ban_dict[STATE_ALL_BANS].pop(0)
elif entry[0] == "Unban":
if current_ip in self.ban_dict[STATE_CURRENT_BANS]:
elif (
entry[0] == "Unban"
and current_ip in self.ban_dict[STATE_CURRENT_BANS]
):
self.ban_dict[STATE_CURRENT_BANS].remove(current_ip)
if self.ban_dict[STATE_CURRENT_BANS]:

View File

@ -459,8 +459,7 @@ class FanEntity(ToggleEntity):
@property
def percentage(self) -> int | None:
"""Return the current speed as a percentage."""
if not self._implemented_preset_mode:
if self.speed in self.preset_modes:
if not self._implemented_preset_mode and self.speed in self.preset_modes:
return None
if not self._implemented_percentage:
return self.speed_to_percentage(self.speed)

View File

@ -120,8 +120,7 @@ class GaradgetCover(CoverEntity):
def __del__(self):
"""Try to remove token."""
if self._obtained_token is True:
if self.access_token is not None:
if self._obtained_token is True and self.access_token is not None:
self.remove_token()
@property
@ -239,8 +238,10 @@ class GaradgetCover(CoverEntity):
)
self._state = STATE_OFFLINE
if self._state not in [STATE_CLOSING, STATE_OPENING]:
if self._unsub_listener_cover is not None:
if (
self._state not in [STATE_CLOSING, STATE_OPENING]
and self._unsub_listener_cover is not None
):
self._unsub_listener_cover()
self._unsub_listener_cover = None

View File

@ -442,12 +442,11 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
if not self._active or self._hvac_mode == HVAC_MODE_OFF:
return
if not force and time is None:
# If the `force` argument is True, we
# ignore `min_cycle_duration`.
# If the `time` argument is not none, we were invoked for
# keep-alive purposes, and `min_cycle_duration` is irrelevant.
if self.min_cycle_duration:
if not force and time is None and self.min_cycle_duration:
if self._is_device_active:
current_state = STATE_ON
else:

View File

@ -17,7 +17,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
for sensor_type, sensor_details in SENSOR_TYPES.items():
if sensor_details[0] not in client.api.data:
continue
if sensor_details[0] in client.api.data:
if sensor_details[0] == "fs":
# fs will provide a list of disks attached
for disk in client.api.data[sensor_details[0]]:
@ -139,17 +138,12 @@ class GlancesSensor(SensorEntity):
if value is None:
return
if value is not None:
if self.sensor_details[0] == "fs":
for var in value["fs"]:
if var["mnt_point"] == self._sensor_name_prefix:
disk = var
break
if self.type == "disk_use_percent":
self._state = disk["percent"]
elif self.type == "disk_use":
self._state = round(disk["used"] / 1024 ** 3, 1)
elif self.type == "disk_free":
if self.type == "disk_free":
try:
self._state = round(disk["free"] / 1024 ** 3, 1)
except KeyError:
@ -157,20 +151,30 @@ class GlancesSensor(SensorEntity):
(disk["size"] - disk["used"]) / 1024 ** 3,
1,
)
elif self.type == "disk_use":
self._state = round(disk["used"] / 1024 ** 3, 1)
elif self.type == "disk_use_percent":
self._state = disk["percent"]
elif self.type == "battery":
for sensor in value["sensors"]:
if sensor["type"] == "battery":
if sensor["label"] == self._sensor_name_prefix:
if (
sensor["type"] == "battery"
and sensor["label"] == self._sensor_name_prefix
):
self._state = sensor["value"]
elif self.type == "fan_speed":
for sensor in value["sensors"]:
if sensor["type"] == "fan_speed":
if sensor["label"] == self._sensor_name_prefix:
if (
sensor["type"] == "fan_speed"
and sensor["label"] == self._sensor_name_prefix
):
self._state = sensor["value"]
elif self.type == "temperature_core":
for sensor in value["sensors"]:
if sensor["type"] == "temperature_core":
if sensor["label"] == self._sensor_name_prefix:
if (
sensor["type"] == "temperature_core"
and sensor["label"] == self._sensor_name_prefix
):
self._state = sensor["value"]
elif self.type == "temperature_hdd":
for sensor in value["sensors"]:
@ -211,10 +215,7 @@ class GlancesSensor(SensorEntity):
count = 0
try:
for container in value["docker"]["containers"]:
if (
container["Status"] == "running"
or "Up" in container["Status"]
):
if container["Status"] == "running" or "Up" in container["Status"]:
count += 1
self._state = count
except KeyError:
@ -223,10 +224,7 @@ class GlancesSensor(SensorEntity):
cpu_use = 0.0
try:
for container in value["docker"]["containers"]:
if (
container["Status"] == "running"
or "Up" in container["Status"]
):
if container["Status"] == "running" or "Up" in container["Status"]:
cpu_use += container["cpu"]["total"]
self._state = round(cpu_use, 1)
except KeyError:
@ -235,10 +233,7 @@ class GlancesSensor(SensorEntity):
mem_use = 0.0
try:
for container in value["docker"]["containers"]:
if (
container["Status"] == "running"
or "Up" in container["Status"]
):
if container["Status"] == "running" or "Up" in container["Status"]:
mem_use += container["memory"]["usage"]
self._state = round(mem_use / 1024 ** 2, 1)
except KeyError:

View File

@ -1428,8 +1428,7 @@ class ModesTrait(_Trait):
elif self.state.domain == humidifier.DOMAIN:
if ATTR_MODE in attrs:
mode_settings["mode"] = attrs.get(ATTR_MODE)
elif self.state.domain == light.DOMAIN:
if light.ATTR_EFFECT in attrs:
elif self.state.domain == light.DOMAIN and light.ATTR_EFFECT in attrs:
mode_settings["effect"] = attrs.get(light.ATTR_EFFECT)
if mode_settings:
@ -1618,8 +1617,10 @@ class OpenCloseTrait(_Trait):
if self.state.domain == binary_sensor.DOMAIN:
response["queryOnlyOpenClose"] = True
response["discreteOnlyOpenClose"] = True
elif self.state.domain == cover.DOMAIN:
if features & cover.SUPPORT_SET_POSITION == 0:
elif (
self.state.domain == cover.DOMAIN
and features & cover.SUPPORT_SET_POSITION == 0
):
response["discreteOnlyOpenClose"] = True
if (

View File

@ -175,8 +175,9 @@ class GoogleWifiAPI:
sensor_value = "Online"
else:
sensor_value = "Offline"
elif attr_key == ATTR_LOCAL_IP:
if not self.raw_data["wan"]["online"]:
elif (
attr_key == ATTR_LOCAL_IP and not self.raw_data["wan"]["online"]
):
sensor_value = STATE_UNKNOWN
self.data[attr_key] = sensor_value

View File

@ -227,8 +227,7 @@ class GPMDP(MediaPlayerEntity):
return
while True:
msg = json.loads(websocket.recv())
if "requestID" in msg:
if msg["requestID"] == self._request_id:
if "requestID" in msg and msg["requestID"] == self._request_id:
return msg
except (
ConnectionRefusedError,