diff --git a/homeassistant/components/ihc/ihcdevice.py b/homeassistant/components/ihc/ihcdevice.py index 0c077f8698e..30c84da40f8 100644 --- a/homeassistant/components/ihc/ihcdevice.py +++ b/homeassistant/components/ihc/ihcdevice.py @@ -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 }" diff --git a/homeassistant/components/lg_soundbar/media_player.py b/homeassistant/components/lg_soundbar/media_player.py index 54d9be78df9..cfd0ebbd7a7 100644 --- a/homeassistant/components/lg_soundbar/media_player.py +++ b/homeassistant/components/lg_soundbar/media_player.py @@ -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"] diff --git a/homeassistant/components/modbus/modbus.py b/homeassistant/components/modbus/modbus.py index 71631352d52..c8e7fc3765e 100644 --- a/homeassistant/components/modbus/modbus.py +++ b/homeassistant/components/modbus/modbus.py @@ -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: diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 593d5bbd202..c8da1d7d8bc 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -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 ) diff --git a/homeassistant/components/mqtt/mixins.py b/homeassistant/components/mqtt/mixins.py index 4c7837a7a2b..aa42d257db4 100644 --- a/homeassistant/components/mqtt/mixins.py +++ b/homeassistant/components/mqtt/mixins.py @@ -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}": { diff --git a/homeassistant/components/panasonic_viera/config_flow.py b/homeassistant/components/panasonic_viera/config_flow.py index 38b6a351f29..80ab929231e 100644 --- a/homeassistant/components/panasonic_viera/config_flow.py +++ b/homeassistant/components/panasonic_viera/config_flow.py @@ -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() diff --git a/homeassistant/components/starline/device_tracker.py b/homeassistant/components/starline/device_tracker.py index ca8118d6b43..1ddcbc9373b 100644 --- a/homeassistant/components/starline/device_tracker.py +++ b/homeassistant/components/starline/device_tracker.py @@ -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): diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index 1d71e055e2e..2ba7752a85f 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -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) diff --git a/homeassistant/components/tomorrowio/config_flow.py b/homeassistant/components/tomorrowio/config_flow.py index d6855f42c0a..aece537c867 100644 --- a/homeassistant/components/tomorrowio/config_flow.py +++ b/homeassistant/components/tomorrowio/config_flow.py @@ -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( {