From 46bbe816f62e4db20057637676b26434a7441bef Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Tue, 7 Apr 2020 21:06:05 +0200 Subject: [PATCH] Remove None from dict.get(key, None) (#33794) --- homeassistant/auth/mfa_modules/notify.py | 6 ++-- homeassistant/components/abode/__init__.py | 9 ++---- .../components/acer_projector/switch.py | 2 +- .../components/alexa/capabilities.py | 2 +- .../components/anel_pwrctrl/switch.py | 2 +- .../components/bluesound/media_player.py | 32 +++++++++---------- homeassistant/components/buienradar/camera.py | 2 +- homeassistant/components/buienradar/sensor.py | 28 ++++++++-------- .../components/buienradar/weather.py | 2 +- .../components/cover/device_condition.py | 4 +-- homeassistant/components/darksky/sensor.py | 2 +- .../components/ddwrt/device_tracker.py | 6 ++-- homeassistant/components/dominos/__init__.py | 2 +- homeassistant/components/ecobee/weather.py | 2 +- homeassistant/components/ecovacs/vacuum.py | 4 +-- .../components/emulated_hue/__init__.py | 2 +- .../components/emulated_hue/hue_api.py | 2 +- homeassistant/components/flexit/climate.py | 4 +-- homeassistant/components/garadget/cover.py | 2 +- homeassistant/components/google/__init__.py | 2 +- homeassistant/components/hdmi_cec/__init__.py | 2 +- .../components/homekit/type_thermostats.py | 10 +++--- homeassistant/components/html5/notify.py | 2 +- homeassistant/components/icloud/__init__.py | 2 +- homeassistant/components/icloud/account.py | 2 +- homeassistant/components/kankun/switch.py | 4 +-- .../components/konnected/__init__.py | 6 ++-- .../components/mediaroom/media_player.py | 4 +-- homeassistant/components/nexia/climate.py | 8 ++--- homeassistant/components/pushover/notify.py | 18 +++++------ .../components/radiotherm/climate.py | 2 +- .../components/raspihats/__init__.py | 2 +- homeassistant/components/recorder/__init__.py | 2 +- homeassistant/components/rflink/__init__.py | 2 +- homeassistant/components/rflink/light.py | 2 +- homeassistant/components/sql/sensor.py | 2 +- homeassistant/components/statistics/sensor.py | 2 +- homeassistant/components/telegram/notify.py | 4 +-- homeassistant/components/toon/__init__.py | 2 +- homeassistant/components/torque/sensor.py | 3 +- homeassistant/components/zabbix/__init__.py | 4 +-- homeassistant/components/zwave/__init__.py | 2 +- homeassistant/scripts/check_config.py | 2 +- .../components/asuswrt/test_device_tracker.py | 2 +- tests/components/template/test_fan.py | 6 ++-- 45 files changed, 104 insertions(+), 110 deletions(-) diff --git a/homeassistant/auth/mfa_modules/notify.py b/homeassistant/auth/mfa_modules/notify.py index 80d0fa3f973..d8c28409b2d 100644 --- a/homeassistant/auth/mfa_modules/notify.py +++ b/homeassistant/auth/mfa_modules/notify.py @@ -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 diff --git a/homeassistant/components/abode/__init__.py b/homeassistant/components/abode/__init__.py index 84d1d34bd78..85e05e89cc1 100644 --- a/homeassistant/components/abode/__init__.py +++ b/homeassistant/components/abode/__init__.py @@ -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): diff --git a/homeassistant/components/acer_projector/switch.py b/homeassistant/components/acer_projector/switch.py index b28d67562d4..bc97a844a5a 100644 --- a/homeassistant/components/acer_projector/switch.py +++ b/homeassistant/components/acer_projector/switch.py @@ -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 diff --git a/homeassistant/components/alexa/capabilities.py b/homeassistant/components/alexa/capabilities.py index 5e1932ceb67..7451d15eb1c 100644 --- a/homeassistant/components/alexa/capabilities.py +++ b/homeassistant/components/alexa/capabilities.py @@ -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 diff --git a/homeassistant/components/anel_pwrctrl/switch.py b/homeassistant/components/anel_pwrctrl/switch.py index be6a76e3b6b..36306f18114 100644 --- a/homeassistant/components/anel_pwrctrl/switch.py +++ b/homeassistant/components/anel_pwrctrl/switch.py @@ -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) diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index 86e62adc618..a0f1d38ba77 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -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 diff --git a/homeassistant/components/buienradar/camera.py b/homeassistant/components/buienradar/camera.py index b685bdb5c73..78c8f82d1ff 100644 --- a/homeassistant/components/buienradar/camera.py +++ b/homeassistant/components/buienradar/camera.py @@ -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 diff --git a/homeassistant/components/buienradar/sensor.py b/homeassistant/components/buienradar/sensor.py index 235390d0013..ddaeec94228 100644 --- a/homeassistant/components/buienradar/sensor.py +++ b/homeassistant/components/buienradar/sensor.py @@ -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 diff --git a/homeassistant/components/buienradar/weather.py b/homeassistant/components/buienradar/weather.py index 32e8babde90..bd54f42fc21 100644 --- a/homeassistant/components/buienradar/weather.py +++ b/homeassistant/components/buienradar/weather.py @@ -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 diff --git a/homeassistant/components/cover/device_condition.py b/homeassistant/components/cover/device_condition.py index 7c6dc5fed72..0bcec2a6e43 100644 --- a/homeassistant/components/cover/device_condition.py +++ b/homeassistant/components/cover/device_condition.py @@ -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} }}}}" ) diff --git a/homeassistant/components/darksky/sensor.py b/homeassistant/components/darksky/sensor.py index 0d6814fca10..1517f47a2d5 100644 --- a/homeassistant/components/darksky/sensor.py +++ b/homeassistant/components/darksky/sensor.py @@ -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, diff --git a/homeassistant/components/ddwrt/device_tracker.py b/homeassistant/components/ddwrt/device_tracker.py index bd2728d03dc..a6bdb9c527b 100644 --- a/homeassistant/components/ddwrt/device_tracker.py +++ b/homeassistant/components/ddwrt/device_tracker.py @@ -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 diff --git a/homeassistant/components/dominos/__init__.py b/homeassistant/components/dominos/__init__.py index 78852fa2699..d3977384255 100644 --- a/homeassistant/components/dominos/__init__.py +++ b/homeassistant/components/dominos/__init__.py @@ -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 diff --git a/homeassistant/components/ecobee/weather.py b/homeassistant/components/ecobee/weather.py index 457d924d2fb..a7fe8d8a0f8 100644 --- a/homeassistant/components/ecobee/weather.py +++ b/homeassistant/components/ecobee/weather.py @@ -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): diff --git a/homeassistant/components/ecovacs/vacuum.py b/homeassistant/components/ecovacs/vacuum.py index 806c0b41285..8b6115970bb 100644 --- a/homeassistant/components/ecovacs/vacuum.py +++ b/homeassistant/components/ecovacs/vacuum.py @@ -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): diff --git a/homeassistant/components/emulated_hue/__init__.py b/homeassistant/components/emulated_hue/__init__.py index 1c37d0215a8..da6e7acab40 100644 --- a/homeassistant/components/emulated_hue/__init__.py +++ b/homeassistant/components/emulated_hue/__init__.py @@ -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 diff --git a/homeassistant/components/emulated_hue/hue_api.py b/homeassistant/components/emulated_hue/hue_api.py index 06a57960898..ecb0241c724 100644 --- a/homeassistant/components/emulated_hue/hue_api.py +++ b/homeassistant/components/emulated_hue/hue_api.py @@ -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] diff --git a/homeassistant/components/flexit/climate.py b/homeassistant/components/flexit/climate.py index fb031359693..68e13abf8d1 100644 --- a/homeassistant/components/flexit/climate.py +++ b/homeassistant/components/flexit/climate.py @@ -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) diff --git a/homeassistant/components/garadget/cover.py b/homeassistant/components/garadget/cover.py index 5a43c3c7281..a1f324be1ff 100644 --- a/homeassistant/components/garadget/cover.py +++ b/homeassistant/components/garadget/cover.py @@ -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"] diff --git a/homeassistant/components/google/__init__.py b/homeassistant/components/google/__init__.py index ec5afde0bac..93afb43cf52 100644 --- a/homeassistant/components/google/__init__.py +++ b/homeassistant/components/google/__init__.py @@ -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}) diff --git a/homeassistant/components/hdmi_cec/__init__.py b/homeassistant/components/hdmi_cec/__init__.py index b460020546f..471a2dd0f46 100644 --- a/homeassistant/components/hdmi_cec/__init__.py +++ b/homeassistant/components/hdmi_cec/__init__.py @@ -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) diff --git a/homeassistant/components/homekit/type_thermostats.py b/homeassistant/components/homekit/type_thermostats.py index 98905e045c5..ebb8ae3883e 100644 --- a/homeassistant/components/homekit/type_thermostats.py +++ b/homeassistant/components/homekit/type_thermostats.py @@ -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 diff --git a/homeassistant/components/html5/notify.py b/homeassistant/components/html5/notify.py index 679968d1b8d..6970ebbedb4 100644 --- a/homeassistant/components/html5/notify.py +++ b/homeassistant/components/html5/notify.py @@ -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 diff --git a/homeassistant/components/icloud/__init__.py b/homeassistant/components/icloud/__init__.py index ba0f42432cc..3879d15cda8 100644 --- a/homeassistant/components/icloud/__init__.py +++ b/homeassistant/components/icloud/__init__.py @@ -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: diff --git a/homeassistant/components/icloud/account.py b/homeassistant/components/icloud/account.py index 50a3e74f78f..e0d9a608605 100644 --- a/homeassistant/components/icloud/account.py +++ b/homeassistant/components/icloud/account.py @@ -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) diff --git a/homeassistant/components/kankun/switch.py b/homeassistant/components/kankun/switch.py index 4f7ba5c8b06..d9f4db62572 100644 --- a/homeassistant/components/kankun/switch.py +++ b/homeassistant/components/kankun/switch.py @@ -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), ) ) diff --git a/homeassistant/components/konnected/__init__.py b/homeassistant/components/konnected/__init__.py index 8df6f7cead6..75cc3126c24 100644 --- a/homeassistant/components/konnected/__init__.py +++ b/homeassistant/components/konnected/__init__.py @@ -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) diff --git a/homeassistant/components/mediaroom/media_player.py b/homeassistant/components/mediaroom/media_player.py index dd67cc28783..492c347959e 100644 --- a/homeassistant/components/mediaroom/media_player.py +++ b/homeassistant/components/mediaroom/media_player.py @@ -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 diff --git a/homeassistant/components/nexia/climate.py b/homeassistant/components/nexia/climate.py index 8af1be20b1e..a3a747d0123 100644 --- a/homeassistant/components/nexia/climate.py +++ b/homeassistant/components/nexia/climate.py @@ -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() diff --git a/homeassistant/components/pushover/notify.py b/homeassistant/components/pushover/notify.py index 01d4d8fddde..952a399157c 100644 --- a/homeassistant/components/pushover/notify.py +++ b/homeassistant/components/pushover/notify.py @@ -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 diff --git a/homeassistant/components/radiotherm/climate.py b/homeassistant/components/radiotherm/climate.py index cba7a736df2..acbd6fe7e5e 100644 --- a/homeassistant/components/radiotherm/climate.py +++ b/homeassistant/components/radiotherm/climate.py @@ -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 diff --git a/homeassistant/components/raspihats/__init__.py b/homeassistant/components/raspihats/__init__.py index fb544d3ebcc..e6fd3d7bb59 100644 --- a/homeassistant/components/raspihats/__init__.py +++ b/homeassistant/components/raspihats/__init__.py @@ -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) diff --git a/homeassistant/components/recorder/__init__.py b/homeassistant/components/recorder/__init__.py index ffd37720053..56f5b53326c 100644 --- a/homeassistant/components/recorder/__init__.py +++ b/homeassistant/components/recorder/__init__.py @@ -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)) diff --git a/homeassistant/components/rflink/__init__.py b/homeassistant/components/rflink/__init__.py index 76b225bd93a..542c63f3b7a 100644 --- a/homeassistant/components/rflink/__init__.py +++ b/homeassistant/components/rflink/__init__.py @@ -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 diff --git a/homeassistant/components/rflink/light.py b/homeassistant/components/rflink/light.py index 18650d2038e..348fff0da9a 100644 --- a/homeassistant/components/rflink/light.py +++ b/homeassistant/components/rflink/light.py @@ -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): diff --git a/homeassistant/components/sql/sensor.py b/homeassistant/components/sql/sensor.py index 52899c7da80..f19941ed043 100644 --- a/homeassistant/components/sql/sensor.py +++ b/homeassistant/components/sql/sensor.py @@ -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)) diff --git a/homeassistant/components/statistics/sensor.py b/homeassistant/components/statistics/sensor.py index 0fb08a0fecb..226d278633b 100644 --- a/homeassistant/components/statistics/sensor.py +++ b/homeassistant/components/statistics/sensor.py @@ -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( diff --git a/homeassistant/components/telegram/notify.py b/homeassistant/components/telegram/notify.py index ceb660d9e1d..673935d8283 100644 --- a/homeassistant/components/telegram/notify.py +++ b/homeassistant/components/telegram/notify.py @@ -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) diff --git a/homeassistant/components/toon/__init__.py b/homeassistant/components/toon/__init__.py index 612561707b1..b078dab898d 100644 --- a/homeassistant/components/toon/__init__.py +++ b/homeassistant/components/toon/__init__.py @@ -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 diff --git a/homeassistant/components/torque/sensor.py b/homeassistant/components/torque/sensor.py index dbb650a8b48..fd7eddbb48a 100644 --- a/homeassistant/components/torque/sensor.py +++ b/homeassistant/components/torque/sensor.py @@ -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]]) diff --git a/homeassistant/components/zabbix/__init__.py b/homeassistant/components/zabbix/__init__.py index 0926f35af38..b6576fc6893 100644 --- a/homeassistant/components/zabbix/__init__.py +++ b/homeassistant/components/zabbix/__init__.py @@ -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: diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index 279cd5b8eb0..f8149782db6 100644 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -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 diff --git a/homeassistant/scripts/check_config.py b/homeassistant/scripts/check_config.py index 25b25f41a20..627f5b9d976 100644 --- a/homeassistant/scripts/check_config.py +++ b/homeassistant/scripts/check_config.py @@ -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] = {} diff --git a/tests/components/asuswrt/test_device_tracker.py b/tests/components/asuswrt/test_device_tracker.py index 62e5ed891ff..3954808aa37 100644 --- a/tests/components/asuswrt/test_device_tracker.py +++ b/tests/components/asuswrt/test_device_tracker.py @@ -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): diff --git a/tests/components/template/test_fan.py b/tests/components/template/test_fan.py index b6b0a87c9f2..fb02e4f3227 100644 --- a/tests/components/template/test_fan.py +++ b/tests/components/template/test_fan.py @@ -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):