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