Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace in-place lists with tuples (1) #53684

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/asuswrt/__init__.py
Expand Up @@ -81,7 +81,7 @@ async def async_setup(hass, config):
options = {}
mode = conf.get(CONF_MODE, MODE_ROUTER)
for name, value in conf.items():
if name in ([CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP]):
if name in (CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not be consistent? There are tuples ending with , and not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat special. The parentheses here weren't used before, i.e.

([CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP])  == [CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP]

There wasn't a trailing comma, so no tuple.

Take a look at the next line as well: if name == CONF_REQUIRE_IP .... That suggests that it should only be a normal list / tuple. Not a tuple of tuples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I took this as an example (bad one), but it's still mixed and matched everywhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You normally don't need a trailing comma for tuples. Only if there is just one value.

I won't recommend adding additional once either as this would change the formatting with black.

if name == CONF_REQUIRE_IP and mode != MODE_AP:
continue
options[name] = value
Expand Down
Expand Up @@ -109,7 +109,9 @@ def update(self):
self._attr_state = vehicle_state.has_check_control_messages
# device class power: On means power detected, Off means no power
if self._attribute == "charging_status":
self._attr_state = vehicle_state.charging_status in [ChargingState.CHARGING]
self._attr_state = vehicle_state.charging_status in (
ChargingState.CHARGING,
)
# device class plug: On means device is plugged in,
# Off means device is unplugged
if self._attribute == "connection_status":
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bmw_connected_drive/lock.py
Expand Up @@ -58,7 +58,7 @@ def unlock(self, **kwargs):
def update(self):
"""Update state of the lock."""
_LOGGER.debug("%s: updating data for %s", self._vehicle.name, self._attribute)
if self._vehicle.state.door_lock_state in [LockState.LOCKED, LockState.SECURED]:
if self._vehicle.state.door_lock_state in (LockState.LOCKED, LockState.SECURED):
self._attr_is_locked = True
else:
self._attr_is_locked = False
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bmw_connected_drive/sensor.py
Expand Up @@ -564,7 +564,7 @@ def update(self) -> None:
self._attr_state = getattr(vehicle_all_trips, self._attribute)

vehicle_state = self._vehicle.state
charging_state = vehicle_state.charging_status in [ChargingState.CHARGING]
charging_state = vehicle_state.charging_status in (ChargingState.CHARGING,)

if self._attribute == "charging_level_hv":
self._attr_icon = icon_for_battery_level(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/braviatv/config_flow.py
Expand Up @@ -31,7 +31,7 @@
def host_valid(host: str) -> bool:
"""Return True if hostname or IP address is valid."""
with suppress(ValueError):
if ipaddress.ip_address(host).version in [4, 6]:
if ipaddress.ip_address(host).version in (4, 6):
return True
disallowed = re.compile(r"[^a-zA-Z\d\-]")
return all(x and not disallowed.search(x) for x in host.split("."))
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/brother/config_flow.py
Expand Up @@ -27,7 +27,7 @@
def host_valid(host: str) -> bool:
"""Return True if hostname or IP address is valid."""
try:
if ipaddress.ip_address(host).version in [4, 6]:
if ipaddress.ip_address(host).version in (4, 6):
return True
except ValueError:
pass
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/buienradar/sensor.py
Expand Up @@ -493,7 +493,7 @@ def _load_data(self, data): # noqa: C901
self._attr_state = nested.get(self.type[len(PRECIPITATION_FORECAST) + 1 :])
return True

if self.type in [WINDSPEED, WINDGUST]:
if self.type in (WINDSPEED, WINDGUST):
# hass wants windspeeds in km/h not m/s, so convert:
self._attr_state = data.get(self.type)
if self.state is not None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/cmus/media_player.py
Expand Up @@ -185,7 +185,7 @@ def volume_down(self):

def play_media(self, media_type, media_id, **kwargs):
"""Send the play command."""
if media_type in [MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST]:
if media_type in (MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST):
self._remote.cmus.player_play_file(media_id)
else:
_LOGGER.error(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/cover/reproduce_state.py
Expand Up @@ -73,9 +73,9 @@ async def _async_reproduce_state(
== state.attributes.get(ATTR_CURRENT_POSITION)
):
# Open/Close
if state.state in [STATE_CLOSED, STATE_CLOSING]:
if state.state in (STATE_CLOSED, STATE_CLOSING):
service = SERVICE_CLOSE_COVER
elif state.state in [STATE_OPEN, STATE_OPENING]:
elif state.state in (STATE_OPEN, STATE_OPENING):
if (
ATTR_CURRENT_POSITION in cur_state.attributes
and ATTR_CURRENT_POSITION in state.attributes
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/darksky/sensor.py
Expand Up @@ -687,10 +687,10 @@ def get_state(self, data):

# Some state data needs to be rounded to whole values or converted to
# percentages
if self.type in ["precip_probability", "cloud_cover", "humidity"]:
if self.type in ("precip_probability", "cloud_cover", "humidity"):
return round(state * 100, 1)

if self.type in [
if self.type in (
"dew_point",
"temperature",
"apparent_temperature",
Expand All @@ -706,7 +706,7 @@ def get_state(self, data):
"pressure",
"ozone",
"uvIndex",
]:
):
return round(state, 1)
return state

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/deconz/sensor.py
Expand Up @@ -267,12 +267,12 @@ def unique_id(self):
Normally there should only be one battery sensor per device from deCONZ.
With specific Danfoss devices each endpoint can report its own battery state.
"""
if self._device.manufacturer == "Danfoss" and self._device.modelid in [
if self._device.manufacturer == "Danfoss" and self._device.modelid in (
"0x8030",
"0x8031",
"0x8034",
"0x8035",
]:
):
return f"{super().unique_id}-battery"
return f"{self.serial}-battery"

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/dovado/sensor.py
Expand Up @@ -74,7 +74,7 @@ def _compute_state(self):
return None
if self._sensor == SENSOR_SMS_UNREAD:
return int(state)
if self._sensor in [SENSOR_UPLOAD, SENSOR_DOWNLOAD]:
if self._sensor in (SENSOR_UPLOAD, SENSOR_DOWNLOAD):
return round(float(state) / 1e6, 1)
return state

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/dyson/fan.py
Expand Up @@ -293,7 +293,7 @@ def oscillating(self):
@property
def is_on(self):
"""Return true if the entity is on."""
return self._device.state.fan_mode in ["FAN", "AUTO"]
return self._device.state.fan_mode in ("FAN", "AUTO")

def set_night_mode(self, night_mode: bool) -> None:
"""Turn fan in night mode."""
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/dyson/vacuum.py
Expand Up @@ -102,11 +102,11 @@ def extra_state_attributes(self):
@property
def is_on(self) -> bool:
"""Return True if entity is on."""
return self._device.state.state in [
return self._device.state.state in (
Dyson360EyeMode.FULL_CLEAN_INITIATED,
Dyson360EyeMode.FULL_CLEAN_ABORTED,
Dyson360EyeMode.FULL_CLEAN_RUNNING,
]
)

@property
def available(self) -> bool:
Expand All @@ -121,15 +121,15 @@ def supported_features(self):
@property
def battery_icon(self):
"""Return the battery icon for the vacuum cleaner."""
charging = self._device.state.state in [Dyson360EyeMode.INACTIVE_CHARGING]
charging = self._device.state.state in (Dyson360EyeMode.INACTIVE_CHARGING,)
return icon_for_battery_level(
battery_level=self.battery_level, charging=charging
)

def turn_on(self, **kwargs):
"""Turn the vacuum on."""
_LOGGER.debug("Turn on device %s", self.name)
if self._device.state.state in [Dyson360EyeMode.FULL_CLEAN_PAUSED]:
if self._device.state.state in (Dyson360EyeMode.FULL_CLEAN_PAUSED,):
self._device.resume()
else:
self._device.start()
Expand All @@ -152,13 +152,13 @@ def set_fan_speed(self, fan_speed, **kwargs):

def start_pause(self, **kwargs):
"""Start, pause or resume the cleaning task."""
if self._device.state.state in [Dyson360EyeMode.FULL_CLEAN_PAUSED]:
if self._device.state.state in (Dyson360EyeMode.FULL_CLEAN_PAUSED,):
_LOGGER.debug("Resume device %s", self.name)
self._device.resume()
elif self._device.state.state in [
elif self._device.state.state in (
Dyson360EyeMode.INACTIVE_CHARGED,
Dyson360EyeMode.INACTIVE_CHARGING,
]:
):
_LOGGER.debug("Start device %s", self.name)
self._device.start()
else:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/econet/climate.py
Expand Up @@ -185,7 +185,7 @@ def fan_mode(self):
econet_fan_mode = self._econet.fan_mode

# Remove this after we figure out how to handle med lo and med hi
if econet_fan_mode in [ThermostatFanMode.MEDHI, ThermostatFanMode.MEDLO]:
if econet_fan_mode in (ThermostatFanMode.MEDHI, ThermostatFanMode.MEDLO):
econet_fan_mode = ThermostatFanMode.MEDIUM

_current_fan_mode = FAN_AUTO
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/emulated_hue/hue_api.py
Expand Up @@ -409,14 +409,14 @@ async def put(self, request, username, entity_number): # noqa: C901
parsed[STATE_BRIGHTNESS] = None
parsed[STATE_ON] = True

elif entity.domain in [
elif entity.domain in (
script.DOMAIN,
media_player.DOMAIN,
fan.DOMAIN,
cover.DOMAIN,
climate.DOMAIN,
humidifier.DOMAIN,
]:
):
# Convert 0-254 to 0-100
level = (parsed[STATE_BRIGHTNESS] / HUE_API_STATE_BRI_MAX) * 100
parsed[STATE_BRIGHTNESS] = round(level)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/hdmi_cec/__init__.py
Expand Up @@ -389,15 +389,15 @@ def _hdmi_cec_unavailable(self, callback_event):
def update(self):
"""Update device status."""
device = self._device
if device.power_status in [POWER_OFF, 3]:
if device.power_status in (POWER_OFF, 3):
self._state = STATE_OFF
elif device.status == STATUS_PLAY:
self._state = STATE_PLAYING
elif device.status == STATUS_STOP:
self._state = STATE_IDLE
elif device.status == STATUS_STILL:
self._state = STATE_PAUSED
elif device.power_status in [POWER_ON, 4]:
elif device.power_status in (POWER_ON, 4):
self._state = STATE_ON
else:
_LOGGER.warning("Unknown state: %d", device.power_status)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/hdmi_cec/media_player.py
Expand Up @@ -156,10 +156,10 @@ def state(self) -> str:
def update(self):
"""Update device status."""
device = self._device
if device.power_status in [POWER_OFF, 3]:
if device.power_status in (POWER_OFF, 3):
self._state = STATE_OFF
elif not self.support_pause:
if device.power_status in [POWER_ON, 4]:
if device.power_status in (POWER_ON, 4):
self._state = STATE_ON
elif device.status == STATUS_PLAY:
self._state = STATE_PLAYING
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/home_connect/switch.py
Expand Up @@ -140,15 +140,15 @@ async def async_update(self):
self._state = False
elif self.device.appliance.status.get(BSH_OPERATION_STATE, {}).get(
ATTR_VALUE, None
) in [
) in (
"BSH.Common.EnumType.OperationState.Ready",
"BSH.Common.EnumType.OperationState.DelayedStart",
"BSH.Common.EnumType.OperationState.Run",
"BSH.Common.EnumType.OperationState.Pause",
"BSH.Common.EnumType.OperationState.ActionRequired",
"BSH.Common.EnumType.OperationState.Aborting",
"BSH.Common.EnumType.OperationState.Finished",
]:
):
self._state = True
elif (
self.device.appliance.status.get(BSH_OPERATION_STATE, {}).get(ATTR_VALUE)
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/homematicip_cloud/climate.py
Expand Up @@ -163,11 +163,11 @@ def preset_mode(self) -> str | None:
if self._device.controlMode == HMIP_ECO_CM:
if self._indoor_climate.absenceType == AbsenceType.VACATION:
return PRESET_AWAY
if self._indoor_climate.absenceType in [
if self._indoor_climate.absenceType in (
AbsenceType.PARTY,
AbsenceType.PERIOD,
AbsenceType.PERMANENT,
]:
):
return PRESET_ECO

return (
Expand Down Expand Up @@ -245,11 +245,11 @@ def extra_state_attributes(self) -> dict[str, Any]:
state_attr = super().extra_state_attributes

if self._device.controlMode == HMIP_ECO_CM:
if self._indoor_climate.absenceType in [
if self._indoor_climate.absenceType in (
AbsenceType.PARTY,
AbsenceType.PERIOD,
AbsenceType.VACATION,
]:
):
state_attr[ATTR_PRESET_END_TIME] = self._indoor_climate.absenceEndTime
elif self._indoor_climate.absenceType == AbsenceType.PERMANENT:
state_attr[ATTR_PRESET_END_TIME] = PERMANENT_END_TIME
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/honeywell/climate.py
Expand Up @@ -205,7 +205,7 @@ def extra_state_attributes(self) -> dict[str, Any]:
@property
def min_temp(self) -> float:
"""Return the minimum temperature."""
if self.hvac_mode in [HVAC_MODE_COOL, HVAC_MODE_HEAT_COOL]:
if self.hvac_mode in (HVAC_MODE_COOL, HVAC_MODE_HEAT_COOL):
return self._device.raw_ui_data["CoolLowerSetptLimit"]
if self.hvac_mode == HVAC_MODE_HEAT:
return self._device.raw_ui_data["HeatLowerSetptLimit"]
Expand All @@ -216,7 +216,7 @@ def max_temp(self) -> float:
"""Return the maximum temperature."""
if self.hvac_mode == HVAC_MODE_COOL:
return self._device.raw_ui_data["CoolUpperSetptLimit"]
if self.hvac_mode in [HVAC_MODE_HEAT, HVAC_MODE_HEAT_COOL]:
if self.hvac_mode in (HVAC_MODE_HEAT, HVAC_MODE_HEAT_COOL):
return self._device.raw_ui_data["HeatUpperSetptLimit"]
return None

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/insteon/utils.py
Expand Up @@ -116,12 +116,12 @@ def async_fire_group_on_off_event(name, address, group, button):
for group in device.events:
if isinstance(group, int):
for event in device.events[group]:
if event in [
if event in (
OFF_EVENT,
ON_EVENT,
OFF_FAST_EVENT,
ON_FAST_EVENT,
]:
):
_LOGGER.debug(
"Registering on/off event for %s %d %s",
str(device.address),
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/itunes/media_player.py
Expand Up @@ -154,7 +154,7 @@ def play_playlist(self, playlist_id_or_name):
found_playlists = [
playlist
for playlist in playlists
if (playlist_id_or_name in [playlist["name"], playlist["id"]])
if (playlist_id_or_name in (playlist["name"], playlist["id"]))
]

if found_playlists:
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/kodi/media_player.py
Expand Up @@ -695,20 +695,20 @@ async def async_play_media(self, media_type, media_id, **kwargs):
await self._kodi.play_playlist(int(media_id))
elif media_type_lower == "directory":
await self._kodi.play_directory(str(media_id))
elif media_type_lower in [
elif media_type_lower in (
MEDIA_TYPE_ARTIST,
MEDIA_TYPE_ALBUM,
MEDIA_TYPE_TRACK,
]:
):
await self.async_clear_playlist()
await self.async_add_to_playlist(media_type_lower, media_id)
await self._kodi.play_playlist(0)
elif media_type_lower in [
elif media_type_lower in (
MEDIA_TYPE_MOVIE,
MEDIA_TYPE_EPISODE,
MEDIA_TYPE_SEASON,
MEDIA_TYPE_TVSHOW,
]:
):
await self._kodi.play_item(
{MAP_KODI_MEDIA_TYPES[media_type_lower]: int(media_id)}
)
Expand Down Expand Up @@ -891,7 +891,7 @@ async def _get_thumbnail_url(
media_image_id,
)

if media_content_type in [None, "library"]:
if media_content_type in (None, "library"):
return await library_payload()

payload = {
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/konnected/panel.py
Expand Up @@ -284,7 +284,7 @@ def async_actuator_configuration(self):
return [
self.format_zone(
data[CONF_ZONE],
{"trigger": (0 if data.get(CONF_ACTIVATION) in [0, STATE_LOW] else 1)},
{"trigger": (0 if data.get(CONF_ACTIVATION) in (0, STATE_LOW) else 1)},
)
for data in self.stored_configuration[CONF_SWITCHES]
]
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/min_max/sensor.py
Expand Up @@ -212,10 +212,10 @@ def _async_min_max_sensor_state_listener(self, event):
new_state = event.data.get("new_state")
entity = event.data.get("entity_id")

if new_state.state is None or new_state.state in [
if new_state.state is None or new_state.state in (
STATE_UNKNOWN,
STATE_UNAVAILABLE,
]:
):
self.states[entity] = STATE_UNKNOWN
self._calc_values()
self.async_write_ha_state()
Expand Down