Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Dec 14, 2024
1 parent e5ed1ef commit c843773
Show file tree
Hide file tree
Showing 147 changed files with 242 additions and 428 deletions.
3 changes: 1 addition & 2 deletions homeassistant/block_async_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ class BlockedCalls:

def enable() -> None:
"""Enable the detection of blocking calls in the event loop."""
calls = _BLOCKED_CALLS.calls
if calls:
if calls := _BLOCKED_CALLS.calls:
raise RuntimeError("Blocking call detection is already enabled")

loop_thread_id = threading.get_ident()
Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/airzone_cloud/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ def _initialize_fan_speeds(self) -> None:

self._speeds = {}
for key, value in fan_speeds.items():
_key = azd_speeds.get(key)
if _key is not None:
if (_key := azd_speeds.get(key)) is not None:
self._speeds[_key] = value

self._speeds_reverse = {v: k for k, v in self._speeds.items()}
Expand Down Expand Up @@ -317,8 +316,7 @@ async def async_set_fan_mode(self, fan_mode: str) -> None:

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
if hvac_mode is not None:
if (hvac_mode := kwargs.get(ATTR_HVAC_MODE)) is not None:
await self.async_set_hvac_mode(hvac_mode)

params: dict[str, Any] = {}
Expand Down Expand Up @@ -374,8 +372,7 @@ async def async_turn_off(self) -> None:

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
if hvac_mode is not None:
if (hvac_mode := kwargs.get(ATTR_HVAC_MODE)) is not None:
await self.async_set_hvac_mode(hvac_mode)

params: dict[str, Any] = {}
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/amberelectric/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def update_price_data(self) -> dict[str, dict[str, Any]]:
]
result["grid"]["renewables"] = round(general[0].renewables)
result["grid"]["price_spike"] = general[0].spike_status.value
tariff_information = general[0].tariff_information
if tariff_information:
if tariff_information := general[0].tariff_information:
result["grid"]["demand_window"] = tariff_information.demand_window

