mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Use dict.get instead of inline if (#109693)
This commit is contained in:
parent
30710815f0
commit
bf8bd5ff21
@ -39,7 +39,7 @@ class IHCDevice(Entity):
|
||||
self.ihc_name = product["name"]
|
||||
self.ihc_note = product["note"]
|
||||
self.ihc_position = product["position"]
|
||||
self.suggested_area = product["group"] if "group" in product else None
|
||||
self.suggested_area = product.get("group")
|
||||
if "id" in product:
|
||||
product_id = product["id"]
|
||||
self.device_id = f"{controller_id}_{product_id }"
|
||||
|
@ -90,7 +90,7 @@ class LGDevice(MediaPlayerEntity):
|
||||
|
||||
def handle_event(self, response):
|
||||
"""Handle responses from the speakers."""
|
||||
data = response["data"] if "data" in response else {}
|
||||
data = response.get("data") or {}
|
||||
if response["msg"] == "EQ_VIEW_INFO":
|
||||
if "i_bass" in data:
|
||||
self._bass = data["i_bass"]
|
||||
|
@ -172,9 +172,7 @@ async def async_modbus_setup(
|
||||
slave = int(float(service.data[ATTR_SLAVE]))
|
||||
address = int(float(service.data[ATTR_ADDRESS]))
|
||||
value = service.data[ATTR_VALUE]
|
||||
hub = hub_collect[
|
||||
service.data[ATTR_HUB] if ATTR_HUB in service.data else DEFAULT_HUB
|
||||
]
|
||||
hub = hub_collect[service.data.get(ATTR_HUB, DEFAULT_HUB)]
|
||||
if isinstance(value, list):
|
||||
await hub.async_pb_call(
|
||||
slave,
|
||||
@ -196,9 +194,7 @@ async def async_modbus_setup(
|
||||
slave = int(float(service.data[ATTR_SLAVE]))
|
||||
address = service.data[ATTR_ADDRESS]
|
||||
state = service.data[ATTR_STATE]
|
||||
hub = hub_collect[
|
||||
service.data[ATTR_HUB] if ATTR_HUB in service.data else DEFAULT_HUB
|
||||
]
|
||||
hub = hub_collect[service.data.get(ATTR_HUB, DEFAULT_HUB)]
|
||||
if isinstance(state, list):
|
||||
await hub.async_pb_call(slave, address, state, CALL_TYPE_WRITE_COILS)
|
||||
else:
|
||||
|
@ -544,7 +544,7 @@ async def websocket_subscribe(
|
||||
)
|
||||
|
||||
# Perform UTF-8 decoding directly in callback routine
|
||||
qos: int = msg["qos"] if "qos" in msg else DEFAULT_QOS
|
||||
qos: int = msg.get("qos", DEFAULT_QOS)
|
||||
connection.subscriptions[msg["id"]] = await async_subscribe(
|
||||
hass, msg["topic"], forward_messages, encoding=None, qos=qos
|
||||
)
|
||||
|
@ -646,8 +646,7 @@ class MqttAvailability(Entity):
|
||||
self._available_latest = False
|
||||
|
||||
self._available = {
|
||||
topic: (self._available[topic] if topic in self._available else False)
|
||||
for topic in self._avail_topics
|
||||
topic: (self._available.get(topic, False)) for topic in self._avail_topics
|
||||
}
|
||||
topics: dict[str, dict[str, Any]] = {
|
||||
f"availability_{topic}": {
|
||||
|
@ -159,12 +159,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Load the data."""
|
||||
self._data = config
|
||||
|
||||
self._data[CONF_PORT] = (
|
||||
self._data[CONF_PORT] if CONF_PORT in self._data else DEFAULT_PORT
|
||||
)
|
||||
self._data[CONF_ON_ACTION] = (
|
||||
self._data[CONF_ON_ACTION] if CONF_ON_ACTION in self._data else None
|
||||
)
|
||||
self._data[CONF_PORT] = self._data.get(CONF_PORT, DEFAULT_PORT)
|
||||
self._data[CONF_ON_ACTION] = self._data.get(CONF_ON_ACTION)
|
||||
|
||||
await self.async_set_unique_id(self._data[CONF_HOST])
|
||||
self._abort_if_unique_id_configured()
|
||||
|
@ -44,7 +44,7 @@ class StarlineDeviceTracker(StarlineEntity, TrackerEntity, RestoreEntity):
|
||||
@property
|
||||
def location_accuracy(self):
|
||||
"""Return the gps accuracy of the device."""
|
||||
return self._device.position["r"] if "r" in self._device.position else 0
|
||||
return self._device.position.get("r", 0)
|
||||
|
||||
@property
|
||||
def latitude(self):
|
||||
|
@ -602,12 +602,8 @@ class TelegramNotificationService:
|
||||
if keys:
|
||||
params[ATTR_REPLYMARKUP] = ReplyKeyboardMarkup(
|
||||
[[key.strip() for key in row.split(",")] for row in keys],
|
||||
resize_keyboard=data[ATTR_RESIZE_KEYBOARD]
|
||||
if ATTR_RESIZE_KEYBOARD in data
|
||||
else False,
|
||||
one_time_keyboard=data[ATTR_ONE_TIME_KEYBOARD]
|
||||
if ATTR_ONE_TIME_KEYBOARD in data
|
||||
else False,
|
||||
resize_keyboard=data.get(ATTR_RESIZE_KEYBOARD, False),
|
||||
one_time_keyboard=data.get(ATTR_ONE_TIME_KEYBOARD, False),
|
||||
)
|
||||
else:
|
||||
params[ATTR_REPLYMARKUP] = ReplyKeyboardRemove(True)
|
||||
|
@ -56,13 +56,12 @@ def _get_config_schema(
|
||||
vol.Required(CONF_API_KEY, default=input_dict.get(CONF_API_KEY)): str,
|
||||
}
|
||||
|
||||
default_location = (
|
||||
input_dict[CONF_LOCATION]
|
||||
if CONF_LOCATION in input_dict
|
||||
else {
|
||||
default_location = input_dict.get(
|
||||
CONF_LOCATION,
|
||||
{
|
||||
CONF_LATITUDE: hass.config.latitude,
|
||||
CONF_LONGITUDE: hass.config.longitude,
|
||||
}
|
||||
},
|
||||
)
|
||||
return vol.Schema(
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user