mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Use assignment expressions 25 (#58182)
This commit is contained in:
parent
2e5c9b69d4
commit
9990385926
@ -157,8 +157,7 @@ class AmbiclimateEntity(ClimateEntity):
|
||||
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temperature is None:
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
await self._heater.set_target_temperature(temperature)
|
||||
|
||||
|
@ -143,8 +143,7 @@ class AmbiclimateAuthCallbackView(HomeAssistantView):
|
||||
async def get(self, request: web.Request) -> str:
|
||||
"""Receive authorization token."""
|
||||
# pylint: disable=no-self-use
|
||||
code = request.query.get("code")
|
||||
if code is None:
|
||||
if (code := request.query.get("code")) is None:
|
||||
return "No code"
|
||||
hass = request.app["hass"]
|
||||
hass.async_create_task(
|
||||
|
@ -273,8 +273,7 @@ class BondFireplace(BondEntity, LightEntity):
|
||||
"""Turn the fireplace on."""
|
||||
_LOGGER.debug("Fireplace async_turn_on called with: %s", kwargs)
|
||||
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
if brightness:
|
||||
if brightness := kwargs.get(ATTR_BRIGHTNESS):
|
||||
flame = round((brightness * 100) / 255)
|
||||
await self._hub.bond.action(self._device.device_id, Action.set_flame(flame))
|
||||
else:
|
||||
|
@ -43,8 +43,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
|
||||
bapi = BruntAPI(username=username, password=password)
|
||||
try:
|
||||
things = bapi.getThings()["things"]
|
||||
if not things:
|
||||
if not (things := bapi.getThings()["things"]):
|
||||
_LOGGER.error("No things present in account")
|
||||
else:
|
||||
add_entities(
|
||||
|
@ -136,12 +136,10 @@ class DaikinClimate(ClimateEntity):
|
||||
values = {}
|
||||
|
||||
for attr in (ATTR_TEMPERATURE, ATTR_FAN_MODE, ATTR_SWING_MODE, ATTR_HVAC_MODE):
|
||||
value = settings.get(attr)
|
||||
if value is None:
|
||||
if (value := settings.get(attr)) is None:
|
||||
continue
|
||||
|
||||
daikin_attr = HA_ATTR_TO_DAIKIN.get(attr)
|
||||
if daikin_attr is not None:
|
||||
if (daikin_attr := HA_ATTR_TO_DAIKIN.get(attr)) is not None:
|
||||
if attr == ATTR_HVAC_MODE:
|
||||
values[daikin_attr] = HA_STATE_TO_DAIKIN[value]
|
||||
elif value in self._list[attr]:
|
||||
|
@ -142,8 +142,7 @@ class DysonClimateEntity(DysonEntity, ClimateEntity):
|
||||
|
||||
def set_temperature(self, **kwargs):
|
||||
"""Set new target temperature."""
|
||||
target_temp = kwargs.get(ATTR_TEMPERATURE)
|
||||
if target_temp is None:
|
||||
if (target_temp := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
_LOGGER.error("Missing target temperature %s", kwargs)
|
||||
return
|
||||
target_temp = int(target_temp)
|
||||
|
@ -97,8 +97,7 @@ class EgardiaAlarm(alarm.AlarmControlPanelEntity):
|
||||
|
||||
def handle_status_event(self, event):
|
||||
"""Handle the Egardia system status event."""
|
||||
statuscode = event.get("status")
|
||||
if statuscode is not None:
|
||||
if (statuscode := event.get("status")) is not None:
|
||||
status = self.lookupstatusfromcode(statuscode)
|
||||
self.parsestatus(status)
|
||||
self.schedule_update_ha_state()
|
||||
|
@ -25,11 +25,9 @@ PLATFORMS = ["sensor"]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Forecast.Solar from a config entry."""
|
||||
api_key = entry.options.get(CONF_API_KEY)
|
||||
# Our option flow may cause it to be an empty string,
|
||||
# this if statement is here to catch that.
|
||||
if not api_key:
|
||||
api_key = None
|
||||
api_key = entry.options.get(CONF_API_KEY) or None
|
||||
|
||||
session = async_get_clientsession(hass)
|
||||
forecast = ForecastSolar(
|
||||
|
@ -10,9 +10,7 @@ async def async_get_solar_forecast(
|
||||
hass: HomeAssistant, config_entry_id: str
|
||||
) -> dict[str, dict[str, float | int]] | None:
|
||||
"""Get solar forecast for a config entry ID."""
|
||||
coordinator = hass.data[DOMAIN].get(config_entry_id)
|
||||
|
||||
if coordinator is None:
|
||||
if (coordinator := hass.data[DOMAIN].get(config_entry_id)) is None:
|
||||
return None
|
||||
|
||||
return {
|
||||
|
@ -297,8 +297,7 @@ def setup(hass: HomeAssistant, base_config: ConfigType) -> bool: # noqa: C901
|
||||
|
||||
def _select_device(call):
|
||||
"""Select the active device."""
|
||||
addr = call.data[ATTR_DEVICE]
|
||||
if not addr:
|
||||
if not (addr := call.data[ATTR_DEVICE]):
|
||||
_LOGGER.error("Device not found: %s", call.data[ATTR_DEVICE])
|
||||
return
|
||||
if addr in device_aliases:
|
||||
|
@ -48,14 +48,11 @@ class HassAqualinkLight(AqualinkEntity, LightEntity):
|
||||
This handles brightness and light effects for lights that do support
|
||||
them.
|
||||
"""
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
effect = kwargs.get(ATTR_EFFECT)
|
||||
|
||||
# For now I'm assuming lights support either effects or brightness.
|
||||
if effect:
|
||||
if effect := kwargs.get(ATTR_EFFECT):
|
||||
effect = AqualinkLightEffect[effect].value
|
||||
await self.dev.set_effect(effect)
|
||||
elif brightness:
|
||||
elif brightness := kwargs.get(ATTR_BRIGHTNESS):
|
||||
# Aqualink supports percentages in 25% increments.
|
||||
pct = int(round(brightness * 4.0 / 255)) * 25
|
||||
await self.dev.set_brightness(pct)
|
||||
|
@ -52,17 +52,14 @@ class MSTeamsNotificationService(BaseNotificationService):
|
||||
|
||||
teams_message.text(message)
|
||||
|
||||
if data is not None:
|
||||
file_url = data.get(ATTR_FILE_URL)
|
||||
if data is not None and (file_url := data.get(ATTR_FILE_URL)) is not None:
|
||||
if not file_url.startswith("http"):
|
||||
_LOGGER.error("URL should start with http or https")
|
||||
return
|
||||
|
||||
if file_url is not None:
|
||||
if not file_url.startswith("http"):
|
||||
_LOGGER.error("URL should start with http or https")
|
||||
return
|
||||
|
||||
message_section = pymsteams.cardsection()
|
||||
message_section.addImage(file_url)
|
||||
teams_message.addSection(message_section)
|
||||
message_section = pymsteams.cardsection()
|
||||
message_section.addImage(file_url)
|
||||
teams_message.addSection(message_section)
|
||||
try:
|
||||
teams_message.send()
|
||||
except RuntimeError as err:
|
||||
|
@ -89,11 +89,9 @@ class NeatoCleaningMap(Camera):
|
||||
self._available = False
|
||||
return
|
||||
|
||||
image_url = None
|
||||
if self._mapdata:
|
||||
map_data: dict[str, Any] = self._mapdata[self._robot_serial]["maps"][0]
|
||||
image_url = map_data["url"]
|
||||
if image_url == self._image_url:
|
||||
if (image_url := map_data["url"]) == self._image_url:
|
||||
_LOGGER.debug(
|
||||
"The map image_url for '%s' is the same as old", self.entity_id
|
||||
)
|
||||
|
@ -71,8 +71,7 @@ async def async_migrate_entry(hass, entry):
|
||||
_LOGGER.debug("Migrating OpenWeatherMap entry from version %s", version)
|
||||
|
||||
if version == 1:
|
||||
mode = data[CONF_MODE]
|
||||
if mode == FORECAST_MODE_FREE_DAILY:
|
||||
if (mode := data[CONF_MODE]) == FORECAST_MODE_FREE_DAILY:
|
||||
mode = FORECAST_MODE_ONECALL_DAILY
|
||||
|
||||
new_data = {**data, CONF_MODE: mode}
|
||||
|
@ -291,8 +291,7 @@ class Plant(Entity):
|
||||
)
|
||||
|
||||
for entity_id in self._sensormap:
|
||||
state = self.hass.states.get(entity_id)
|
||||
if state is not None:
|
||||
if (state := self.hass.states.get(entity_id)) is not None:
|
||||
self.state_changed(entity_id, state)
|
||||
|
||||
def _load_history_from_db(self):
|
||||
|
@ -88,8 +88,7 @@ class PlayStation4FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
if user_input[CONF_MODE] == CONF_MANUAL:
|
||||
try:
|
||||
device = user_input[CONF_IP_ADDRESS]
|
||||
if device:
|
||||
if device := user_input[CONF_IP_ADDRESS]:
|
||||
self.m_device = device
|
||||
except KeyError:
|
||||
errors[CONF_IP_ADDRESS] = "no_ipaddress"
|
||||
|
@ -203,8 +203,7 @@ class PS4Device(MediaPlayerEntity):
|
||||
store = self._games[self._media_content_id]
|
||||
|
||||
# If locked get attributes from file.
|
||||
locked = store.get(ATTR_LOCKED)
|
||||
if locked:
|
||||
if store.get(ATTR_LOCKED):
|
||||
self._media_title = store.get(ATTR_MEDIA_TITLE)
|
||||
self._source = self._media_title
|
||||
self._media_image = store.get(ATTR_MEDIA_IMAGE_URL)
|
||||
|
@ -202,8 +202,7 @@ async def websocket_remove_device(
|
||||
device_id = msg["device_id"]
|
||||
dev_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
|
||||
device = dev_registry.async_get(device_id)
|
||||
if not device:
|
||||
if not (device := dev_registry.async_get(device_id)):
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Device not found"
|
||||
)
|
||||
|
@ -162,8 +162,7 @@ class TasmotaLight(
|
||||
def state_updated(self, state: bool, **kwargs: Any) -> None:
|
||||
"""Handle state updates."""
|
||||
self._on_off_state = state
|
||||
attributes = kwargs.get("attributes")
|
||||
if attributes:
|
||||
if attributes := kwargs.get("attributes"):
|
||||
if "brightness" in attributes:
|
||||
brightness = float(attributes["brightness"])
|
||||
percent_bright = brightness / TASMOTA_BRIGHTNESS_MAX
|
||||
|
@ -171,8 +171,7 @@ class TfiacClimate(ClimateEntity):
|
||||
|
||||
async def async_set_temperature(self, **kwargs):
|
||||
"""Set new target temperature."""
|
||||
temp = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temp is not None:
|
||||
if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None:
|
||||
await self._client.set_state(TARGET_TEMP, temp)
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode):
|
||||
|
@ -65,7 +65,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Withings component."""
|
||||
conf = config.get(DOMAIN, {})
|
||||
if not conf:
|
||||
if not (conf := config.get(DOMAIN, {})):
|
||||
return True
|
||||
|
||||
# Make the config available to the oauth2 config flow.
|
||||
|
Loading…
x
Reference in New Issue
Block a user