Remove None from dict.get(key, None) (#33794)

This commit is contained in:
springstan 2020-04-07 21:06:05 +02:00 committed by GitHub
parent d54ee77375
commit 46bbe816f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 104 additions and 110 deletions

View file

@ -204,7 +204,7 @@ class NotifyAuthModule(MultiFactorAuthModule):
await self._async_load()
assert self._user_settings is not None
notify_setting = self._user_settings.get(user_id, None)
notify_setting = self._user_settings.get(user_id)
if notify_setting is None:
return False
@ -222,7 +222,7 @@ class NotifyAuthModule(MultiFactorAuthModule):
await self._async_load()
assert self._user_settings is not None
notify_setting = self._user_settings.get(user_id, None)
notify_setting = self._user_settings.get(user_id)
if notify_setting is None:
raise ValueError("Cannot find user_id")
@ -246,7 +246,7 @@ class NotifyAuthModule(MultiFactorAuthModule):
await self._async_load()
assert self._user_settings is not None
notify_setting = self._user_settings.get(user_id, None)
notify_setting = self._user_settings.get(user_id)
if notify_setting is None:
_LOGGER.error("Cannot find user %s", user_id)
return

View file

@ -187,7 +187,7 @@ def setup_hass_services(hass):
def trigger_automation(call):
"""Trigger an Abode automation."""
entity_ids = call.data.get(ATTR_ENTITY_ID, None)
entity_ids = call.data.get(ATTR_ENTITY_ID)
target_entities = [
entity_id
@ -303,7 +303,7 @@ class AbodeEntity(Entity):
async def async_will_remove_from_hass(self):
"""Unsubscribe from Abode connection status updates."""
await self.hass.async_add_executor_job(
self._data.abode.events.remove_connection_status_callback, self.unique_id,
self._data.abode.events.remove_connection_status_callback, self.unique_id
)
def _update_connection_status(self):
@ -396,10 +396,7 @@ class AbodeAutomation(AbodeEntity):
@property
def device_state_attributes(self):
"""Return the state attributes."""
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
"type": "CUE automation",
}
return {ATTR_ATTRIBUTION: ATTRIBUTION, "type": "CUE automation"}
@property
def unique_id(self):

View file

@ -152,7 +152,7 @@ class AcerSwitch(SwitchDevice):
self._available = False
for key in self._attributes:
msg = CMD_DICT.get(key, None)
msg = CMD_DICT.get(key)
if msg:
awns = self._write_read_format(msg)
self._attributes[key] = awns

View file

@ -1086,7 +1086,7 @@ class AlexaPowerLevelController(AlexaCapability):
if self.entity.domain == fan.DOMAIN:
speed = self.entity.attributes.get(fan.ATTR_SPEED)
return PERCENTAGE_FAN_MAP.get(speed, None)
return PERCENTAGE_FAN_MAP.get(speed)
return None

View file

@ -30,7 +30,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up PwrCtrl devices/switches."""
host = config.get(CONF_HOST, None)
host = config.get(CONF_HOST)
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
port_recv = config.get(CONF_PORT_RECV)

View file

@ -155,11 +155,11 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
hass,
async_add_entities,
discovery_info.get(CONF_HOST),
discovery_info.get(CONF_PORT, None),
discovery_info.get(CONF_PORT),
)
return
hosts = config.get(CONF_HOSTS, None)
hosts = config.get(CONF_HOSTS)
if hosts:
for host in hosts:
_add_player(
@ -258,7 +258,7 @@ class BluesoundPlayer(MediaPlayerDevice):
if not self._icon:
self._icon = self._sync_status.get("@icon", self.host)
master = self._sync_status.get("master", None)
master = self._sync_status.get("master")
if master is not None:
self._is_master = False
master_host = master.get("#text")
@ -276,7 +276,7 @@ class BluesoundPlayer(MediaPlayerDevice):
else:
if self._master is not None:
self._master = None
slaves = self._sync_status.get("slave", None)
slaves = self._sync_status.get("slave")
self._is_master = slaves is not None
if on_updated_cb:
@ -404,7 +404,7 @@ class BluesoundPlayer(MediaPlayerDevice):
self._last_status_update = dt_util.utcnow()
self._status = xmltodict.parse(result)["status"].copy()
group_name = self._status.get("groupName", None)
group_name = self._status.get("groupName")
if group_name != self._group_name:
_LOGGER.debug("Group name change detected on device: %s", self.host)
self._group_name = group_name
@ -555,7 +555,7 @@ class BluesoundPlayer(MediaPlayerDevice):
if self.is_grouped and not self.is_master:
return STATE_GROUPED
status = self._status.get("state", None)
status = self._status.get("state")
if status in ("pause", "stop"):
return STATE_PAUSED
if status in ("stream", "play"):
@ -568,7 +568,7 @@ class BluesoundPlayer(MediaPlayerDevice):
if self._status is None or (self.is_grouped and not self.is_master):
return None
return self._status.get("title1", None)
return self._status.get("title1")
@property
def media_artist(self):
@ -579,9 +579,9 @@ class BluesoundPlayer(MediaPlayerDevice):
if self.is_grouped and not self.is_master:
return self._group_name
artist = self._status.get("artist", None)
artist = self._status.get("artist")
if not artist:
artist = self._status.get("title2", None)
artist = self._status.get("title2")
return artist
@property
@ -590,9 +590,9 @@ class BluesoundPlayer(MediaPlayerDevice):
if self._status is None or (self.is_grouped and not self.is_master):
return None
album = self._status.get("album", None)
album = self._status.get("album")
if not album:
album = self._status.get("title3", None)
album = self._status.get("title3")
return album
@property
@ -601,7 +601,7 @@ class BluesoundPlayer(MediaPlayerDevice):
if self._status is None or (self.is_grouped and not self.is_master):
return None
url = self._status.get("image", None)
url = self._status.get("image")
if not url:
return
if url[0] == "/":
@ -619,7 +619,7 @@ class BluesoundPlayer(MediaPlayerDevice):
if self._last_status_update is None or mediastate == STATE_IDLE:
return None
position = self._status.get("secs", None)
position = self._status.get("secs")
if position is None:
return None
@ -635,7 +635,7 @@ class BluesoundPlayer(MediaPlayerDevice):
if self._status is None or (self.is_grouped and not self.is_master):
return None
duration = self._status.get("totlen", None)
duration = self._status.get("totlen")
if duration is None:
return None
return float(duration)
@ -648,9 +648,9 @@ class BluesoundPlayer(MediaPlayerDevice):
@property
def volume_level(self):
"""Volume level of the media player (0..1)."""
volume = self._status.get("volume", None)
volume = self._status.get("volume")
if self.is_grouped:
volume = self._sync_status.get("@volume", None)
volume = self._sync_status.get("@volume")
if volume is not None:
return int(volume) / 100

View file

@ -128,7 +128,7 @@ class BuienradarCam(Camera):
_LOG.debug("HTTP 304 - success")
return True
last_modified = res.headers.get("Last-Modified", None)
last_modified = res.headers.get("Last-Modified")
if last_modified:
self._last_modified = last_modified

View file

@ -256,7 +256,7 @@ class BrSensor(Entity):
"""Generate a unique id using coordinates and sensor type."""
# The combination of the location, name and sensor type is unique
return "{:2.6f}{:2.6f}{}".format(
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE], self.type,
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE], self.type
)
@callback
@ -307,17 +307,17 @@ class BrSensor(Entity):
return False
if condition:
new_state = condition.get(CONDITION, None)
new_state = condition.get(CONDITION)
if self.type.startswith(SYMBOL):
new_state = condition.get(EXACTNL, None)
new_state = condition.get(EXACTNL)
if self.type.startswith("conditioncode"):
new_state = condition.get(CONDCODE, None)
new_state = condition.get(CONDCODE)
if self.type.startswith("conditiondetailed"):
new_state = condition.get(DETAILED, None)
new_state = condition.get(DETAILED)
if self.type.startswith("conditionexact"):
new_state = condition.get(EXACT, None)
new_state = condition.get(EXACT)
img = condition.get(IMAGE, None)
img = condition.get(IMAGE)
if new_state != self._state or img != self._entity_picture:
self._state = new_state
@ -346,20 +346,20 @@ class BrSensor(Entity):
if self.type == SYMBOL or self.type.startswith(CONDITION):
# update weather symbol & status text
condition = data.get(CONDITION, None)
condition = data.get(CONDITION)
if condition:
if self.type == SYMBOL:
new_state = condition.get(EXACTNL, None)
new_state = condition.get(EXACTNL)
if self.type == CONDITION:
new_state = condition.get(CONDITION, None)
new_state = condition.get(CONDITION)
if self.type == "conditioncode":
new_state = condition.get(CONDCODE, None)
new_state = condition.get(CONDCODE)
if self.type == "conditiondetailed":
new_state = condition.get(DETAILED, None)
new_state = condition.get(DETAILED)
if self.type == "conditionexact":
new_state = condition.get(EXACT, None)
new_state = condition.get(EXACT)
img = condition.get(IMAGE, None)
img = condition.get(IMAGE)
if new_state != self._state or img != self._entity_picture:
self._state = new_state

View file

@ -101,7 +101,7 @@ class BrWeather(WeatherEntity):
def __init__(self, data, config):
"""Initialise the platform with a data instance and station name."""
self._stationname = config.get(CONF_NAME, None)
self._stationname = config.get(CONF_NAME)
self._forecast = config.get(CONF_FORECAST)
self._data = data

View file

@ -191,8 +191,8 @@ def async_condition_from_config(
position = "current_position"
if config[CONF_TYPE] == "is_tilt_position":
position = "current_tilt_position"
min_pos = config.get(CONF_ABOVE, None)
max_pos = config.get(CONF_BELOW, None)
min_pos = config.get(CONF_ABOVE)
max_pos = config.get(CONF_BELOW)
value_template = template.Template( # type: ignore
f"{{{{ state.attributes.{position} }}}}"
)

View file

@ -492,7 +492,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
units = "us"
forecast_data = DarkSkyData(
api_key=config.get(CONF_API_KEY, None),
api_key=config.get(CONF_API_KEY),
latitude=latitude,
longitude=longitude,
units=units,

View file

@ -86,7 +86,7 @@ class DdWrtDeviceScanner(DeviceScanner):
if not data:
return None
dhcp_leases = data.get("dhcp_leases", None)
dhcp_leases = data.get("dhcp_leases")
if not dhcp_leases:
return None
@ -124,9 +124,9 @@ class DdWrtDeviceScanner(DeviceScanner):
self.last_results = []
if self.wireless_only:
active_clients = data.get("active_wireless", None)
active_clients = data.get("active_wireless")
else:
active_clients = data.get("arp_table", None)
active_clients = data.get("arp_table")
if not active_clients:
return False

View file

@ -113,7 +113,7 @@ class Dominos:
def handle_order(self, call):
"""Handle ordering pizza."""
entity_ids = call.data.get(ATTR_ORDER_ENTITY, None)
entity_ids = call.data.get(ATTR_ORDER_ENTITY)
target_orders = [
order

View file

@ -179,7 +179,7 @@ class EcobeeWeather(WeatherEntity):
"""Get the latest weather data."""
await self.data.update()
thermostat = self.data.ecobee.get_thermostat(self._index)
self.weather = thermostat.get("weather", None)
self.weather = thermostat.get("weather")
def _process_forecast(json):

View file

@ -55,7 +55,7 @@ class EcovacsVacuum(VacuumDevice):
"""Initialize the Ecovacs Vacuum."""
self.device = device
self.device.connect_and_wait_until_ready()
if self.device.vacuum.get("nick", None) is not None:
if self.device.vacuum.get("nick") is not None:
self._name = str(self.device.vacuum["nick"])
else:
# In case there is no nickname defined, use the device id
@ -96,7 +96,7 @@ class EcovacsVacuum(VacuumDevice):
@property
def unique_id(self) -> str:
"""Return an unique ID."""
return self.device.vacuum.get("did", None)
return self.device.vacuum.get("did")
@property
def is_on(self):

View file

@ -230,7 +230,7 @@ class Config:
self._entities_with_hidden_attr_in_config = {}
for entity_id in self.entities:
hidden_value = self.entities[entity_id].get(CONF_ENTITY_HIDDEN, None)
hidden_value = self.entities[entity_id].get(CONF_ENTITY_HIDDEN)
if hidden_value is not None:
self._entities_with_hidden_attr_in_config[entity_id] = hidden_value

View file

@ -537,7 +537,7 @@ def get_entity_state(config, entity):
if data[STATE_ON]:
data[STATE_BRIGHTNESS] = entity.attributes.get(ATTR_BRIGHTNESS, 0)
hue_sat = entity.attributes.get(ATTR_HS_COLOR, None)
hue_sat = entity.attributes.get(ATTR_HS_COLOR)
if hue_sat is not None:
hue = hue_sat[0]
sat = hue_sat[1]

View file

@ -36,8 +36,8 @@ SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Flexit Platform."""
modbus_slave = config.get(CONF_SLAVE, None)
name = config.get(CONF_NAME, None)
modbus_slave = config.get(CONF_SLAVE)
name = config.get(CONF_NAME)
hub = hass.data[MODBUS_DOMAIN][config.get(CONF_HUB)]
add_entities([Flexit(hub, modbus_slave, name)], True)

View file

@ -229,7 +229,7 @@ class GaradgetCover(CoverDevice):
try:
status = self._get_variable("doorStatus")
_LOGGER.debug("Current Status: %s", status["status"])
self._state = STATES_MAP.get(status["status"], None)
self._state = STATES_MAP.get(status["status"])
self.time_in_state = status["time"]
self.signal = status["signal"]
self.sensor = status["sensor"]

View file

@ -234,7 +234,7 @@ def setup_services(hass, hass_config, track_new_found_calendars, calendar_servic
def _found_calendar(call):
"""Check if we know about a calendar and generate PLATFORM_DISCOVER."""
calendar = get_calendar_info(hass, call.data)
if hass.data[DATA_INDEX].get(calendar[CONF_CAL_ID], None) is not None:
if hass.data[DATA_INDEX].get(calendar[CONF_CAL_ID]) is not None:
return
hass.data[DATA_INDEX].update({calendar[CONF_CAL_ID]: calendar})

View file

@ -202,7 +202,7 @@ def setup(hass: HomeAssistant, base_config):
if multiprocessing.cpu_count() < 2
else None
)
host = base_config[DOMAIN].get(CONF_HOST, None)
host = base_config[DOMAIN].get(CONF_HOST)
display_name = base_config[DOMAIN].get(CONF_DISPLAY_NAME, DEFAULT_DISPLAY_NAME)
if host:
adapter = TcpAdapter(host, name=display_name, activate_source=False)

View file

@ -73,9 +73,7 @@ from .util import temperature_to_homekit, temperature_to_states
_LOGGER = logging.getLogger(__name__)
HC_HOMEKIT_VALID_MODES_WATER_HEATER = {
"Heat": 1,
}
HC_HOMEKIT_VALID_MODES_WATER_HEATER = {"Heat": 1}
UNIT_HASS_TO_HOMEKIT = {TEMP_CELSIUS: 0, TEMP_FAHRENHEIT: 1}
UNIT_HOMEKIT_TO_HASS = {c: s for s, c in UNIT_HASS_TO_HOMEKIT.items()}
@ -138,7 +136,7 @@ class Thermostat(HomeAccessory):
)
# Target mode characteristics
hc_modes = state.attributes.get(ATTR_HVAC_MODES, None)
hc_modes = state.attributes.get(ATTR_HVAC_MODES)
if hc_modes is None:
_LOGGER.error(
"%s: HVAC modes not yet available. Please disable auto start for homekit.",
@ -239,7 +237,7 @@ class Thermostat(HomeAccessory):
setter_callback=self.set_target_humidity,
)
self.char_current_humidity = serv_thermostat.configure_char(
CHAR_CURRENT_HUMIDITY, value=50,
CHAR_CURRENT_HUMIDITY, value=50
)
def get_temperature_range(self):
@ -278,7 +276,7 @@ class Thermostat(HomeAccessory):
_LOGGER.debug("%s: Set target humidity to %d", self.entity_id, value)
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_HUMIDITY: value}
self.call_service(
DOMAIN_CLIMATE, SERVICE_SET_HUMIDITY, params, f"{value}{UNIT_PERCENTAGE}",
DOMAIN_CLIMATE, SERVICE_SET_HUMIDITY, params, f"{value}{UNIT_PERCENTAGE}"
)
@debounce

