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

View File

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

View File

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

View File

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

View File

@ -30,7 +30,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up PwrCtrl devices/switches.""" """Set up PwrCtrl devices/switches."""
host = config.get(CONF_HOST, None) host = config.get(CONF_HOST)
username = config.get(CONF_USERNAME) username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD) password = config.get(CONF_PASSWORD)
port_recv = config.get(CONF_PORT_RECV) 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, hass,
async_add_entities, async_add_entities,
discovery_info.get(CONF_HOST), discovery_info.get(CONF_HOST),
discovery_info.get(CONF_PORT, None), discovery_info.get(CONF_PORT),
) )
return return
hosts = config.get(CONF_HOSTS, None) hosts = config.get(CONF_HOSTS)
if hosts: if hosts:
for host in hosts: for host in hosts:
_add_player( _add_player(
@ -258,7 +258,7 @@ class BluesoundPlayer(MediaPlayerDevice):
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", None) master = self._sync_status.get("master")
if 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")
@ -276,7 +276,7 @@ class BluesoundPlayer(MediaPlayerDevice):
else: else:
if self._master is not None: if self._master is not None:
self._master = None self._master = None
slaves = self._sync_status.get("slave", None) slaves = self._sync_status.get("slave")
self._is_master = slaves is not None self._is_master = slaves is not None
if on_updated_cb: if on_updated_cb:
@ -404,7 +404,7 @@ class BluesoundPlayer(MediaPlayerDevice):
self._last_status_update = dt_util.utcnow() self._last_status_update = dt_util.utcnow()
self._status = xmltodict.parse(result)["status"].copy() 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: if group_name != self._group_name:
_LOGGER.debug("Group name change detected on device: %s", self.host) _LOGGER.debug("Group name change detected on device: %s", self.host)
self._group_name = group_name self._group_name = group_name
@ -555,7 +555,7 @@ class BluesoundPlayer(MediaPlayerDevice):
if self.is_grouped and not self.is_master: if self.is_grouped and not self.is_master:
return STATE_GROUPED return STATE_GROUPED
status = self._status.get("state", None) status = self._status.get("state")
if status in ("pause", "stop"): if status in ("pause", "stop"):
return STATE_PAUSED return STATE_PAUSED
if status in ("stream", "play"): 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): if self._status is None or (self.is_grouped and not self.is_master):
return None return None
return self._status.get("title1", None) return self._status.get("title1")
@property @property
def media_artist(self): def media_artist(self):
@ -579,9 +579,9 @@ class BluesoundPlayer(MediaPlayerDevice):
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", None) artist = self._status.get("artist")
if not artist: if not artist:
artist = self._status.get("title2", None) artist = self._status.get("title2")
return artist return artist
@property @property
@ -590,9 +590,9 @@ class BluesoundPlayer(MediaPlayerDevice):
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", None) album = self._status.get("album")
if not album: if not album:
album = self._status.get("title3", None) album = self._status.get("title3")
return album return album
@property @property
@ -601,7 +601,7 @@ class BluesoundPlayer(MediaPlayerDevice):
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", None) url = self._status.get("image")
if not url: if not url:
return return
if url[0] == "/": if url[0] == "/":
@ -619,7 +619,7 @@ class BluesoundPlayer(MediaPlayerDevice):
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", None) position = self._status.get("secs")
if position is None: if position is None:
return None return None
@ -635,7 +635,7 @@ class BluesoundPlayer(MediaPlayerDevice):
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", None) duration = self._status.get("totlen")
if duration is None: if duration is None:
return None return None
return float(duration) return float(duration)
@ -648,9 +648,9 @@ class BluesoundPlayer(MediaPlayerDevice):
@property @property
def volume_level(self): def volume_level(self):
"""Volume level of the media player (0..1).""" """Volume level of the media player (0..1)."""
volume = self._status.get("volume", None) volume = self._status.get("volume")
if self.is_grouped: if self.is_grouped:
volume = self._sync_status.get("@volume", None) volume = self._sync_status.get("@volume")
if volume is not None: if volume is not None:
return int(volume) / 100 return int(volume) / 100

View File

@ -128,7 +128,7 @@ class BuienradarCam(Camera):
_LOG.debug("HTTP 304 - success") _LOG.debug("HTTP 304 - success")
return True return True
last_modified = res.headers.get("Last-Modified", None) last_modified = res.headers.get("Last-Modified")
if last_modified: if last_modified:
self._last_modified = 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.""" """Generate a unique id using coordinates and sensor type."""
# The combination of the location, name and sensor type is unique # The combination of the location, name and sensor type is unique
return "{:2.6f}{:2.6f}{}".format( return "{:2.6f}{:2.6f}{}".format(
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE], self.type, coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE], self.type
) )
@callback @callback
@ -307,17 +307,17 @@ class BrSensor(Entity):
return False return False
if condition: if condition:
new_state = condition.get(CONDITION, None) new_state = condition.get(CONDITION)
if self.type.startswith(SYMBOL): if self.type.startswith(SYMBOL):
new_state = condition.get(EXACTNL, None) new_state = condition.get(EXACTNL)
if self.type.startswith("conditioncode"): if self.type.startswith("conditioncode"):
new_state = condition.get(CONDCODE, None) new_state = condition.get(CONDCODE)
if self.type.startswith("conditiondetailed"): if self.type.startswith("conditiondetailed"):
new_state = condition.get(DETAILED, None) new_state = condition.get(DETAILED)
if self.type.startswith("conditionexact"): 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: if new_state != self._state or img != self._entity_picture:
self._state = new_state self._state = new_state
@ -346,20 +346,20 @@ class BrSensor(Entity):
if self.type == SYMBOL or self.type.startswith(CONDITION): if self.type == SYMBOL or self.type.startswith(CONDITION):
# update weather symbol & status text # update weather symbol & status text
condition = data.get(CONDITION, None) condition = data.get(CONDITION)
if condition: if condition:
if self.type == SYMBOL: if self.type == SYMBOL:
new_state = condition.get(EXACTNL, None) new_state = condition.get(EXACTNL)
if self.type == CONDITION: if self.type == CONDITION:
new_state = condition.get(CONDITION, None) new_state = condition.get(CONDITION)
if self.type == "conditioncode": if self.type == "conditioncode":
new_state = condition.get(CONDCODE, None) new_state = condition.get(CONDCODE)
if self.type == "conditiondetailed": if self.type == "conditiondetailed":
new_state = condition.get(DETAILED, None) new_state = condition.get(DETAILED)
if self.type == "conditionexact": 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: if new_state != self._state or img != self._entity_picture:
self._state = new_state self._state = new_state

