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: try:
_LOGGER.debug("Opening socket to ebusd %s", name) _LOGGER.debug("Opening socket to ebusd %s", name)
command_result = ebusdpy.write(self._address, self._circuit, name, value) command_result = ebusdpy.write(self._address, self._circuit, name, value)
if command_result is not None: if command_result is not None and "done" not in command_result:
if "done" not in command_result:
_LOGGER.warning("Write command failed: %s", name) _LOGGER.warning("Write command failed: %s", name)
except RuntimeError as err: except RuntimeError as err:
_LOGGER.error(err) _LOGGER.error(err)

View File

@ -170,8 +170,11 @@ class Monitor:
) )
for dev in self.devices: for dev in self.devices:
if dev.namespace == namespace and dev.instance == instance: if (
if dev.temperature != temperature: dev.namespace == namespace
and dev.instance == instance
and dev.temperature != temperature
):
dev.temperature = temperature dev.temperature = temperature
dev.schedule_update_ha_state() 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 active_emby_devices[dev_id] = new
new_devices.append(new) new_devices.append(new)
elif dev_id in inactive_emby_devices: elif (
if emby.devices[dev_id].state != "Off": dev_id in inactive_emby_devices and emby.devices[dev_id].state != "Off"
):
add = inactive_emby_devices.pop(dev_id) add = inactive_emby_devices.pop(dev_id)
active_emby_devices[dev_id] = add active_emby_devices[dev_id] = add
_LOGGER.debug("Showing %s, item: %s", 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: for elem in data.data:
if exclude_feeds is not None: if exclude_feeds is not None and int(elem["id"]) in exclude_feeds:
if int(elem["id"]) in exclude_feeds:
continue continue
if include_only_feeds is not None: if include_only_feeds is not None and int(elem["id"]) not in include_only_feeds:
if int(elem["id"]) not in include_only_feeds:
continue continue
name = None name = None

View File

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

View File

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

View File

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

View File

@ -120,8 +120,7 @@ class GaradgetCover(CoverEntity):
def __del__(self): def __del__(self):
"""Try to remove token.""" """Try to remove token."""
if self._obtained_token is True: if self._obtained_token is True and self.access_token is not None:
if self.access_token is not None:
self.remove_token() self.remove_token()
@property @property
@ -239,8 +238,10 @@ class GaradgetCover(CoverEntity):
) )
self._state = STATE_OFFLINE self._state = STATE_OFFLINE
if self._state not in [STATE_CLOSING, STATE_OPENING]: if (
if self._unsub_listener_cover is not None: self._state not in [STATE_CLOSING, STATE_OPENING]
and self._unsub_listener_cover is not None
):
self._unsub_listener_cover() self._unsub_listener_cover()
self._unsub_listener_cover = None 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: if not self._active or self._hvac_mode == HVAC_MODE_OFF:
return return
if not force and time is None:
# If the `force` argument is True, we # If the `force` argument is True, we
# ignore `min_cycle_duration`. # ignore `min_cycle_duration`.
# If the `time` argument is not none, we were invoked for # If the `time` argument is not none, we were invoked for
# keep-alive purposes, and `min_cycle_duration` is irrelevant. # 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: if self._is_device_active:
current_state = STATE_ON current_state = STATE_ON
else: 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(): for sensor_type, sensor_details in SENSOR_TYPES.items():
if sensor_details[0] not in client.api.data: if sensor_details[0] not in client.api.data:
continue continue
if sensor_details[0] in client.api.data:
if sensor_details[0] == "fs": if sensor_details[0] == "fs":
# fs will provide a list of disks attached # fs will provide a list of disks attached
for disk in client.api.data[sensor_details[0]]: for disk in client.api.data[sensor_details[0]]:
@ -139,17 +138,12 @@ class GlancesSensor(SensorEntity):
if value is None: if value is None:
return return
if value is not None:
if self.sensor_details[0] == "fs": if self.sensor_details[0] == "fs":
for var in value["fs"]: for var in value["fs"]:
if var["mnt_point"] == self._sensor_name_prefix: if var["mnt_point"] == self._sensor_name_prefix:
disk = var disk = var
break break
if self.type == "disk_use_percent": if self.type == "disk_free":
self._state = disk["percent"]
elif self.type == "disk_use":
self._state = round(disk["used"] / 1024 ** 3, 1)
elif self.type == "disk_free":
try: try:
self._state = round(disk["free"] / 1024 ** 3, 1) self._state = round(disk["free"] / 1024 ** 3, 1)
except KeyError: except KeyError:
@ -157,20 +151,30 @@ class GlancesSensor(SensorEntity):
(disk["size"] - disk["used"]) / 1024 ** 3, (disk["size"] - disk["used"]) / 1024 ** 3,
1, 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": elif self.type == "battery":
for sensor in value["sensors"]: for sensor in value["sensors"]:
if sensor["type"] == "battery": if (
if sensor["label"] == self._sensor_name_prefix: sensor["type"] == "battery"
and sensor["label"] == self._sensor_name_prefix
):
self._state = sensor["value"] self._state = sensor["value"]
elif self.type == "fan_speed": elif self.type == "fan_speed":
for sensor in value["sensors"]: for sensor in value["sensors"]:
if sensor["type"] == "fan_speed": if (
if sensor["label"] == self._sensor_name_prefix: sensor["type"] == "fan_speed"
and sensor["label"] == self._sensor_name_prefix
):
self._state = sensor["value"] self._state = sensor["value"]
elif self.type == "temperature_core": elif self.type == "temperature_core":
for sensor in value["sensors"]: for sensor in value["sensors"]:
if sensor["type"] == "temperature_core": if (
if sensor["label"] == self._sensor_name_prefix: sensor["type"] == "temperature_core"
and sensor["label"] == self._sensor_name_prefix
):
self._state = sensor["value"] self._state = sensor["value"]
elif self.type == "temperature_hdd": elif self.type == "temperature_hdd":
for sensor in value["sensors"]: for sensor in value["sensors"]:
@ -211,10 +215,7 @@ class GlancesSensor(SensorEntity):
count = 0 count = 0
try: try:
for container in value["docker"]["containers"]: for container in value["docker"]["containers"]:
if ( if container["Status"] == "running" or "Up" in container["Status"]:
container["Status"] == "running"
or "Up" in container["Status"]
):
count += 1 count += 1
self._state = count self._state = count
except KeyError: except KeyError:
@ -223,10 +224,7 @@ class GlancesSensor(SensorEntity):
cpu_use = 0.0 cpu_use = 0.0
try: try:
for container in value["docker"]["containers"]: for container in value["docker"]["containers"]:
if ( if container["Status"] == "running" or "Up" in container["Status"]:
container["Status"] == "running"
or "Up" in container["Status"]
):
cpu_use += container["cpu"]["total"] cpu_use += container["cpu"]["total"]
self._state = round(cpu_use, 1) self._state = round(cpu_use, 1)
except KeyError: except KeyError:
@ -235,10 +233,7 @@ class GlancesSensor(SensorEntity):
mem_use = 0.0 mem_use = 0.0
try: try:
for container in value["docker"]["containers"]: for container in value["docker"]["containers"]:
if ( if container["Status"] == "running" or "Up" in container["Status"]:
container["Status"] == "running"
or "Up" in container["Status"]
):
mem_use += container["memory"]["usage"] mem_use += container["memory"]["usage"]
self._state = round(mem_use / 1024 ** 2, 1) self._state = round(mem_use / 1024 ** 2, 1)
except KeyError: except KeyError:

View File

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

View File

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

View File

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