View file

@ -335,7 +335,7 @@ class HTML5PushCallbackView(HomeAssistantView):
def check_authorization_header(self, request):
"""Check the authorization header."""
auth = request.headers.get(AUTHORIZATION, None)
auth = request.headers.get(AUTHORIZATION)
if not auth:
return self.json_message(
"Authorization header is expected", status_code=HTTP_UNAUTHORIZED

View file

@ -186,7 +186,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
if account_identifier is None:
return None
icloud_account = hass.data[DOMAIN].get(account_identifier, None)
icloud_account = hass.data[DOMAIN].get(account_identifier)
if icloud_account is None:
for account in hass.data[DOMAIN].values():
if account.name == account_identifier:

View file

@ -167,7 +167,7 @@ class IcloudAccount:
):
continue
if self._devices.get(device_id, None) is not None:
if self._devices.get(device_id) is not None:
# Seen device -> updating
_LOGGER.debug("Updating iCloud device: %s", device_name)
self._devices[device_id].update(status)

View file

@ -47,10 +47,10 @@ def setup_platform(hass, config, add_entities_callback, discovery_info=None):
KankunSwitch(
hass,
properties.get(CONF_NAME, dev_name),
properties.get(CONF_HOST, None),
properties.get(CONF_HOST),
properties.get(CONF_PORT, DEFAULT_PORT),
properties.get(CONF_PATH, DEFAULT_PATH),
properties.get(CONF_USERNAME, None),
properties.get(CONF_USERNAME),
properties.get(CONF_PASSWORD),
)
)

