mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use assignment expressions 22 (#57971)
This commit is contained in:
parent
ea2bc3fde1
commit
62c20860ac
@ -70,8 +70,7 @@ class AlexaConfig(AbstractConfig):
|
|||||||
return self._config[CONF_FILTER](entity_id)
|
return self._config[CONF_FILTER](entity_id)
|
||||||
|
|
||||||
entity_registry = er.async_get(self.hass)
|
entity_registry = er.async_get(self.hass)
|
||||||
registry_entry = entity_registry.async_get(entity_id)
|
if registry_entry := entity_registry.async_get(entity_id):
|
||||||
if registry_entry:
|
|
||||||
auxiliary_entity = registry_entry.entity_category in (
|
auxiliary_entity = registry_entry.entity_category in (
|
||||||
ENTITY_CATEGORY_CONFIG,
|
ENTITY_CATEGORY_CONFIG,
|
||||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||||
|
@ -14,20 +14,14 @@ from .gateway import AugustGateway
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_validate_input(
|
async def async_validate_input(data, august_gateway):
|
||||||
data,
|
|
||||||
august_gateway,
|
|
||||||
):
|
|
||||||
"""Validate the user input allows us to connect.
|
"""Validate the user input allows us to connect.
|
||||||
|
|
||||||
Data has the keys from DATA_SCHEMA with values provided by the user.
|
Data has the keys from DATA_SCHEMA with values provided by the user.
|
||||||
|
|
||||||
Request configuration steps from the user.
|
Request configuration steps from the user.
|
||||||
"""
|
"""
|
||||||
|
if (code := data.get(VERIFICATION_CODE_KEY)) is not None:
|
||||||
code = data.get(VERIFICATION_CODE_KEY)
|
|
||||||
|
|
||||||
if code is not None:
|
|
||||||
result = await august_gateway.authenticator.async_validate_verification_code(
|
result = await august_gateway.authenticator.async_validate_verification_code(
|
||||||
code
|
code
|
||||||
)
|
)
|
||||||
|
@ -90,8 +90,7 @@ class ServiceBusNotificationService(BaseNotificationService):
|
|||||||
if ATTR_TARGET in kwargs:
|
if ATTR_TARGET in kwargs:
|
||||||
dto[ATTR_ASB_TARGET] = kwargs[ATTR_TARGET]
|
dto[ATTR_ASB_TARGET] = kwargs[ATTR_TARGET]
|
||||||
|
|
||||||
data = kwargs.get(ATTR_DATA)
|
if data := kwargs.get(ATTR_DATA):
|
||||||
if data:
|
|
||||||
dto.update(data)
|
dto.update(data)
|
||||||
|
|
||||||
queue_message = Message(json.dumps(dto))
|
queue_message = Message(json.dumps(dto))
|
||||||
|
@ -160,8 +160,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
hosts = config.get(CONF_HOSTS)
|
if hosts := config.get(CONF_HOSTS):
|
||||||
if hosts:
|
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
_add_player(
|
_add_player(
|
||||||
hass,
|
hass,
|
||||||
@ -173,15 +172,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
|
|
||||||
async def async_service_handler(service):
|
async def async_service_handler(service):
|
||||||
"""Map services to method of Bluesound devices."""
|
"""Map services to method of Bluesound devices."""
|
||||||
method = SERVICE_TO_METHOD.get(service.service)
|
if not (method := SERVICE_TO_METHOD.get(service.service)):
|
||||||
if not method:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
key: value for key, value in service.data.items() if key != ATTR_ENTITY_ID
|
key: value for key, value in service.data.items() if key != ATTR_ENTITY_ID
|
||||||
}
|
}
|
||||||
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
if entity_ids := service.data.get(ATTR_ENTITY_ID):
|
||||||
if entity_ids:
|
|
||||||
target_players = [
|
target_players = [
|
||||||
player
|
player
|
||||||
for player in hass.data[DATA_BLUESOUND]
|
for player in hass.data[DATA_BLUESOUND]
|
||||||
@ -259,8 +256,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
if not self._icon:
|
if not self._icon:
|
||||||
self._icon = self._sync_status.get("@icon", self.host)
|
self._icon = self._sync_status.get("@icon", self.host)
|
||||||
|
|
||||||
master = self._sync_status.get("master")
|
if (master := self._sync_status.get("master")) is not None:
|
||||||
if master is not None:
|
|
||||||
self._is_master = False
|
self._is_master = False
|
||||||
master_host = master.get("#text")
|
master_host = master.get("#text")
|
||||||
master_device = [
|
master_device = [
|
||||||
@ -580,8 +576,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
if self.is_grouped and not self.is_master:
|
if self.is_grouped and not self.is_master:
|
||||||
return self._group_name
|
return self._group_name
|
||||||
|
|
||||||
artist = self._status.get("artist")
|
if not (artist := self._status.get("artist")):
|
||||||
if not artist:
|
|
||||||
artist = self._status.get("title2")
|
artist = self._status.get("title2")
|
||||||
return artist
|
return artist
|
||||||
|
|
||||||
@ -591,8 +586,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
if self._status is None or (self.is_grouped and not self.is_master):
|
if self._status is None or (self.is_grouped and not self.is_master):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
album = self._status.get("album")
|
if not (album := self._status.get("album")):
|
||||||
if not album:
|
|
||||||
album = self._status.get("title3")
|
album = self._status.get("title3")
|
||||||
return album
|
return album
|
||||||
|
|
||||||
@ -602,8 +596,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
if self._status is None or (self.is_grouped and not self.is_master):
|
if self._status is None or (self.is_grouped and not self.is_master):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
url = self._status.get("image")
|
if not (url := self._status.get("image")):
|
||||||
if not url:
|
|
||||||
return
|
return
|
||||||
if url[0] == "/":
|
if url[0] == "/":
|
||||||
url = f"http://{self.host}:{self.port}{url}"
|
url = f"http://{self.host}:{self.port}{url}"
|
||||||
@ -620,8 +613,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
if self._last_status_update is None or mediastate == STATE_IDLE:
|
if self._last_status_update is None or mediastate == STATE_IDLE:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
position = self._status.get("secs")
|
if (position := self._status.get("secs")) is None:
|
||||||
if position is None:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
position = float(position)
|
position = float(position)
|
||||||
@ -636,8 +628,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
if self._status is None or (self.is_grouped and not self.is_master):
|
if self._status is None or (self.is_grouped and not self.is_master):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
duration = self._status.get("totlen")
|
if (duration := self._status.get("totlen")) is None:
|
||||||
if duration is None:
|
|
||||||
return None
|
return None
|
||||||
return float(duration)
|
return float(duration)
|
||||||
|
|
||||||
@ -712,8 +703,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
if self._status is None or (self.is_grouped and not self.is_master):
|
if self._status is None or (self.is_grouped and not self.is_master):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
current_service = self._status.get("service", "")
|
if (current_service := self._status.get("service", "")) == "":
|
||||||
if current_service == "":
|
|
||||||
return ""
|
return ""
|
||||||
stream_url = self._status.get("streamUrl", "")
|
stream_url = self._status.get("streamUrl", "")
|
||||||
|
|
||||||
|
@ -140,8 +140,7 @@ class ECSensor(SensorEntity):
|
|||||||
else:
|
else:
|
||||||
self._unit = sensor_data.get("unit")
|
self._unit = sensor_data.get("unit")
|
||||||
|
|
||||||
timestamp = metadata.get("timestamp")
|
if timestamp := metadata.get("timestamp"):
|
||||||
if timestamp:
|
|
||||||
updated_utc = datetime.strptime(timestamp, "%Y%m%d%H%M%S").isoformat()
|
updated_utc = datetime.strptime(timestamp, "%Y%m%d%H%M%S").isoformat()
|
||||||
else:
|
else:
|
||||||
updated_utc = None
|
updated_utc = None
|
||||||
|
@ -125,8 +125,7 @@ class FritzboxConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
assert isinstance(host, str)
|
assert isinstance(host, str)
|
||||||
self.context[CONF_HOST] = host
|
self.context[CONF_HOST] = host
|
||||||
|
|
||||||
uuid = discovery_info.get(ATTR_UPNP_UDN)
|
if uuid := discovery_info.get(ATTR_UPNP_UDN):
|
||||||
if uuid:
|
|
||||||
if uuid.startswith("uuid:"):
|
if uuid.startswith("uuid:"):
|
||||||
uuid = uuid[5:]
|
uuid = uuid[5:]
|
||||||
await self.async_set_unique_id(uuid)
|
await self.async_set_unique_id(uuid)
|
||||||
|
@ -57,8 +57,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the Hangouts bot component."""
|
"""Set up the Hangouts bot component."""
|
||||||
config = config.get(DOMAIN)
|
if (config := config.get(DOMAIN)) is None:
|
||||||
if config is None:
|
|
||||||
hass.data[DOMAIN] = {
|
hass.data[DOMAIN] = {
|
||||||
CONF_INTENTS: {},
|
CONF_INTENTS: {},
|
||||||
CONF_DEFAULT_CONVERSATIONS: [],
|
CONF_DEFAULT_CONVERSATIONS: [],
|
||||||
|
@ -211,8 +211,7 @@ class Life360Scanner:
|
|||||||
prev_seen = self._prev_seen(dev_id, last_seen)
|
prev_seen = self._prev_seen(dev_id, last_seen)
|
||||||
|
|
||||||
if not loc:
|
if not loc:
|
||||||
err_msg = member["issues"]["title"]
|
if err_msg := member["issues"]["title"]:
|
||||||
if err_msg:
|
|
||||||
if member["issues"]["dialog"]:
|
if member["issues"]["dialog"]:
|
||||||
err_msg += f": {member['issues']['dialog']}"
|
err_msg += f": {member['issues']['dialog']}"
|
||||||
else:
|
else:
|
||||||
|
@ -208,8 +208,7 @@ class EventManager:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
topic = msg.Topic._value_1
|
topic = msg.Topic._value_1
|
||||||
parser = PARSERS.get(topic)
|
if not (parser := PARSERS.get(topic)):
|
||||||
if not parser:
|
|
||||||
if topic not in UNHANDLED_TOPICS:
|
if topic not in UNHANDLED_TOPICS:
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"No registered handler for event from %s: %s",
|
"No registered handler for event from %s: %s",
|
||||||
|
@ -164,9 +164,7 @@ class Proximity(Entity):
|
|||||||
|
|
||||||
# Check for devices in the monitored zone.
|
# Check for devices in the monitored zone.
|
||||||
for device in self.proximity_devices:
|
for device in self.proximity_devices:
|
||||||
device_state = self.hass.states.get(device)
|
if (device_state := self.hass.states.get(device)) is None:
|
||||||
|
|
||||||
if device_state is None:
|
|
||||||
devices_to_calculate = True
|
devices_to_calculate = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -201,8 +201,7 @@ class RadioThermostat(ClimateEntity):
|
|||||||
|
|
||||||
def set_fan_mode(self, fan_mode):
|
def set_fan_mode(self, fan_mode):
|
||||||
"""Turn fan on/off."""
|
"""Turn fan on/off."""
|
||||||
code = FAN_MODE_TO_CODE.get(fan_mode)
|
if (code := FAN_MODE_TO_CODE.get(fan_mode)) is not None:
|
||||||
if code is not None:
|
|
||||||
self.device.fmode = code
|
self.device.fmode = code
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -322,8 +321,7 @@ class RadioThermostat(ClimateEntity):
|
|||||||
|
|
||||||
def set_temperature(self, **kwargs):
|
def set_temperature(self, **kwargs):
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||||
if temperature is None:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
temperature = round_temp(temperature)
|
temperature = round_temp(temperature)
|
||||||
|
@ -24,8 +24,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Roku from a config entry."""
|
"""Set up Roku from a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
coordinator = hass.data[DOMAIN].get(entry.entry_id)
|
if not (coordinator := hass.data[DOMAIN].get(entry.entry_id)):
|
||||||
if not coordinator:
|
|
||||||
coordinator = RokuDataUpdateCoordinator(hass, host=entry.data[CONF_HOST])
|
coordinator = RokuDataUpdateCoordinator(hass, host=entry.data[CONF_HOST])
|
||||||
hass.data[DOMAIN][entry.entry_id] = coordinator
|
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||||
|
|
||||||
|
@ -404,8 +404,7 @@ class ScriptEntity(ToggleEntity, RestoreEntity):
|
|||||||
script_trace.set_trace(trace_get())
|
script_trace.set_trace(trace_get())
|
||||||
with trace_path("sequence"):
|
with trace_path("sequence"):
|
||||||
this = None
|
this = None
|
||||||
state = self.hass.states.get(self.entity_id)
|
if state := self.hass.states.get(self.entity_id):
|
||||||
if state:
|
|
||||||
this = state.as_dict()
|
this = state.as_dict()
|
||||||
script_vars = {"this": this, **(variables or {})}
|
script_vars = {"this": this, **(variables or {})}
|
||||||
return await self.script.async_run(script_vars, context)
|
return await self.script.async_run(script_vars, context)
|
||||||
|
@ -446,8 +446,7 @@ class TibberRtDataCoordinator(update_coordinator.DataUpdateCoordinator):
|
|||||||
|
|
||||||
def get_live_measurement(self):
|
def get_live_measurement(self):
|
||||||
"""Get live measurement data."""
|
"""Get live measurement data."""
|
||||||
errors = self.data.get("errors")
|
if errors := self.data.get("errors"):
|
||||||
if errors:
|
|
||||||
_LOGGER.error(errors[0])
|
_LOGGER.error(errors[0])
|
||||||
return None
|
return None
|
||||||
return self.data.get("data", {}).get("liveMeasurement")
|
return self.data.get("data", {}).get("liveMeasurement")
|
||||||
|
@ -89,8 +89,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
errors = {}
|
errors = {}
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
host = user_input[CONF_HOST]
|
if not (host := user_input[CONF_HOST]):
|
||||||
if not host:
|
|
||||||
return await self.async_step_pick_device()
|
return await self.async_step_pick_device()
|
||||||
try:
|
try:
|
||||||
device = await self._async_try_connect(host, raise_on_progress=False)
|
device = await self._async_try_connect(host, raise_on_progress=False)
|
||||||
|
@ -169,8 +169,7 @@ class SensorTrend(BinarySensorEntity):
|
|||||||
@callback
|
@callback
|
||||||
def trend_sensor_state_listener(event):
|
def trend_sensor_state_listener(event):
|
||||||
"""Handle state changes on the observed device."""
|
"""Handle state changes on the observed device."""
|
||||||
new_state = event.data.get("new_state")
|
if (new_state := event.data.get("new_state")) is None:
|
||||||
if new_state is None:
|
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
if self._attribute:
|
if self._attribute:
|
||||||
|
@ -313,8 +313,7 @@ async def async_send_message( # noqa: C901
|
|||||||
filesize = len(input_file)
|
filesize = len(input_file)
|
||||||
_LOGGER.debug("Filesize is %s bytes", filesize)
|
_LOGGER.debug("Filesize is %s bytes", filesize)
|
||||||
|
|
||||||
content_type = mimetypes.guess_type(path)[0]
|
if (content_type := mimetypes.guess_type(path)[0]) is None:
|
||||||
if content_type is None:
|
|
||||||
content_type = DEFAULT_CONTENT_TYPE
|
content_type = DEFAULT_CONTENT_TYPE
|
||||||
_LOGGER.debug("Content type is %s", content_type)
|
_LOGGER.debug("Content type is %s", content_type)
|
||||||
|
|
||||||
|
@ -1075,9 +1075,7 @@ class YeelightAmbientLight(YeelightColorLightWithoutNightlightSwitch):
|
|||||||
return "bright"
|
return "bright"
|
||||||
|
|
||||||
def _get_property(self, prop, default=None):
|
def _get_property(self, prop, default=None):
|
||||||
bg_prop = self.PROPERTIES_MAPPING.get(prop)
|
if not (bg_prop := self.PROPERTIES_MAPPING.get(prop)):
|
||||||
|
|
||||||
if not bg_prop:
|
|
||||||
bg_prop = f"bg_{prop}"
|
bg_prop = f"bg_{prop}"
|
||||||
|
|
||||||
return super()._get_property(bg_prop, default)
|
return super()._get_property(bg_prop, default)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user