Enable Ruff RET502 (#115139)
This commit is contained in:
parent
ff2b851683
commit
c2b3bf3fb9
34 changed files with 87 additions and 86 deletions
|
@ -415,13 +415,14 @@ async def async_send_changereport_message(
|
|||
if invalidate_access_token:
|
||||
# Invalidate the access token and try again
|
||||
config.async_invalidate_access_token()
|
||||
return await async_send_changereport_message(
|
||||
await async_send_changereport_message(
|
||||
hass,
|
||||
config,
|
||||
alexa_entity,
|
||||
alexa_properties,
|
||||
invalidate_access_token=False,
|
||||
)
|
||||
return
|
||||
await config.set_authorized(False)
|
||||
|
||||
_LOGGER.error(
|
||||
|
|
|
@ -344,7 +344,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
):
|
||||
"""Send command to the player."""
|
||||
if not self._is_online and not allow_offline:
|
||||
return
|
||||
return None
|
||||
|
||||
if method[0] == "/":
|
||||
method = method[1:]
|
||||
|
@ -468,7 +468,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
"""Update Capture sources."""
|
||||
resp = await self.send_bluesound_command("RadioBrowse?service=Capture")
|
||||
if not resp:
|
||||
return
|
||||
return None
|
||||
self._capture_items = []
|
||||
|
||||
def _create_capture_item(item):
|
||||
|
@ -496,7 +496,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
"""Update Presets."""
|
||||
resp = await self.send_bluesound_command("Presets")
|
||||
if not resp:
|
||||
return
|
||||
return None
|
||||
self._preset_items = []
|
||||
|
||||
def _create_preset_item(item):
|
||||
|
@ -526,7 +526,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
"""Update Services."""
|
||||
resp = await self.send_bluesound_command("Services")
|
||||
if not resp:
|
||||
return
|
||||
return None
|
||||
self._services_items = []
|
||||
|
||||
def _create_service_item(item):
|
||||
|
@ -603,7 +603,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
return None
|
||||
|
||||
if not (url := self._status.get("image")):
|
||||
return
|
||||
return None
|
||||
if url[0] == "/":
|
||||
url = f"http://{self.host}:{self.port}{url}"
|
||||
|
||||
|
@ -937,14 +937,14 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if selected_source.get("is_raw_url"):
|
||||
url = selected_source["url"]
|
||||
|
||||
return await self.send_bluesound_command(url)
|
||||
await self.send_bluesound_command(url)
|
||||
|
||||
async def async_clear_playlist(self) -> None:
|
||||
"""Clear players playlist."""
|
||||
if self.is_grouped and not self.is_master:
|
||||
return
|
||||
|
||||
return await self.send_bluesound_command("Clear")
|
||||
await self.send_bluesound_command("Clear")
|
||||
|
||||
async def async_media_next_track(self) -> None:
|
||||
"""Send media_next command to media player."""
|
||||
|
@ -957,7 +957,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if "@name" in action and "@url" in action and action["@name"] == "skip":
|
||||
cmd = action["@url"]
|
||||
|
||||
return await self.send_bluesound_command(cmd)
|
||||
await self.send_bluesound_command(cmd)
|
||||
|
||||
async def async_media_previous_track(self) -> None:
|
||||
"""Send media_previous command to media player."""
|
||||
|
@ -970,35 +970,35 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if "@name" in action and "@url" in action and action["@name"] == "back":
|
||||
cmd = action["@url"]
|
||||
|
||||
return await self.send_bluesound_command(cmd)
|
||||
await self.send_bluesound_command(cmd)
|
||||
|
||||
async def async_media_play(self) -> None:
|
||||
"""Send media_play command to media player."""
|
||||
if self.is_grouped and not self.is_master:
|
||||
return
|
||||
|
||||
return await self.send_bluesound_command("Play")
|
||||
await self.send_bluesound_command("Play")
|
||||
|
||||
async def async_media_pause(self) -> None:
|
||||
"""Send media_pause command to media player."""
|
||||
if self.is_grouped and not self.is_master:
|
||||
return
|
||||
|
||||
return await self.send_bluesound_command("Pause")
|
||||
await self.send_bluesound_command("Pause")
|
||||
|
||||
async def async_media_stop(self) -> None:
|
||||
"""Send stop command."""
|
||||
if self.is_grouped and not self.is_master:
|
||||
return
|
||||
|
||||
return await self.send_bluesound_command("Pause")
|
||||
await self.send_bluesound_command("Pause")
|
||||
|
||||
async def async_media_seek(self, position: float) -> None:
|
||||
"""Send media_seek command to media player."""
|
||||
if self.is_grouped and not self.is_master:
|
||||
return
|
||||
|
||||
return await self.send_bluesound_command(f"Play?seek={float(position)}")
|
||||
await self.send_bluesound_command(f"Play?seek={float(position)}")
|
||||
|
||||
async def async_play_media(
|
||||
self, media_type: MediaType | str, media_id: str, **kwargs: Any
|
||||
|
@ -1017,21 +1017,21 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
|
||||
url = f"Play?url={media_id}"
|
||||
|
||||
return await self.send_bluesound_command(url)
|
||||
await self.send_bluesound_command(url)
|
||||
|
||||
async def async_volume_up(self) -> None:
|
||||
"""Volume up the media player."""
|
||||
current_vol = self.volume_level
|
||||
if not current_vol or current_vol >= 1:
|
||||
return
|
||||
return await self.async_set_volume_level(current_vol + 0.01)
|
||||
await self.async_set_volume_level(current_vol + 0.01)
|
||||
|
||||
async def async_volume_down(self) -> None:
|
||||
"""Volume down the media player."""
|
||||
current_vol = self.volume_level
|
||||
if not current_vol or current_vol <= 0:
|
||||
return
|
||||
return await self.async_set_volume_level(current_vol - 0.01)
|
||||
await self.async_set_volume_level(current_vol - 0.01)
|
||||
|
||||
async def async_set_volume_level(self, volume: float) -> None:
|
||||
"""Send volume_up command to media player."""
|
||||
|
@ -1039,13 +1039,13 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
volume = 0
|
||||
elif volume > 1:
|
||||
volume = 1
|
||||
return await self.send_bluesound_command(f"Volume?level={float(volume) * 100}")
|
||||
await self.send_bluesound_command(f"Volume?level={float(volume) * 100}")
|
||||
|
||||
async def async_mute_volume(self, mute: bool) -> None:
|
||||
"""Send mute command to media player."""
|
||||
if mute:
|
||||
return await self.send_bluesound_command("Volume?mute=1")
|
||||
return await self.send_bluesound_command("Volume?mute=0")
|
||||
await self.send_bluesound_command("Volume?mute=1")
|
||||
await self.send_bluesound_command("Volume?mute=0")
|
||||
|
||||
async def async_browse_media(
|
||||
self,
|
||||
|
|
|
@ -152,7 +152,7 @@ class DdWrtDeviceScanner(DeviceScanner):
|
|||
)
|
||||
except requests.exceptions.Timeout:
|
||||
_LOGGER.exception("Connection to the router timed out")
|
||||
return
|
||||
return None
|
||||
if response.status_code == HTTPStatus.OK:
|
||||
return _parse_ddwrt_response(response.text)
|
||||
if response.status_code == HTTPStatus.UNAUTHORIZED:
|
||||
|
@ -160,7 +160,7 @@ class DdWrtDeviceScanner(DeviceScanner):
|
|||
_LOGGER.exception(
|
||||
"Failed to authenticate, check your username and password"
|
||||
)
|
||||
return
|
||||
return None
|
||||
_LOGGER.error("Invalid response from DD-WRT: %s", response)
|
||||
|
||||
|
||||
|
|
|
@ -112,12 +112,12 @@ async def async_handle_message(hass, message):
|
|||
)
|
||||
req = message.get("result")
|
||||
if req.get("actionIncomplete", True):
|
||||
return
|
||||
return None
|
||||
|
||||
elif _api_version is V2:
|
||||
req = message.get("queryResult")
|
||||
if req.get("allRequiredParamsPresent", False) is False:
|
||||
return
|
||||
return None
|
||||
|
||||
action = req.get("action", "")
|
||||
parameters = req.get("parameters").copy()
|
||||
|
|
|
@ -184,7 +184,7 @@ class FireServiceRotaClient:
|
|||
async def update_call(self, func, *args):
|
||||
"""Perform update call and return data."""
|
||||
if self.token_refresh_failure:
|
||||
return
|
||||
return None
|
||||
|
||||
try:
|
||||
return await self._hass.async_add_executor_job(func, *args)
|
||||
|
|
|
@ -699,7 +699,8 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
|||
return
|
||||
|
||||
if kwargs.get(ATTR_MEDIA_ANNOUNCE):
|
||||
return await self._async_announce(media_id)
|
||||
await self._async_announce(media_id)
|
||||
return
|
||||
|
||||
# if kwargs[ATTR_MEDIA_ENQUEUE] is None, we assume MediaPlayerEnqueue.REPLACE
|
||||
# if kwargs[ATTR_MEDIA_ENQUEUE] is True, we assume MediaPlayerEnqueue.ADD
|
||||
|
@ -709,11 +710,12 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
|||
ATTR_MEDIA_ENQUEUE, MediaPlayerEnqueue.REPLACE
|
||||
)
|
||||
if enqueue in {True, MediaPlayerEnqueue.ADD, MediaPlayerEnqueue.REPLACE}:
|
||||
return await self.api.add_to_queue(
|
||||
await self.api.add_to_queue(
|
||||
uris=media_id,
|
||||
playback="start",
|
||||
clear=enqueue == MediaPlayerEnqueue.REPLACE,
|
||||
)
|
||||
return
|
||||
|
||||
current_position = next(
|
||||
(
|
||||
|
@ -724,13 +726,14 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
|||
0,
|
||||
)
|
||||
if enqueue == MediaPlayerEnqueue.NEXT:
|
||||
return await self.api.add_to_queue(
|
||||
await self.api.add_to_queue(
|
||||
uris=media_id,
|
||||
playback="start",
|
||||
position=current_position + 1,
|
||||
)
|
||||
return
|
||||
# enqueue == MediaPlayerEnqueue.PLAY
|
||||
return await self.api.add_to_queue(
|
||||
await self.api.add_to_queue(
|
||||
uris=media_id,
|
||||
playback="start",
|
||||
position=current_position,
|
||||
|
|
|
@ -308,10 +308,9 @@ class AFSAPIDevice(MediaPlayerEntity):
|
|||
# Keys of presets are 0-based, while the list shown on the device starts from 1
|
||||
preset = int(keys[0]) - 1
|
||||
|
||||
result = await self.fs_device.select_preset(preset)
|
||||
await self.fs_device.select_preset(preset)
|
||||
else:
|
||||
result = await self.fs_device.nav_select_item_via_path(keys)
|
||||
await self.fs_device.nav_select_item_via_path(keys)
|
||||
|
||||
await self.async_update()
|
||||
self._attr_media_content_id = media_id
|
||||
return result
|
||||
|
|
|
@ -151,9 +151,8 @@ class ExposedEntities:
|
|||
"""
|
||||
entity_registry = er.async_get(self._hass)
|
||||
if not (registry_entry := entity_registry.async_get(entity_id)):
|
||||
return self._async_set_legacy_assistant_option(
|
||||
assistant, entity_id, key, value
|
||||
)
|
||||
self._async_set_legacy_assistant_option(assistant, entity_id, key, value)
|
||||
return
|
||||
|
||||
assistant_options: ReadOnlyDict[str, Any] | dict[str, Any]
|
||||
if (
|
||||
|
|
|
@ -141,7 +141,7 @@ class IPMAWeather(WeatherEntity, IPMADevice):
|
|||
forecast = self._hourly_forecast
|
||||
|
||||
if not forecast:
|
||||
return
|
||||
return None
|
||||
|
||||
return self._condition_conversion(forecast[0].weather_type.id, None)
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ async def async_setup_entry(
|
|||
def async_update_data():
|
||||
"""Handle updated data from the API endpoint."""
|
||||
if not coordinator.last_update_success:
|
||||
return
|
||||
return None
|
||||
|
||||
devices = coordinator.data
|
||||
entities = []
|
||||
|
|
|
@ -86,7 +86,7 @@ class MerakiView(HomeAssistantView):
|
|||
_LOGGER.debug("Processing %s", data["type"])
|
||||
if not data["data"]["observations"]:
|
||||
_LOGGER.debug("No observations found")
|
||||
return
|
||||
return None
|
||||
self._handle(request.app[KEY_HASS], data)
|
||||
|
||||
@callback
|
||||
|
|
|
@ -131,7 +131,7 @@ class NSDepartureSensor(SensorEntity):
|
|||
def extra_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
if not self._trips:
|
||||
return
|
||||
return None
|
||||
|
||||
if self._trips[0].trip_parts:
|
||||
route = [self._trips[0].departure]
|
||||
|
|
|
@ -213,7 +213,7 @@ class OpenThermClimate(ClimateEntity):
|
|||
def current_temperature(self):
|
||||
"""Return the current temperature."""
|
||||
if self._current_temperature is None:
|
||||
return
|
||||
return None
|
||||
if self.floor_temp is True:
|
||||
if self.precision == PRECISION_HALVES:
|
||||
return int(2 * self._current_temperature) / 2
|
||||
|
|
|
@ -194,7 +194,7 @@ async def handle_webhook(hass, webhook_id, request):
|
|||
data = WEBHOOK_SCHEMA(await request.json())
|
||||
except vol.MultipleInvalid as error:
|
||||
_LOGGER.warning("An error occurred when parsing webhook data <%s>", error)
|
||||
return
|
||||
return None
|
||||
|
||||
device_id = _device_id(data)
|
||||
sensor_data = PlaatoAirlock.from_web_hook(data)
|
||||
|
|
|
@ -200,7 +200,7 @@ def execute(hass, filename, source, data=None, return_response=False):
|
|||
_LOGGER.error(
|
||||
"Error loading script %s: %s", filename, ", ".join(compiled.errors)
|
||||
)
|
||||
return
|
||||
return None
|
||||
|
||||
if compiled.warnings:
|
||||
_LOGGER.warning(
|
||||
|
|
|
@ -922,13 +922,15 @@ class Recorder(threading.Thread):
|
|||
assert isinstance(task, RecorderTask)
|
||||
if task.commit_before:
|
||||
self._commit_event_session_or_retry()
|
||||
return task.run(self)
|
||||
task.run(self)
|
||||
except exc.DatabaseError as err:
|
||||
if self._handle_database_error(err):
|
||||
return
|
||||
_LOGGER.exception("Unhandled database error while processing task %s", task)
|
||||
except SQLAlchemyError:
|
||||
_LOGGER.exception("SQLAlchemyError error processing task %s", task)
|
||||
else:
|
||||
return
|
||||
|
||||
# Reset the session if an SQLAlchemyError (including DatabaseError)
|
||||
# happens to rollback and recover
|
||||
|
|
|
@ -174,7 +174,7 @@ class Gateway:
|
|||
"""Get the model of the modem."""
|
||||
model = await self._worker.get_model_async()
|
||||
if not model or not model[0]:
|
||||
return
|
||||
return None
|
||||
display = model[0] # Identification model
|
||||
if model[1]: # Real model
|
||||
display = f"{display} ({model[1]})"
|
||||
|
@ -184,7 +184,7 @@ class Gateway:
|
|||
"""Get the firmware information of the modem."""
|
||||
firmware = await self._worker.get_firmware_async()
|
||||
if not firmware or not firmware[0]:
|
||||
return
|
||||
return None
|
||||
display = firmware[0] # Version
|
||||
if firmware[1]: # Date
|
||||
display = f"{display} ({firmware[1]})"
|
||||
|
|
|
@ -167,14 +167,14 @@ class SnmpScanner(DeviceScanner):
|
|||
async for errindication, errstatus, errindex, res in walker:
|
||||
if errindication:
|
||||
_LOGGER.error("SNMPLIB error: %s", errindication)
|
||||
return
|
||||
return None
|
||||
if errstatus:
|
||||
_LOGGER.error(
|
||||
"SNMP error: %s at %s",
|
||||
errstatus.prettyPrint(),
|
||||
errindex and res[int(errindex) - 1][0] or "?",
|
||||
)
|
||||
return
|
||||
return None
|
||||
|
||||
for _oid, value in res:
|
||||
if not isEndOfMib(res):
|
||||
|
|
|
@ -396,7 +396,7 @@ class SongpalEntity(MediaPlayerEntity):
|
|||
async def async_turn_on(self) -> None:
|
||||
"""Turn the device on."""
|
||||
try:
|
||||
return await self._dev.set_power(True)
|
||||
await self._dev.set_power(True)
|
||||
except SongpalException as ex:
|
||||
if ex.code == ERROR_REQUEST_RETRY:
|
||||
_LOGGER.debug(
|
||||
|
@ -408,7 +408,7 @@ class SongpalEntity(MediaPlayerEntity):
|
|||
async def async_turn_off(self) -> None:
|
||||
"""Turn the device off."""
|
||||
try:
|
||||
return await self._dev.set_power(False)
|
||||
await self._dev.set_power(False)
|
||||
except SongpalException as ex:
|
||||
if ex.code == ERROR_REQUEST_RETRY:
|
||||
_LOGGER.debug(
|
||||
|
|
|
@ -373,7 +373,8 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||
raise ValueError(
|
||||
f"Media type {media_type} is not supported when enqueue is ADD"
|
||||
)
|
||||
return self.data.client.add_to_queue(media_id, kwargs.get("device_id"))
|
||||
self.data.client.add_to_queue(media_id, kwargs.get("device_id"))
|
||||
return
|
||||
|
||||
self.data.client.start_playback(**kwargs)
|
||||
|
||||
|
|
|
@ -369,7 +369,7 @@ class SQLSensor(ManualTriggerSensorEntity):
|
|||
)
|
||||
sess.rollback()
|
||||
sess.close()
|
||||
return
|
||||
return None
|
||||
|
||||
for res in result.mappings():
|
||||
_LOGGER.debug("Query %s result in %s", self._query, res.items())
|
||||
|
|
|
@ -108,21 +108,21 @@ class TelegramNotificationService(BaseNotificationService):
|
|||
for photo_data in photos:
|
||||
service_data.update(photo_data)
|
||||
self.hass.services.call(DOMAIN, "send_photo", service_data=service_data)
|
||||
return
|
||||
return None
|
||||
if data is not None and ATTR_VIDEO in data:
|
||||
videos = data.get(ATTR_VIDEO)
|
||||
videos = videos if isinstance(videos, list) else [videos]
|
||||
for video_data in videos:
|
||||
service_data.update(video_data)
|
||||
self.hass.services.call(DOMAIN, "send_video", service_data=service_data)
|
||||
return
|
||||
return None
|
||||
if data is not None and ATTR_VOICE in data:
|
||||
voices = data.get(ATTR_VOICE)
|
||||
voices = voices if isinstance(voices, list) else [voices]
|
||||
for voice_data in voices:
|
||||
service_data.update(voice_data)
|
||||
self.hass.services.call(DOMAIN, "send_voice", service_data=service_data)
|
||||
return
|
||||
return None
|
||||
if data is not None and ATTR_LOCATION in data:
|
||||
service_data.update(data.get(ATTR_LOCATION))
|
||||
return self.hass.services.call(
|
||||
|
|
|
@ -107,10 +107,10 @@ class ThomsonDeviceScanner(DeviceScanner):
|
|||
telnet.write(b"exit\r\n")
|
||||
except EOFError:
|
||||
_LOGGER.exception("Unexpected response from router")
|
||||
return
|
||||
return None
|
||||
except ConnectionRefusedError:
|
||||
_LOGGER.exception("Connection refused by router. Telnet enabled?")
|
||||
return
|
||||
return None
|
||||
|
||||
devices = {}
|
||||
for device in devices_result:
|
||||
|
|
|
@ -248,7 +248,7 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
def _entity_lkp(self, entity_id, state_attr=None):
|
||||
"""Look up an entity state."""
|
||||
if (state_obj := self.hass.states.get(entity_id)) is None:
|
||||
return
|
||||
return None
|
||||
|
||||
if state_attr:
|
||||
return state_obj.attributes.get(state_attr)
|
||||
|
|
|
@ -100,12 +100,12 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
or state.entity_id in exclude_e
|
||||
or state.domain in exclude_d
|
||||
):
|
||||
return
|
||||
return None
|
||||
|
||||
if (include_e and state.entity_id not in include_e) or (
|
||||
include_d and state.domain not in include_d
|
||||
):
|
||||
return
|
||||
return None
|
||||
|
||||
try:
|
||||
_state_as_value = float(state.state)
|
||||
|
|
|
@ -100,27 +100,27 @@ def ws_require_user(
|
|||
|
||||
if only_owner and not connection.user.is_owner:
|
||||
output_error("only_owner", "Only allowed as owner")
|
||||
return
|
||||
return None
|
||||
|
||||
if only_system_user and not connection.user.system_generated:
|
||||
output_error("only_system_user", "Only allowed as system user")
|
||||
return
|
||||
return None
|
||||
|
||||
if not allow_system_user and connection.user.system_generated:
|
||||
output_error("not_system_user", "Not allowed as system user")
|
||||
return
|
||||
return None
|
||||
|
||||
if only_active_user and not connection.user.is_active:
|
||||
output_error("only_active_user", "Only allowed as active user")
|
||||
return
|
||||
return None
|
||||
|
||||
if only_inactive_user and connection.user.is_active:
|
||||
output_error("only_inactive_user", "Not allowed as active user")
|
||||
return
|
||||
return None
|
||||
|
||||
if only_supervisor and connection.user.name != HASSIO_USER_NAME:
|
||||
output_error("only_supervisor", "Only allowed as Supervisor")
|
||||
return
|
||||
return None
|
||||
|
||||
return func(hass, connection, msg)
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class XiaomiDeviceScanner(DeviceScanner):
|
|||
self.mac2name = dict(mac2name_list)
|
||||
else:
|
||||
# Error, handled in the _retrieve_list_with_retry
|
||||
return
|
||||
return None
|
||||
return self.mac2name.get(device.upper(), None)
|
||||
|
||||
def _update_info(self):
|
||||
|
@ -117,34 +117,34 @@ def _retrieve_list(host, token, **kwargs):
|
|||
res = requests.get(url, timeout=10, **kwargs)
|
||||
except requests.exceptions.Timeout:
|
||||
_LOGGER.exception("Connection to the router timed out at URL %s", url)
|
||||
return
|
||||
return None
|
||||
if res.status_code != HTTPStatus.OK:
|
||||
_LOGGER.exception("Connection failed with http code %s", res.status_code)
|
||||
return
|
||||
return None
|
||||
try:
|
||||
result = res.json()
|
||||
except ValueError:
|
||||
# If json decoder could not parse the response
|
||||
_LOGGER.exception("Failed to parse response from mi router")
|
||||
return
|
||||
return None
|
||||
try:
|
||||
xiaomi_code = result["code"]
|
||||
except KeyError:
|
||||
_LOGGER.exception("No field code in response from mi router. %s", result)
|
||||
return
|
||||
return None
|
||||
if xiaomi_code == 0:
|
||||
try:
|
||||
return result["list"]
|
||||
except KeyError:
|
||||
_LOGGER.exception("No list in response from mi router. %s", result)
|
||||
return
|
||||
return None
|
||||
else:
|
||||
_LOGGER.info(
|
||||
"Receive wrong Xiaomi code %s, expected 0 in response %s",
|
||||
xiaomi_code,
|
||||
result,
|
||||
)
|
||||
return
|
||||
return None
|
||||
|
||||
|
||||
def _get_token(host, username, password):
|
||||
|
@ -155,14 +155,14 @@ def _get_token(host, username, password):
|
|||
res = requests.post(url, data=data, timeout=5)
|
||||
except requests.exceptions.Timeout:
|
||||
_LOGGER.exception("Connection to the router timed out")
|
||||
return
|
||||
return None
|
||||
if res.status_code == HTTPStatus.OK:
|
||||
try:
|
||||
result = res.json()
|
||||
except ValueError:
|
||||
# If JSON decoder could not parse the response
|
||||
_LOGGER.exception("Failed to parse response from mi router")
|
||||
return
|
||||
return None
|
||||
try:
|
||||
return result["token"]
|
||||
except KeyError:
|
||||
|
@ -171,7 +171,7 @@ def _get_token(host, username, password):
|
|||
"url: [%s] \nwith parameter: [%s] \nwas: [%s]"
|
||||
)
|
||||
_LOGGER.exception(error_message, url, data, result)
|
||||
return
|
||||
return None
|
||||
else:
|
||||
_LOGGER.error(
|
||||
"Invalid response: [%s] at url: [%s] with data [%s]", res, url, data
|
||||
|
|
|
@ -268,7 +268,7 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
|
|||
"bug (https://github.com/home-assistant/core/pull/"
|
||||
"11631#issuecomment-357507744)"
|
||||
)
|
||||
return
|
||||
return None
|
||||
|
||||
if NO_MOTION in data:
|
||||
self._no_motion_since = data[NO_MOTION]
|
||||
|
|
|
@ -834,7 +834,8 @@ async def async_setup_entry(
|
|||
elif model in MODELS_VACUUM or model.startswith(
|
||||
(ROBOROCK_GENERIC, ROCKROBO_GENERIC)
|
||||
):
|
||||
return _setup_vacuum_sensors(hass, config_entry, async_add_entities)
|
||||
_setup_vacuum_sensors(hass, config_entry, async_add_entities)
|
||||
return
|
||||
|
||||
for sensor, description in SENSOR_TYPES.items():
|
||||
if sensor not in sensors:
|
||||
|
|
|
@ -149,7 +149,7 @@ class YiCamera(Camera):
|
|||
async def handle_async_mjpeg_stream(self, request):
|
||||
"""Generate an HTTP MJPEG stream from the camera."""
|
||||
if not self._is_on:
|
||||
return
|
||||
return None
|
||||
|
||||
stream = CameraMjpeg(self._manager.binary)
|
||||
await stream.open_camera(self._last_url, extra_cmd=self._extra_arguments)
|
||||
|
|
|
@ -104,11 +104,11 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
"""Add an event to the outgoing Zabbix list."""
|
||||
state = event.data.get("new_state")
|
||||
if state is None or state.state in (STATE_UNKNOWN, "", STATE_UNAVAILABLE):
|
||||
return
|
||||
return None
|
||||
|
||||
entity_id = state.entity_id
|
||||
if not entities_filter(entity_id):
|
||||
return
|
||||
return None
|
||||
|
||||
floats = {}
|
||||
strings = {}
|
||||
|
|
|
@ -38,7 +38,7 @@ def async_create_flow(
|
|||
)
|
||||
return
|
||||
|
||||
return dispatcher.async_create(domain, context, data)
|
||||
dispatcher.async_create(domain, context, data)
|
||||
|
||||
|
||||
@callback
|
||||
|
|
|
@ -800,7 +800,6 @@ ignore = [
|
|||
"PT019",
|
||||
"PYI024", # Use typing.NamedTuple instead of collections.namedtuple
|
||||
"RET503",
|
||||
"RET502",
|
||||
"RET501",
|
||||
"TRY002",
|
||||
"TRY301"
|
||||
|
|
|
@ -39,7 +39,6 @@ def encrypt_payload(secret_key, payload, encode_json=True):
|
|||
from nacl.secret import SecretBox
|
||||
except (ImportError, OSError):
|
||||
pytest.skip("libnacl/libsodium is not installed")
|
||||
return
|
||||
|
||||
import json
|
||||
|
||||
|
@ -61,7 +60,6 @@ def encrypt_payload_legacy(secret_key, payload, encode_json=True):
|
|||
from nacl.secret import SecretBox
|
||||
except (ImportError, OSError):
|
||||
pytest.skip("libnacl/libsodium is not installed")
|
||||
return
|
||||
|
||||
import json
|
||||
|
||||
|
@ -86,7 +84,6 @@ def decrypt_payload(secret_key, encrypted_data):
|
|||
from nacl.secret import SecretBox
|
||||
except (ImportError, OSError):
|
||||
pytest.skip("libnacl/libsodium is not installed")
|
||||
return
|
||||
|
||||
import json
|
||||
|
||||
|
@ -107,7 +104,6 @@ def decrypt_payload_legacy(secret_key, encrypted_data):
|
|||
from nacl.secret import SecretBox
|
||||
except (ImportError, OSError):
|
||||
pytest.skip("libnacl/libsodium is not installed")
|
||||
return
|
||||
|
||||
import json
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue