Skip to content

Commit

Permalink
maint: Sourcery recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Jan 13, 2025
1 parent f527aba commit 06edb16
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 51 deletions.
18 changes: 6 additions & 12 deletions custom_components/homelink/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ def _update_attributes(self) -> None:
self._status, self._alarms_devices, self._alarms_rooms = self._set_status()

def _is_data_in_coordinator(self) -> bool:
if self._key in self.coordinator.data[COORD_PROPERTIES]:
return True
return False
return self._key in self.coordinator.data[COORD_PROPERTIES]

def _set_status(self) -> tuple[bool, list[str | None] | str, list[Any] | str]:
status = STATUS_GOOD
Expand Down Expand Up @@ -563,15 +561,11 @@ def _update_attributes(self) -> None:
self._status = self._set_status()

def _is_data_in_coordinator(self) -> bool:
if (
self._parent_key not in self.coordinator.data[COORD_PROPERTIES]
or self._key
not in self.coordinator.data[COORD_PROPERTIES][self._parent_key][
COORD_DEVICES
]
):
return False
return True
return (
self._parent_key in self.coordinator.data[COORD_PROPERTIES]
and self._key
in self.coordinator.data[COORD_PROPERTIES][self._parent_key][COORD_DEVICES]
)

def _set_status(self) -> bool:
return bool(self._get_alerts())
Expand Down
42 changes: 19 additions & 23 deletions custom_components/homelink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,11 @@ def _update_attributes(self) -> None:
break

def _is_data_in_coordinator(self) -> bool:
if (
self._parent_key not in self.coordinator.data[COORD_PROPERTIES]
or self._key
not in self.coordinator.data[COORD_PROPERTIES][self._parent_key][
COORD_DEVICES
]
):
return False
return True
return (
self._parent_key in self.coordinator.data[COORD_PROPERTIES]
and self._key
in self.coordinator.data[COORD_PROPERTIES][self._parent_key][COORD_DEVICES]
)

def _update_values(self, value: Any) -> None:
self._state = value.value
Expand Down Expand Up @@ -475,15 +471,15 @@ def _update_attributes(self) -> None:
self._insight = insight

def _is_data_in_coordinator(self) -> bool:
for insight in self.coordinator.data[COORD_PROPERTIES][self._key][
COORD_INSIGHTS
]:
if (
return any(
(
insight.appliesto == APPLIESTO_PROPERTY
and insight.hl_type == self._insight.hl_type
):
return True
return False
)
for insight in self.coordinator.data[COORD_PROPERTIES][self._key][
COORD_INSIGHTS
]
)


class HomeLINKRoomInsightSensor(HomeLINKDeviceEntity, SensorEntity):
Expand Down Expand Up @@ -557,13 +553,13 @@ def _update_attributes(self) -> None:
self._insight = insight

def _is_data_in_coordinator(self) -> bool:
for insight in self.coordinator.data[COORD_PROPERTIES][self._parent_key][
COORD_INSIGHTS
]:
if (
return any(
(
insight.appliesto == APPLIESTO_ROOM
and insight.location == self._insight.location
and insight.hl_type == self._insight.hl_type
):
return True
return False
)
for insight in self.coordinator.data[COORD_PROPERTIES][self._parent_key][
COORD_INSIGHTS
]
)
26 changes: 10 additions & 16 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# pylint: disable=protected-access,redefined-outer-name
"""Global fixtures for integration."""

import sys
from dataclasses import dataclass
from datetime import date
import sys
from unittest.mock import Mock, PropertyMock, patch

import pytest
from aiohttp import ClientSession
from aiohttp.test_utils import TestClient
import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry
from pytest_homeassistant_custom_component.test_util.aiohttp import AiohttpClientMocker
from pytest_homeassistant_custom_component.typing import ClientSessionGenerator

from custom_components.homelink import HLData
from custom_components.homelink.const import DOMAIN
from homeassistant.components.application_credentials import (
ClientCredential,
async_import_client_credential,
Expand All @@ -23,6 +17,12 @@
from homeassistant.core import Event, HomeAssistant
from homeassistant.core_config import async_process_ha_core_config
from homeassistant.setup import async_setup_component
from pytest_homeassistant_custom_component.common import MockConfigEntry
from pytest_homeassistant_custom_component.test_util.aiohttp import AiohttpClientMocker
from pytest_homeassistant_custom_component.typing import ClientSessionGenerator

from custom_components.homelink import HLData
from custom_components.homelink.const import DOMAIN

from .helpers.const import ( # MQTT_HA_OPTIONS,; MQTT_HL_OPTIONS,
BASE_CONFIG_ENTRY,
Expand Down Expand Up @@ -216,10 +216,7 @@ async def setup_webhook_integration(
webhook_config_entry: HomelinkMockConfigEntry,
) -> None:
"""Fixture for setting up the component."""
if hasattr(request, "param"):
method_name = request.param
else:
method_name = "standard_mocks"
method_name = request.param if hasattr(request, "param") else "standard_mocks"

mock_method = getattr(THIS_MODULE, method_name)
mock_method(aioclient_mock)
Expand All @@ -243,10 +240,7 @@ async def setup_insight_integration(
insight_config_entry: HomelinkMockConfigEntry,
) -> None:
"""Fixture for setting up the component."""
if hasattr(request, "param"):
method_name = request.param
else:
method_name = "standard_mocks"
method_name = request.param if hasattr(request, "param") else "standard_mocks"

mock_method = getattr(THIS_MODULE, method_name)
mock_method(aioclient_mock)
Expand Down

0 comments on commit 06edb16

Please sign in to comment.