controlled_load = [
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/aosmith/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ async def async_set_operation_mode(self, operation_mode: str) -> None:

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
temperature = kwargs.get("temperature")
if temperature is not None:
if (temperature := kwargs.get("temperature")) is not None:
await self.client.update_setpoint(self.junction_id, temperature)

await self.coordinator.async_request_refresh()
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/apple_tv/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,8 @@ async def async_pair_next_protocol(self) -> ConfigFlowResult:

self.protocol = self.protocols_to_pair.popleft()
assert self.atv
service = self.atv.get_service(self.protocol)

if service is None:
if (service := self.atv.get_service(self.protocol)) is None:
_LOGGER.debug(
"%s does not support pairing (cannot find a corresponding service)",
self.protocol,
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/assist_pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,7 @@ def _pipeline_debug_recording_thread_proc(
run_recording_dir.mkdir(parents=True, exist_ok=True)

while True:
message = queue.get(timeout=message_timeout)
if message is None:
if (message := queue.get(timeout=message_timeout)) is None:
# Stop signal
break

Expand Down Expand Up @@ -1716,8 +1715,7 @@ def ws_get_item(
self, hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict
) -> None:
"""Get an item."""
item_id = msg.get(self.item_id_key)
if item_id is None:
if (item_id := msg.get(self.item_id_key)) is None:
item_id = self.storage_collection.async_get_preferred_item()

if item_id.startswith("conversation.") and hass.states.get(item_id):
Expand Down
12 changes: 4 additions & 8 deletions homeassistant/components/assist_satellite/websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ async def websocket_intercept_wake_word(
msg: dict[str, Any],
) -> None:
"""Intercept the next wake word from a satellite."""
satellite = hass.data[DATA_COMPONENT].get_entity(msg["entity_id"])
if satellite is None:
if (satellite := hass.data[DATA_COMPONENT].get_entity(msg["entity_id"])) is None:
connection.send_error(
msg["id"], websocket_api.ERR_NOT_FOUND, "Entity not found"
)
Expand Down Expand Up @@ -86,8 +85,7 @@ def websocket_get_configuration(
msg: dict[str, Any],
) -> None:
"""Get the current satellite configuration."""
satellite = hass.data[DATA_COMPONENT].get_entity(msg["entity_id"])
if satellite is None:
if (satellite := hass.data[DATA_COMPONENT].get_entity(msg["entity_id"])) is None:
connection.send_error(
msg["id"], websocket_api.ERR_NOT_FOUND, "Entity not found"
)
Expand Down Expand Up @@ -115,8 +113,7 @@ async def websocket_set_wake_words(
msg: dict[str, Any],
) -> None:
"""Set the active wake words for the satellite."""
satellite = hass.data[DATA_COMPONENT].get_entity(msg["entity_id"])
if satellite is None:
if (satellite := hass.data[DATA_COMPONENT].get_entity(msg["entity_id"])) is None:
connection.send_error(
msg["id"], websocket_api.ERR_NOT_FOUND, "Entity not found"
)
Expand Down Expand Up @@ -168,8 +165,7 @@ async def websocket_test_connection(
Send an announcement to the device with a special media id.
"""
component: EntityComponent[AssistSatelliteEntity] = hass.data[DOMAIN]
satellite = component.get_entity(msg["entity_id"])
if satellite is None:
if (satellite := component.get_entity(msg["entity_id"])) is None:
connection.send_error(
msg["id"], websocket_api.ERR_NOT_FOUND, "Entity not found"
)
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/backup/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ async def get(
if agent_id not in manager.backup_agents:
return Response(status=HTTPStatus.BAD_REQUEST)
agent = manager.backup_agents[agent_id]
backup = await agent.async_get_backup(backup_id)

# We don't need to check if the path exists, aiohttp.FileResponse will handle
# that
if backup is None:
if (backup := await agent.async_get_backup(backup_id)) is None:
return Response(status=HTTPStatus.NOT_FOUND)

headers = {
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/bayesian/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ def _process_numeric_state(
if TYPE_CHECKING:
assert entity_id is not None

entity = self.hass.states.get(entity_id)
if entity is None:
if (entity := self.hass.states.get(entity_id)) is None:
return None

try:
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/blue_current/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ def __init__(
def update_from_latest_data(self) -> None:
"""Update the grid sensor from the latest data."""

new_value = self.connector.grid.get(self.key)

if new_value is not None:
if (new_value := self.connector.grid.get(self.key)) is not None:
self.has_value = True
self._attr_native_value = new_value

Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/bluesound/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ def media_image_url(self) -> str | None:
if self._status is None or (self.is_grouped and not self.is_master):
return None

url = self._status.image
if url is None:
if (url := self._status.image) is None:
return None

if url[0] == "/":
Expand All @@ -418,8 +417,7 @@ def media_position(self) -> int | None:
if self._last_status_update is None or mediastate == MediaPlayerState.IDLE:
return None

position = self._status.seconds
if position is None:
if (position := self._status.seconds) is None:
return None

if mediastate == MediaPlayerState.PLAYING:
Expand All @@ -433,8 +431,7 @@ def media_duration(self) -> int | None:
if self._status is None or (self.is_grouped and not self.is_master):
return None

duration = self._status.total_seconds
if duration is None:
if (duration := self._status.total_seconds) is None:
return None

return int(duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def deserialize_entity_description(
# out, but it doesn't. If we end up using this in more
# places we can add a `as_dict` and a `from_dict`
# method to these classes
if field_name == CONF_ENTITY_CATEGORY:
if (field_name := field.name) == CONF_ENTITY_CATEGORY:
value = try_parse_enum(EntityCategory, data.get(field_name))
else:
value = data.get(field_name)
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/cambridge_audio/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ def supported_features(self) -> MediaPlayerEntityFeature:
if TransportControl.PLAY_PAUSE in controls:
features |= MediaPlayerEntityFeature.PLAY | MediaPlayerEntityFeature.PAUSE
for control in controls:
feature = TRANSPORT_FEATURES.get(control)
if feature:
if feature := TRANSPORT_FEATURES.get(control):
features |= feature
return features

@property
def state(self) -> MediaPlayerState:
"""Return the state of the device."""
media_state = self.client.play_state.state
if media_state == "NETWORK":
if (media_state := self.client.play_state.state) == "NETWORK":
return MediaPlayerState.STANDBY
if self.client.state.power:
if media_state == "play":
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/camera/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

def get_camera_from_entity_id(hass: HomeAssistant, entity_id: str) -> Camera:
"""Get camera component from entity_id."""
component = hass.data.get(DATA_COMPONENT)
if component is None:
if (component := hass.data.get(DATA_COMPONENT)) is None:
raise HomeAssistantError("Camera integration not set up")

if (camera := component.get_entity(entity_id)) is None:
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ def _report_legacy_aux(self) -> None:
@property
def state(self) -> str | None:
"""Return the current state."""
hvac_mode = self.hvac_mode
if hvac_mode is None:
if (hvac_mode := self.hvac_mode) is None:
return None
# Support hvac_mode as string for custom integration backwards compatibility
if not isinstance(hvac_mode, HVACMode):
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/command_line/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ async def async_call_shell_with_timeout(
_LOGGER.error("Timeout for command: %s", command)
return -1

return_code = proc.returncode
if return_code == _EXEC_FAILED_CODE:
if (return_code := proc.returncode) == _EXEC_FAILED_CODE:
_LOGGER.error("Error trying to exec command: %s", command)
elif log_return_code and return_code != 0:
_LOGGER.error(
Expand Down
12 changes: 4 additions & 8 deletions homeassistant/components/control4/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ async def async_setup_entry(
) -> None:
"""Set up Control4 rooms from a config entry."""
entry_data = hass.data[DOMAIN][entry.entry_id]
ui_config = entry_data[CONF_UI_CONFIGURATION]

# OS 2 will not have a ui_configuration
if not ui_config:
if not (ui_config := entry_data[CONF_UI_CONFIGURATION]):
_LOGGER.debug("No UI Configuration found for Control4")
return

all_rooms = await get_rooms(hass, entry)
if not all_rooms:
if not (all_rooms := await get_rooms(hass, entry)):
return

scan_interval = entry_data[CONF_SCAN_INTERVAL]
Expand Down Expand Up @@ -233,8 +231,7 @@ def _get_current_video_device_id(self) -> int | None:
return self._get_device_from_variable(CONTROL4_CURRENT_VIDEO_DEVICE)

def _get_current_playing_device_id(self) -> int | None:
media_info = self._get_media_info()
if media_info:
if media_info := self._get_media_info():
if "medSrcDev" in media_info:
return media_info["medSrcDev"]
if "deviceid" in media_info:
Expand Down Expand Up @@ -293,8 +290,7 @@ def source(self):
@property
def media_title(self) -> str | None:
"""Get the Media Title."""
media_info = self._get_media_info()
if not media_info:
if not (media_info := self._get_media_info()):
return None
if "title" in media_info:
return media_info["title"]
Expand Down
12 changes: 3 additions & 9 deletions homeassistant/components/conversation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ def async_get_conversation_languages(
agents: list[ConversationEntity | AbstractConversationAgent]

if agent_id:
agent = async_get_agent(hass, agent_id)

if agent is None:
if (agent := async_get_agent(hass, agent_id)) is None:
raise ValueError(f"Agent {agent_id} not found")

# Shortcut
Expand Down Expand Up @@ -175,9 +173,7 @@ def async_get_agent_info(
agent_id: str | None = None,
) -> AgentInfo | None:
"""Get information on the agent or None if not found."""
agent = async_get_agent(hass, agent_id)

if agent is None:
if (agent := async_get_agent(hass, agent_id)) is None:
return None

if isinstance(agent, ConversationEntity):
Expand All @@ -199,9 +195,7 @@ async def async_prepare_agent(
hass: HomeAssistant, agent_id: str | None, language: str
) -> None:
"""Prepare given agent."""
agent = async_get_agent(hass, agent_id)

if agent is None:
if (agent := async_get_agent(hass, agent_id)) is None:
raise ValueError("Invalid agent specified")

await agent.async_prepare(language)
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/conversation/agent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ async def async_converse(
device_id: str | None = None,
) -> ConversationResult:
"""Process text and get intent."""
agent = async_get_agent(hass, agent_id)

if agent is None:
if (agent := async_get_agent(hass, agent_id)) is None:
raise ValueError(f"Agent {agent_id} not found")

if isinstance(agent, ConversationEntity):
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/conversation/default_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ async def _async_process_intent_result(
}
for entity in result.entities_list
}
device_area = self._get_device_area(user_input.device_id)
if device_area:
if device_area := self._get_device_area(user_input.device_id):
slots["preferred_area_id"] = {"value": device_area.id}
async_conversation_trace_append(
ConversationTraceEventType.TOOL_CALL,
Expand Down Expand Up @@ -1297,8 +1296,7 @@ async def _handle_trigger_result(
response_text = ""
response_set_by_trigger = False
for trigger_future in asyncio.as_completed(trigger_callbacks):
trigger_response = await trigger_future
if trigger_response is None:
if (trigger_response := await trigger_future) is None:
continue

response_text = trigger_response
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/conversation/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ async def websocket_prepare(
msg: dict[str, Any],
) -> None:
"""Reload intents."""
agent = async_get_agent(hass, msg.get("agent_id"))

if agent is None:
if (agent := async_get_agent(hass, msg.get("agent_id"))) is None:
connection.send_error(msg["id"], websocket_api.ERR_NOT_FOUND, "Agent not found")
return

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/conversation/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def async_conversation_trace_append(
event_type: ConversationTraceEventType, event_data: dict[str, Any]
) -> None:
"""Append a ConversationTraceEvent to the current active trace."""
trace = _current_trace.get()
if not trace:
if not (trace := _current_trace.get()):
return
trace.add_event(ConversationTraceEvent(event_type, event_data))

Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/devialet/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ def _handle_coordinator_update(self) -> None:
@property
def state(self) -> MediaPlayerState | None:
"""Return the state of the device."""
playing_state = self.coordinator.client.playing_state

if not playing_state:
if not (playing_state := self.coordinator.client.playing_state):
return MediaPlayerState.IDLE
if playing_state == "playing":
return MediaPlayerState.PLAYING
Expand Down
Loading

0 comments on commit c843773

Please sign in to comment.