View file

@ -245,7 +245,7 @@ async def async_setup(hass: HomeAssistant, config: dict):
# hass.async_add_job to avoid a deadlock.
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=device,
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=device
)
)
return True
@ -314,7 +314,7 @@ class KonnectedView(HomeAssistantView):
hass = request.app["hass"]
data = hass.data[DOMAIN]
auth = request.headers.get(AUTHORIZATION, None)
auth = request.headers.get(AUTHORIZATION)
tokens = []
if hass.data[DOMAIN].get(CONF_ACCESS_TOKEN):
tokens.extend([hass.data[DOMAIN][CONF_ACCESS_TOKEN]])
@ -417,7 +417,7 @@ class KonnectedView(HomeAssistantView):
zone_entity_id = zone.get(ATTR_ENTITY_ID)
if zone_entity_id:
resp["state"] = self.binary_value(
hass.states.get(zone_entity_id).state, zone[CONF_ACTIVATION],
hass.states.get(zone_entity_id).state, zone[CONF_ACTIVATION]
)
return self.json(resp)

View file

@ -70,7 +70,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
known_hosts = hass.data.get(DATA_MEDIAROOM)
if known_hosts is None:
known_hosts = hass.data[DATA_MEDIAROOM] = []
host = config.get(CONF_HOST, None)
host = config.get(CONF_HOST)
if host:
async_add_entities(
[
@ -101,7 +101,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
if not config[CONF_OPTIMISTIC]:
already_installed = hass.data.get(DISCOVERY_MEDIAROOM, None)
already_installed = hass.data.get(DISCOVERY_MEDIAROOM)
if not already_installed:
hass.data[DISCOVERY_MEDIAROOM] = await install_mediaroom_protocol(
responses_callback=callback_notify

View file

@ -121,7 +121,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
SERVICE_SET_HUMIDIFY_SETPOINT,
)
platform.async_register_entity_service(
SERVICE_SET_AIRCLEANER_MODE, SET_AIRCLEANER_SCHEMA, SERVICE_SET_AIRCLEANER_MODE,
SERVICE_SET_AIRCLEANER_MODE, SET_AIRCLEANER_SCHEMA, SERVICE_SET_AIRCLEANER_MODE
)
entities = []
@ -323,9 +323,9 @@ class NexiaZone(NexiaThermostatZoneEntity, ClimateDevice):
def set_temperature(self, **kwargs):
"""Set target temperature."""
new_heat_temp = kwargs.get(ATTR_TARGET_TEMP_LOW, None)
new_cool_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH, None)
set_temp = kwargs.get(ATTR_TEMPERATURE, None)
new_heat_temp = kwargs.get(ATTR_TARGET_TEMP_LOW)
new_cool_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
set_temp = kwargs.get(ATTR_TEMPERATURE)
deadband = self._thermostat.get_deadband()
cur_cool_temp = self._zone.get_cooling_setpoint()

View file

@ -58,17 +58,17 @@ class PushoverNotificationService(BaseNotificationService):
# Extract params from data dict
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
data = dict(kwargs.get(ATTR_DATA) or {})
url = data.get(ATTR_URL, None)
url_title = data.get(ATTR_URL_TITLE, None)
priority = data.get(ATTR_PRIORITY, None)
retry = data.get(ATTR_RETRY, None)
expire = data.get(ATTR_EXPIRE, None)
callback_url = data.get(ATTR_CALLBACK_URL, None)
timestamp = data.get(ATTR_TIMESTAMP, None)
sound = data.get(ATTR_SOUND, None)
url = data.get(ATTR_URL)
url_title = data.get(ATTR_URL_TITLE)
priority = data.get(ATTR_PRIORITY)
retry = data.get(ATTR_RETRY)
expire = data.get(ATTR_EXPIRE)
callback_url = data.get(ATTR_CALLBACK_URL)
timestamp = data.get(ATTR_TIMESTAMP)
sound = data.get(ATTR_SOUND)
html = 1 if data.get(ATTR_HTML, False) else 0
image = data.get(ATTR_ATTACHMENT, None)
image = data.get(ATTR_ATTACHMENT)
# Check for attachment
if image is not None:
# Only allow attachments from whitelisted paths, check valid path

View file

@ -198,7 +198,7 @@ class RadioThermostat(ClimateDevice):
def set_fan_mode(self, fan_mode):
"""Turn fan on/off."""
code = FAN_MODE_TO_CODE.get(fan_mode, None)
code = FAN_MODE_TO_CODE.get(fan_mode)
if code is not None:
self.device.fmode = code

View file

@ -95,7 +95,7 @@ class I2CHatsDIScanner:
state = (value >> channel) & 0x01
old_state = (old_value >> channel) & 0x01
if state != old_state:
callback = callbacks.get(channel, None)
callback = callbacks.get(channel)
if callback is not None:
callback(state)
setattr(digital_inputs, self._OLD_VALUE, value)

View file

@ -149,7 +149,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
db_max_retries = conf[CONF_DB_MAX_RETRIES]
db_retry_wait = conf[CONF_DB_RETRY_WAIT]
db_url = conf.get(CONF_DB_URL, None)
db_url = conf.get(CONF_DB_URL)
if not db_url:
db_url = DEFAULT_URL.format(hass_config_path=hass.config.path(DEFAULT_DB_FILE))

View file

@ -158,7 +158,7 @@ async def async_setup(hass, config):
return
# Lookup entities who registered this device id as device id or alias
event_id = event.get(EVENT_KEY_ID, None)
event_id = event.get(EVENT_KEY_ID)
is_group_event = (
event_type == EVENT_KEY_COMMAND

View file

@ -82,7 +82,7 @@ def entity_type_for_device_id(device_id):
"newkaku": TYPE_HYBRID
}
protocol = device_id.split("_")[0]
return entity_type_mapping.get(protocol, None)
return entity_type_mapping.get(protocol)
def entity_class_for_type(entity_type):

View file

@ -44,7 +44,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the SQL sensor platform."""
db_url = config.get(CONF_DB_URL, None)
db_url = config.get(CONF_DB_URL)
if not db_url:
db_url = DEFAULT_URL.format(hass_config_path=hass.config.path(DEFAULT_DB_FILE))

View file

@ -69,7 +69,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
entity_id = config.get(CONF_ENTITY_ID)
name = config.get(CONF_NAME)
sampling_size = config.get(CONF_SAMPLING_SIZE)
max_age = config.get(CONF_MAX_AGE, None)
max_age = config.get(CONF_MAX_AGE)
precision = config.get(CONF_PRECISION)
async_add_entities(

View file

@ -62,14 +62,14 @@ class TelegramNotificationService(BaseNotificationService):
# Send a photo, video, document, or location
if data is not None and ATTR_PHOTO in data:
photos = data.get(ATTR_PHOTO, None)
photos = data.get(ATTR_PHOTO)
photos = photos if isinstance(photos, list) else [photos]
for photo_data in photos:
service_data.update(photo_data)
self.hass.services.call(DOMAIN, "send_photo", service_data=service_data)
return
if data is not None and ATTR_VIDEO in data:
videos = data.get(ATTR_VIDEO, None)
videos = data.get(ATTR_VIDEO)
videos = videos if isinstance(videos, list) else [videos]
for video_data in videos:
service_data.update(video_data)

View file

@ -96,7 +96,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigType) -> bool:
def update(call):
"""Service call to manually update the data."""
called_display = call.data.get(CONF_DISPLAY, None)
called_display = call.data.get(CONF_DISPLAY)
for toon_data in hass.data[DATA_TOON].values():
if (
called_display and called_display == toon_data.display_name

View file

@ -102,8 +102,7 @@ class TorqueReceiveDataView(HomeAssistantView):
for pid in names:
if pid not in self.sensors:
self.sensors[pid] = TorqueSensor(
ENTITY_NAME_FORMAT.format(self.vehicle, names[pid]),
units.get(pid, None),
ENTITY_NAME_FORMAT.format(self.vehicle, names[pid]), units.get(pid)
)
hass.async_add_job(self.add_entities, [self.sensors[pid]])

View file

@ -46,8 +46,8 @@ def setup(hass, config):
schema = "http"
url = urljoin("{}://{}".format(schema, conf[CONF_HOST]), conf[CONF_PATH])
username = conf.get(CONF_USERNAME, None)
password = conf.get(CONF_PASSWORD, None)
username = conf.get(CONF_USERNAME)
password = conf.get(CONF_PASSWORD)
zapi = ZabbixAPI(url)
try:

View file

@ -297,7 +297,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
if discovery_info is None or DATA_NETWORK not in hass.data:
return False
device = hass.data[DATA_DEVICES].get(discovery_info[const.DISCOVERY_DEVICE], None)
device = hass.data[DATA_DEVICES].get(discovery_info[const.DISCOVERY_DEVICE])
if device is None:
return False

View file

@ -118,7 +118,7 @@ def run(script_args: List) -> int:
if domain == ERROR_STR:
continue
print(" ", color(C_HEAD, domain + ":"))
dump_dict(res["components"].get(domain, None))
dump_dict(res["components"].get(domain))
if args.secrets:
flatsecret: Dict[str, str] = {}

View file

@ -33,7 +33,7 @@ async def test_network_unreachable(hass):
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
)
assert result
assert hass.data.get(DATA_ASUSWRT, None) is None
assert hass.data.get(DATA_ASUSWRT) is None
async def test_get_scanner_with_password_no_pubkey(hass):

View file

@ -594,9 +594,9 @@ def _verify(
state = hass.states.get(_TEST_FAN)
attributes = state.attributes
assert state.state == expected_state
assert attributes.get(ATTR_SPEED, None) == expected_speed
assert attributes.get(ATTR_OSCILLATING, None) == expected_oscillating
assert attributes.get(ATTR_DIRECTION, None) == expected_direction
assert attributes.get(ATTR_SPEED) == expected_speed
assert attributes.get(ATTR_OSCILLATING) == expected_oscillating
assert attributes.get(ATTR_DIRECTION) == expected_direction
async def _register_components(hass, speed_list=None):