From 0d595a28457f89948c2a697bfc9bf576f1af5e60 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 27 Mar 2021 12:39:37 +0100 Subject: [PATCH] Merge of nested IF-IF cases - E-G (#48367) --- homeassistant/components/ebusd/__init__.py | 5 +- .../eddystone_temperature/sensor.py | 11 +- homeassistant/components/emby/media_player.py | 13 +- homeassistant/components/emoncms/sensor.py | 10 +- .../components/emulated_hue/hue_api.py | 101 ++++--- homeassistant/components/fail2ban/sensor.py | 8 +- homeassistant/components/fan/__init__.py | 5 +- homeassistant/components/garadget/cover.py | 15 +- .../components/generic_thermostat/climate.py | 41 ++- homeassistant/components/glances/sensor.py | 259 +++++++++--------- .../components/google_assistant/trait.py | 23 +- .../components/google_wifi/sensor.py | 7 +- .../components/gpmdp/media_player.py | 5 +- 13 files changed, 257 insertions(+), 246 deletions(-) diff --git a/homeassistant/components/ebusd/__init__.py b/homeassistant/components/ebusd/__init__.py index 00c40344d6e..beb8abd6289 100644 --- a/homeassistant/components/ebusd/__init__.py +++ b/homeassistant/components/ebusd/__init__.py @@ -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: - _LOGGER.warning("Write command failed: %s", name) + 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) diff --git a/homeassistant/components/eddystone_temperature/sensor.py b/homeassistant/components/eddystone_temperature/sensor.py index 70afde4ffb1..28711821f50 100644 --- a/homeassistant/components/eddystone_temperature/sensor.py +++ b/homeassistant/components/eddystone_temperature/sensor.py @@ -170,10 +170,13 @@ class Monitor: ) for dev in self.devices: - if dev.namespace == namespace and dev.instance == instance: - if dev.temperature != temperature: - dev.temperature = temperature - dev.schedule_update_ha_state() + if ( + dev.namespace == namespace + and dev.instance == instance + and dev.temperature != temperature + ): + dev.temperature = temperature + dev.schedule_update_ha_state() def stop(self): """Signal runner to stop and join thread.""" diff --git a/homeassistant/components/emby/media_player.py b/homeassistant/components/emby/media_player.py index 1cbc893f98b..5656a1f1486 100644 --- a/homeassistant/components/emby/media_player.py +++ b/homeassistant/components/emby/media_player.py @@ -96,12 +96,13 @@ 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": - add = inactive_emby_devices.pop(dev_id) - active_emby_devices[dev_id] = add - _LOGGER.debug("Showing %s, item: %s", dev_id, add) - add.set_available(True) + 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) + add.set_available(True) if new_devices: _LOGGER.debug("Adding new devices: %s", new_devices) diff --git a/homeassistant/components/emoncms/sensor.py b/homeassistant/components/emoncms/sensor.py index 4913f6340cc..bfc86db387e 100644 --- a/homeassistant/components/emoncms/sensor.py +++ b/homeassistant/components/emoncms/sensor.py @@ -92,13 +92,11 @@ 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: - continue + 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: - continue + if include_only_feeds is not None and int(elem["id"]) not in include_only_feeds: + continue name = None if sensor_names is not None: diff --git a/homeassistant/components/emulated_hue/hue_api.py b/homeassistant/components/emulated_hue/hue_api.py index 647d9db1335..f97636a46c0 100644 --- a/homeassistant/components/emulated_hue/hue_api.py +++ b/homeassistant/components/emulated_hue/hue_api.py @@ -439,11 +439,13 @@ 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: - data[ATTR_BRIGHTNESS] = hue_brightness_to_hass( - parsed[STATE_BRIGHTNESS] - ) + if ( + entity_features & SUPPORT_BRIGHTNESS + and parsed[STATE_BRIGHTNESS] is not None + ): + data[ATTR_BRIGHTNESS] = hue_brightness_to_hass( + parsed[STATE_BRIGHTNESS] + ) if entity_features & SUPPORT_COLOR: if any((parsed[STATE_HUE], parsed[STATE_SATURATION])): @@ -466,13 +468,17 @@ 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: - data[ATTR_COLOR_TEMP] = parsed[STATE_COLOR_TEMP] + 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: - data[ATTR_TRANSITION] = parsed[STATE_TRANSITON] / 10 + 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 elif entity.domain == script.DOMAIN: @@ -489,11 +495,13 @@ class HueOneLightChangeView(HomeAssistantView): # only setting the temperature service = None - if entity_features & SUPPORT_TARGET_TEMPERATURE: - if parsed[STATE_BRIGHTNESS] is not None: - domain = entity.domain - service = SERVICE_SET_TEMPERATURE - data[ATTR_TEMPERATURE] = parsed[STATE_BRIGHTNESS] + 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] # If the requested entity is a humidifier, set the humidity elif entity.domain == humidifier.DOMAIN: @@ -505,43 +513,48 @@ 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: - turn_on_needed = True - domain = entity.domain - service = SERVICE_VOLUME_SET - # Convert 0-100 to 0.0-1.0 - data[ATTR_MEDIA_VOLUME_LEVEL] = parsed[STATE_BRIGHTNESS] / 100.0 + if ( + entity_features & SUPPORT_VOLUME_SET + and parsed[STATE_BRIGHTNESS] is not None + ): + turn_on_needed = True + domain = entity.domain + service = SERVICE_VOLUME_SET + # Convert 0-100 to 0.0-1.0 + data[ATTR_MEDIA_VOLUME_LEVEL] = parsed[STATE_BRIGHTNESS] / 100.0 # 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: - domain = entity.domain - service = SERVICE_SET_COVER_POSITION - data[ATTR_POSITION] = parsed[STATE_BRIGHTNESS] + 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: - domain = entity.domain - # Convert 0-100 to a fan speed - brightness = parsed[STATE_BRIGHTNESS] - if brightness == 0: - data[ATTR_SPEED] = SPEED_OFF - elif 0 < brightness <= 33.3: - data[ATTR_SPEED] = SPEED_LOW - elif 33.3 < brightness <= 66.6: - data[ATTR_SPEED] = SPEED_MEDIUM - elif 66.6 < brightness <= 100: - data[ATTR_SPEED] = SPEED_HIGH + 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] + if brightness == 0: + data[ATTR_SPEED] = SPEED_OFF + elif 0 < brightness <= 33.3: + data[ATTR_SPEED] = SPEED_LOW + elif 33.3 < brightness <= 66.6: + data[ATTR_SPEED] = SPEED_MEDIUM + elif 66.6 < brightness <= 100: + data[ATTR_SPEED] = SPEED_HIGH # Map the off command to on if entity.domain in config.off_maps_to_on_domains: diff --git a/homeassistant/components/fail2ban/sensor.py b/homeassistant/components/fail2ban/sensor.py index 87a8460f149..29ac5c3d0b5 100644 --- a/homeassistant/components/fail2ban/sensor.py +++ b/homeassistant/components/fail2ban/sensor.py @@ -90,9 +90,11 @@ 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]: - self.ban_dict[STATE_CURRENT_BANS].remove(current_ip) + 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]: self.last_ban = self.ban_dict[STATE_CURRENT_BANS][-1] diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index da2224aaf33..305c99072ab 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -459,9 +459,8 @@ 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: - return None + 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) return 0 diff --git a/homeassistant/components/garadget/cover.py b/homeassistant/components/garadget/cover.py index 206aaa6614d..ad89c3a035b 100644 --- a/homeassistant/components/garadget/cover.py +++ b/homeassistant/components/garadget/cover.py @@ -120,9 +120,8 @@ class GaradgetCover(CoverEntity): def __del__(self): """Try to remove token.""" - if self._obtained_token is True: - if self.access_token is not None: - self.remove_token() + if self._obtained_token is True and self.access_token is not None: + self.remove_token() @property def name(self): @@ -239,10 +238,12 @@ class GaradgetCover(CoverEntity): ) self._state = STATE_OFFLINE - if self._state not in [STATE_CLOSING, STATE_OPENING]: - if self._unsub_listener_cover is not None: - self._unsub_listener_cover() - self._unsub_listener_cover = 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 def _get_variable(self, var): """Get latest status.""" diff --git a/homeassistant/components/generic_thermostat/climate.py b/homeassistant/components/generic_thermostat/climate.py index 3c7959dbf4d..ef3cf11fa1c 100644 --- a/homeassistant/components/generic_thermostat/climate.py +++ b/homeassistant/components/generic_thermostat/climate.py @@ -442,28 +442,27 @@ 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 self._is_device_active: - current_state = STATE_ON - else: - current_state = HVAC_MODE_OFF - try: - long_enough = condition.state( - self.hass, - self.heater_entity_id, - current_state, - self.min_cycle_duration, - ) - except ConditionError: - long_enough = False + # 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 not force and time is None and self.min_cycle_duration: + if self._is_device_active: + current_state = STATE_ON + else: + current_state = HVAC_MODE_OFF + try: + long_enough = condition.state( + self.hass, + self.heater_entity_id, + current_state, + self.min_cycle_duration, + ) + except ConditionError: + long_enough = False - if not long_enough: - return + if not long_enough: + return too_cold = self._target_temp >= self._cur_temp + self._cold_tolerance too_hot = self._cur_temp >= self._target_temp + self._hot_tolerance diff --git a/homeassistant/components/glances/sensor.py b/homeassistant/components/glances/sensor.py index 52649518b68..bbe045eb232 100644 --- a/homeassistant/components/glances/sensor.py +++ b/homeassistant/components/glances/sensor.py @@ -17,45 +17,44 @@ 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]]: - dev.append( - GlancesSensor( - client, - name, - disk["mnt_point"], - SENSOR_TYPES[sensor_type][1], - sensor_type, - SENSOR_TYPES[sensor_type], - ) - ) - elif sensor_details[0] == "sensors": - # sensors will provide temp for different devices - for sensor in client.api.data[sensor_details[0]]: - if sensor["type"] == sensor_type: - dev.append( - GlancesSensor( - client, - name, - sensor["label"], - SENSOR_TYPES[sensor_type][1], - sensor_type, - SENSOR_TYPES[sensor_type], - ) - ) - elif client.api.data[sensor_details[0]]: + if sensor_details[0] == "fs": + # fs will provide a list of disks attached + for disk in client.api.data[sensor_details[0]]: dev.append( GlancesSensor( client, name, - "", + disk["mnt_point"], SENSOR_TYPES[sensor_type][1], sensor_type, SENSOR_TYPES[sensor_type], ) ) + elif sensor_details[0] == "sensors": + # sensors will provide temp for different devices + for sensor in client.api.data[sensor_details[0]]: + if sensor["type"] == sensor_type: + dev.append( + GlancesSensor( + client, + name, + sensor["label"], + SENSOR_TYPES[sensor_type][1], + sensor_type, + SENSOR_TYPES[sensor_type], + ) + ) + elif client.api.data[sensor_details[0]]: + dev.append( + GlancesSensor( + client, + name, + "", + SENSOR_TYPES[sensor_type][1], + sensor_type, + SENSOR_TYPES[sensor_type], + ) + ) async_add_entities(dev, True) @@ -139,107 +138,103 @@ 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": - try: - self._state = round(disk["free"] / 1024 ** 3, 1) - except KeyError: - self._state = round( - (disk["size"] - disk["used"]) / 1024 ** 3, - 1, - ) - elif self.type == "battery": - for sensor in value["sensors"]: - if sensor["type"] == "battery": - if 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: - 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: - self._state = sensor["value"] - elif self.type == "temperature_hdd": - for sensor in value["sensors"]: - if ( - sensor["type"] == "temperature_hdd" - and sensor["label"] == self._sensor_name_prefix - ): - self._state = sensor["value"] - elif self.type == "memory_use_percent": - self._state = value["mem"]["percent"] - elif self.type == "memory_use": - self._state = round(value["mem"]["used"] / 1024 ** 2, 1) - elif self.type == "memory_free": - self._state = round(value["mem"]["free"] / 1024 ** 2, 1) - elif self.type == "swap_use_percent": - self._state = value["memswap"]["percent"] - elif self.type == "swap_use": - self._state = round(value["memswap"]["used"] / 1024 ** 3, 1) - elif self.type == "swap_free": - self._state = round(value["memswap"]["free"] / 1024 ** 3, 1) - elif self.type == "processor_load": - # Windows systems don't provide load details + 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_free": try: - self._state = value["load"]["min15"] + self._state = round(disk["free"] / 1024 ** 3, 1) except KeyError: - self._state = value["cpu"]["total"] - elif self.type == "process_running": - self._state = value["processcount"]["running"] - elif self.type == "process_total": - self._state = value["processcount"]["total"] - elif self.type == "process_thread": - self._state = value["processcount"]["thread"] - elif self.type == "process_sleeping": - self._state = value["processcount"]["sleeping"] - elif self.type == "cpu_use_percent": - self._state = value["quicklook"]["cpu"] - elif self.type == "docker_active": - count = 0 - try: - for container in value["docker"]["containers"]: - if ( - container["Status"] == "running" - or "Up" in container["Status"] - ): - count += 1 - self._state = count - except KeyError: - self._state = count - elif self.type == "docker_cpu_use": - cpu_use = 0.0 - try: - for container in value["docker"]["containers"]: - if ( - container["Status"] == "running" - or "Up" in container["Status"] - ): - cpu_use += container["cpu"]["total"] - self._state = round(cpu_use, 1) - except KeyError: - self._state = STATE_UNAVAILABLE - elif self.type == "docker_memory_use": - mem_use = 0.0 - try: - for container in value["docker"]["containers"]: - if ( - container["Status"] == "running" - or "Up" in container["Status"] - ): - mem_use += container["memory"]["usage"] - self._state = round(mem_use / 1024 ** 2, 1) - except KeyError: - self._state = STATE_UNAVAILABLE + self._state = round( + (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" + 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" + 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" + and sensor["label"] == self._sensor_name_prefix + ): + self._state = sensor["value"] + elif self.type == "temperature_hdd": + for sensor in value["sensors"]: + if ( + sensor["type"] == "temperature_hdd" + and sensor["label"] == self._sensor_name_prefix + ): + self._state = sensor["value"] + elif self.type == "memory_use_percent": + self._state = value["mem"]["percent"] + elif self.type == "memory_use": + self._state = round(value["mem"]["used"] / 1024 ** 2, 1) + elif self.type == "memory_free": + self._state = round(value["mem"]["free"] / 1024 ** 2, 1) + elif self.type == "swap_use_percent": + self._state = value["memswap"]["percent"] + elif self.type == "swap_use": + self._state = round(value["memswap"]["used"] / 1024 ** 3, 1) + elif self.type == "swap_free": + self._state = round(value["memswap"]["free"] / 1024 ** 3, 1) + elif self.type == "processor_load": + # Windows systems don't provide load details + try: + self._state = value["load"]["min15"] + except KeyError: + self._state = value["cpu"]["total"] + elif self.type == "process_running": + self._state = value["processcount"]["running"] + elif self.type == "process_total": + self._state = value["processcount"]["total"] + elif self.type == "process_thread": + self._state = value["processcount"]["thread"] + elif self.type == "process_sleeping": + self._state = value["processcount"]["sleeping"] + elif self.type == "cpu_use_percent": + self._state = value["quicklook"]["cpu"] + elif self.type == "docker_active": + count = 0 + try: + for container in value["docker"]["containers"]: + if container["Status"] == "running" or "Up" in container["Status"]: + count += 1 + self._state = count + except KeyError: + self._state = count + elif self.type == "docker_cpu_use": + cpu_use = 0.0 + try: + for container in value["docker"]["containers"]: + if container["Status"] == "running" or "Up" in container["Status"]: + cpu_use += container["cpu"]["total"] + self._state = round(cpu_use, 1) + except KeyError: + self._state = STATE_UNAVAILABLE + elif self.type == "docker_memory_use": + mem_use = 0.0 + try: + for container in value["docker"]["containers"]: + if container["Status"] == "running" or "Up" in container["Status"]: + mem_use += container["memory"]["usage"] + self._state = round(mem_use / 1024 ** 2, 1) + except KeyError: + self._state = STATE_UNAVAILABLE diff --git a/homeassistant/components/google_assistant/trait.py b/homeassistant/components/google_assistant/trait.py index 8f01482aa45..384c5bfd0ae 100644 --- a/homeassistant/components/google_assistant/trait.py +++ b/homeassistant/components/google_assistant/trait.py @@ -1428,9 +1428,8 @@ 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: - mode_settings["effect"] = attrs.get(light.ATTR_EFFECT) + elif self.state.domain == light.DOMAIN and light.ATTR_EFFECT in attrs: + mode_settings["effect"] = attrs.get(light.ATTR_EFFECT) if mode_settings: response["on"] = self.state.state not in (STATE_OFF, STATE_UNKNOWN) @@ -1618,15 +1617,17 @@ 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: - response["discreteOnlyOpenClose"] = True + elif ( + self.state.domain == cover.DOMAIN + and features & cover.SUPPORT_SET_POSITION == 0 + ): + response["discreteOnlyOpenClose"] = True - if ( - features & cover.SUPPORT_OPEN == 0 - and features & cover.SUPPORT_CLOSE == 0 - ): - response["queryOnlyOpenClose"] = True + if ( + features & cover.SUPPORT_OPEN == 0 + and features & cover.SUPPORT_CLOSE == 0 + ): + response["queryOnlyOpenClose"] = True if self.state.attributes.get(ATTR_ASSUMED_STATE): response["commandOnlyOpenClose"] = True diff --git a/homeassistant/components/google_wifi/sensor.py b/homeassistant/components/google_wifi/sensor.py index cf5a804e5a5..28ec5df7486 100644 --- a/homeassistant/components/google_wifi/sensor.py +++ b/homeassistant/components/google_wifi/sensor.py @@ -175,9 +175,10 @@ class GoogleWifiAPI: sensor_value = "Online" else: sensor_value = "Offline" - elif attr_key == ATTR_LOCAL_IP: - if not self.raw_data["wan"]["online"]: - sensor_value = STATE_UNKNOWN + elif ( + attr_key == ATTR_LOCAL_IP and not self.raw_data["wan"]["online"] + ): + sensor_value = STATE_UNKNOWN self.data[attr_key] = sensor_value except KeyError: diff --git a/homeassistant/components/gpmdp/media_player.py b/homeassistant/components/gpmdp/media_player.py index 2fa227f0953..5680eb75500 100644 --- a/homeassistant/components/gpmdp/media_player.py +++ b/homeassistant/components/gpmdp/media_player.py @@ -227,9 +227,8 @@ class GPMDP(MediaPlayerEntity): return while True: msg = json.loads(websocket.recv()) - if "requestID" in msg: - if msg["requestID"] == self._request_id: - return msg + if "requestID" in msg and msg["requestID"] == self._request_id: + return msg except ( ConnectionRefusedError, ConnectionResetError,