View File

@ -101,7 +101,7 @@ class BrWeather(WeatherEntity):
def __init__(self, data, config): def __init__(self, data, config):
"""Initialise the platform with a data instance and station name.""" """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._forecast = config.get(CONF_FORECAST)
self._data = data self._data = data

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -230,7 +230,7 @@ class Config:
self._entities_with_hidden_attr_in_config = {} self._entities_with_hidden_attr_in_config = {}
for entity_id in self.entities: 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: if hidden_value is not None:
self._entities_with_hidden_attr_in_config[entity_id] = hidden_value 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]: if data[STATE_ON]:
data[STATE_BRIGHTNESS] = entity.attributes.get(ATTR_BRIGHTNESS, 0) 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: if hue_sat is not None:
hue = hue_sat[0] hue = hue_sat[0]
sat = hue_sat[1] 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): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Flexit Platform.""" """Set up the Flexit Platform."""
modbus_slave = config.get(CONF_SLAVE, None) modbus_slave = config.get(CONF_SLAVE)
name = config.get(CONF_NAME, None) name = config.get(CONF_NAME)
hub = hass.data[MODBUS_DOMAIN][config.get(CONF_HUB)] hub = hass.data[MODBUS_DOMAIN][config.get(CONF_HUB)]
add_entities([Flexit(hub, modbus_slave, name)], True) add_entities([Flexit(hub, modbus_slave, name)], True)

View File

@ -229,7 +229,7 @@ class GaradgetCover(CoverDevice):
try: try:
status = self._get_variable("doorStatus") status = self._get_variable("doorStatus")
_LOGGER.debug("Current Status: %s", status["status"]) _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.time_in_state = status["time"]
self.signal = status["signal"] self.signal = status["signal"]
self.sensor = status["sensor"] 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): def _found_calendar(call):
"""Check if we know about a calendar and generate PLATFORM_DISCOVER.""" """Check if we know about a calendar and generate PLATFORM_DISCOVER."""
calendar = get_calendar_info(hass, call.data) 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 return
hass.data[DATA_INDEX].update({calendar[CONF_CAL_ID]: calendar}) 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 if multiprocessing.cpu_count() < 2
else None 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) display_name = base_config[DOMAIN].get(CONF_DISPLAY_NAME, DEFAULT_DISPLAY_NAME)
if host: if host:
adapter = TcpAdapter(host, name=display_name, activate_source=False) 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__) _LOGGER = logging.getLogger(__name__)
HC_HOMEKIT_VALID_MODES_WATER_HEATER = { HC_HOMEKIT_VALID_MODES_WATER_HEATER = {"Heat": 1}
"Heat": 1,
}
UNIT_HASS_TO_HOMEKIT = {TEMP_CELSIUS: 0, TEMP_FAHRENHEIT: 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()} 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 # 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: if hc_modes is None:
_LOGGER.error( _LOGGER.error(
"%s: HVAC modes not yet available. Please disable auto start for homekit.", "%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, setter_callback=self.set_target_humidity,
) )
self.char_current_humidity = serv_thermostat.configure_char( self.char_current_humidity = serv_thermostat.configure_char(
CHAR_CURRENT_HUMIDITY, value=50, CHAR_CURRENT_HUMIDITY, value=50
) )
def get_temperature_range(self): def get_temperature_range(self):
@ -278,7 +276,7 @@ class Thermostat(HomeAccessory):
_LOGGER.debug("%s: Set target humidity to %d", self.entity_id, value) _LOGGER.debug("%s: Set target humidity to %d", self.entity_id, value)
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_HUMIDITY: value} params = {ATTR_ENTITY_ID: self.entity_id, ATTR_HUMIDITY: value}
self.call_service( self.call_service(
DOMAIN_CLIMATE, SERVICE_SET_HUMIDITY, params, f"{value}{UNIT_PERCENTAGE}", DOMAIN_CLIMATE, SERVICE_SET_HUMIDITY, params, f"{value}{UNIT_PERCENTAGE}"
) )
@debounce @debounce

View File

@ -335,7 +335,7 @@ class HTML5PushCallbackView(HomeAssistantView):
def check_authorization_header(self, request): def check_authorization_header(self, request):
"""Check the authorization header.""" """Check the authorization header."""
auth = request.headers.get(AUTHORIZATION, None) auth = request.headers.get(AUTHORIZATION)
if not auth: if not auth:
return self.json_message( return self.json_message(
"Authorization header is expected", status_code=HTTP_UNAUTHORIZED "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: if account_identifier is None:
return 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: if icloud_account is None:
for account in hass.data[DOMAIN].values(): for account in hass.data[DOMAIN].values():
if account.name == account_identifier: if account.name == account_identifier:

View File

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

View File

@ -47,10 +47,10 @@ def setup_platform(hass, config, add_entities_callback, discovery_info=None):
KankunSwitch( KankunSwitch(
hass, hass,
properties.get(CONF_NAME, dev_name), properties.get(CONF_NAME, dev_name),
properties.get(CONF_HOST, None), properties.get(CONF_HOST),
properties.get(CONF_PORT, DEFAULT_PORT), properties.get(CONF_PORT, DEFAULT_PORT),
properties.get(CONF_PATH, DEFAULT_PATH), properties.get(CONF_PATH, DEFAULT_PATH),
properties.get(CONF_USERNAME, None), properties.get(CONF_USERNAME),
properties.get(CONF_PASSWORD), 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_add_job to avoid a deadlock.
hass.async_create_task( hass.async_create_task(
hass.config_entries.flow.async_init( 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 return True
@ -314,7 +314,7 @@ class KonnectedView(HomeAssistantView):
hass = request.app["hass"] hass = request.app["hass"]
data = hass.data[DOMAIN] data = hass.data[DOMAIN]
auth = request.headers.get(AUTHORIZATION, None) auth = request.headers.get(AUTHORIZATION)
tokens = [] tokens = []
if hass.data[DOMAIN].get(CONF_ACCESS_TOKEN): if hass.data[DOMAIN].get(CONF_ACCESS_TOKEN):
tokens.extend([hass.data[DOMAIN][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) zone_entity_id = zone.get(ATTR_ENTITY_ID)
if zone_entity_id: if zone_entity_id:
resp["state"] = self.binary_value( 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) 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) known_hosts = hass.data.get(DATA_MEDIAROOM)
if known_hosts is None: if known_hosts is None:
known_hosts = hass.data[DATA_MEDIAROOM] = [] known_hosts = hass.data[DATA_MEDIAROOM] = []
host = config.get(CONF_HOST, None) host = config.get(CONF_HOST)
if host: if host:
async_add_entities( async_add_entities(
[ [
@ -101,7 +101,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
if not config[CONF_OPTIMISTIC]: if not config[CONF_OPTIMISTIC]:
already_installed = hass.data.get(DISCOVERY_MEDIAROOM, None) already_installed = hass.data.get(DISCOVERY_MEDIAROOM)
if not already_installed: if not already_installed:
hass.data[DISCOVERY_MEDIAROOM] = await install_mediaroom_protocol( hass.data[DISCOVERY_MEDIAROOM] = await install_mediaroom_protocol(
responses_callback=callback_notify 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, SERVICE_SET_HUMIDIFY_SETPOINT,
) )
platform.async_register_entity_service( 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 = [] entities = []
@ -323,9 +323,9 @@ class NexiaZone(NexiaThermostatZoneEntity, ClimateDevice):
def set_temperature(self, **kwargs): def set_temperature(self, **kwargs):
"""Set target temperature.""" """Set target temperature."""
new_heat_temp = kwargs.get(ATTR_TARGET_TEMP_LOW, None) new_heat_temp = kwargs.get(ATTR_TARGET_TEMP_LOW)
new_cool_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH, None) new_cool_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
set_temp = kwargs.get(ATTR_TEMPERATURE, None) set_temp = kwargs.get(ATTR_TEMPERATURE)
deadband = self._thermostat.get_deadband() deadband = self._thermostat.get_deadband()
cur_cool_temp = self._zone.get_cooling_setpoint() cur_cool_temp = self._zone.get_cooling_setpoint()

View File

@ -58,17 +58,17 @@ class PushoverNotificationService(BaseNotificationService):
# Extract params from data dict # Extract params from data dict
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
data = dict(kwargs.get(ATTR_DATA) or {}) data = dict(kwargs.get(ATTR_DATA) or {})
url = data.get(ATTR_URL, None) url = data.get(ATTR_URL)
url_title = data.get(ATTR_URL_TITLE, None) url_title = data.get(ATTR_URL_TITLE)
priority = data.get(ATTR_PRIORITY, None) priority = data.get(ATTR_PRIORITY)
retry = data.get(ATTR_RETRY, None) retry = data.get(ATTR_RETRY)
expire = data.get(ATTR_EXPIRE, None) expire = data.get(ATTR_EXPIRE)
callback_url = data.get(ATTR_CALLBACK_URL, None) callback_url = data.get(ATTR_CALLBACK_URL)
timestamp = data.get(ATTR_TIMESTAMP, None) timestamp = data.get(ATTR_TIMESTAMP)
sound = data.get(ATTR_SOUND, None) sound = data.get(ATTR_SOUND)
html = 1 if data.get(ATTR_HTML, False) else 0 html = 1 if data.get(ATTR_HTML, False) else 0
image = data.get(ATTR_ATTACHMENT, None) image = data.get(ATTR_ATTACHMENT)
# Check for attachment # Check for attachment
if image is not None: if image is not None:
# Only allow attachments from whitelisted paths, check valid path # 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): def set_fan_mode(self, fan_mode):
"""Turn fan on/off.""" """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: if code is not None:
self.device.fmode = code self.device.fmode = code

View File

@ -95,7 +95,7 @@ class I2CHatsDIScanner:
state = (value >> channel) & 0x01 state = (value >> channel) & 0x01
old_state = (old_value >> channel) & 0x01 old_state = (old_value >> channel) & 0x01
if state != old_state: if state != old_state:
callback = callbacks.get(channel, None) callback = callbacks.get(channel)
if callback is not None: if callback is not None:
callback(state) callback(state)
setattr(digital_inputs, self._OLD_VALUE, value) 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_max_retries = conf[CONF_DB_MAX_RETRIES]
db_retry_wait = conf[CONF_DB_RETRY_WAIT] 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: if not db_url:
db_url = DEFAULT_URL.format(hass_config_path=hass.config.path(DEFAULT_DB_FILE)) 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 return
# Lookup entities who registered this device id as device id or alias # 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 = ( is_group_event = (
event_type == EVENT_KEY_COMMAND event_type == EVENT_KEY_COMMAND

View File

@ -82,7 +82,7 @@ def entity_type_for_device_id(device_id):
"newkaku": TYPE_HYBRID "newkaku": TYPE_HYBRID
} }
protocol = device_id.split("_")[0] 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): 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): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the SQL sensor platform.""" """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: if not db_url:
db_url = DEFAULT_URL.format(hass_config_path=hass.config.path(DEFAULT_DB_FILE)) 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) entity_id = config.get(CONF_ENTITY_ID)
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
sampling_size = config.get(CONF_SAMPLING_SIZE) 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) precision = config.get(CONF_PRECISION)
async_add_entities( async_add_entities(

View File

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

View File

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

View File

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

View File

@ -46,8 +46,8 @@ def setup(hass, config):
schema = "http" schema = "http"
url = urljoin("{}://{}".format(schema, conf[CONF_HOST]), conf[CONF_PATH]) url = urljoin("{}://{}".format(schema, conf[CONF_HOST]), conf[CONF_PATH])
username = conf.get(CONF_USERNAME, None) username = conf.get(CONF_USERNAME)
password = conf.get(CONF_PASSWORD, None) password = conf.get(CONF_PASSWORD)
zapi = ZabbixAPI(url) zapi = ZabbixAPI(url)
try: 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: if discovery_info is None or DATA_NETWORK not in hass.data:
return False 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: if device is None:
return False return False

View File

@ -118,7 +118,7 @@ def run(script_args: List) -> int:
if domain == ERROR_STR: if domain == ERROR_STR:
continue continue
print(" ", color(C_HEAD, domain + ":")) print(" ", color(C_HEAD, domain + ":"))
dump_dict(res["components"].get(domain, None)) dump_dict(res["components"].get(domain))
if args.secrets: if args.secrets:
flatsecret: Dict[str, str] = {} 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"}} hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
) )
assert result 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): async def test_get_scanner_with_password_no_pubkey(hass):

View File

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