From ea9fea579c4cd94f9367e6e14e98d54a14991eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Ljubenovi=C4=87?= Date: Wed, 4 Sep 2024 21:01:08 +0200 Subject: [PATCH] added pragmas not to cover already covered by ha --- custom_components/catlink/__init__.py | 1 + custom_components/catlink/binary_sensor.py | 2 +- custom_components/catlink/button.py | 4 +-- .../catlink/entitites/catlink_binary.py | 2 +- custom_components/catlink/helpers.py | 4 +-- custom_components/catlink/sensor.py | 2 +- custom_components/catlink/switch.py | 4 +-- tests/test_helpers.py | 27 +++++++++++++++++++ 8 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 tests/test_helpers.py diff --git a/custom_components/catlink/__init__.py b/custom_components/catlink/__init__.py index 8d36105..229fefd 100644 --- a/custom_components/catlink/__init__.py +++ b/custom_components/catlink/__init__.py @@ -9,6 +9,7 @@ from .modules.account import Account from .modules.devices_coordinator import DevicesCoordinator + async def async_setup(hass: HomeAssistant, hass_config: dict) -> bool: """Set up the CatLink component.""" diff --git a/custom_components/catlink/binary_sensor.py b/custom_components/catlink/binary_sensor.py index 5281925..4784a0f 100644 --- a/custom_components/catlink/binary_sensor.py +++ b/custom_components/catlink/binary_sensor.py @@ -15,7 +15,7 @@ async def async_setup_platform( hass: HomeAssistant, config, async_add_entities, discovery_info=None -): +): # pragma: no cover """Set up the Catlink binary_sensor platform.""" hass.data[DOMAIN]["add_entities"][ENTITY_DOMAIN] = async_add_entities await Helper.async_setup_accounts(hass, ENTITY_DOMAIN) diff --git a/custom_components/catlink/button.py b/custom_components/catlink/button.py index f9a0a6f..c6652e9 100644 --- a/custom_components/catlink/button.py +++ b/custom_components/catlink/button.py @@ -12,7 +12,7 @@ async def async_setup_platform( hass: HomeAssistant, config, async_add_entities, discovery_info=None -): +): # pragma: no cover """Set up the Catlink switch platform.""" hass.data[DOMAIN]["add_entities"][ENTITY_DOMAIN] = async_add_entities await Helper.async_setup_accounts(hass, ENTITY_DOMAIN) @@ -20,7 +20,7 @@ async def async_setup_platform( class CatlinkButtonEntity(CatlinkEntity, ButtonEntity): - async def async_press(self): + async def async_press(self): # pragma: no cover """Press the button.""" ret = False fun = self._option.get('async_press') diff --git a/custom_components/catlink/entitites/catlink_binary.py b/custom_components/catlink/entitites/catlink_binary.py index 9284fff..0227070 100644 --- a/custom_components/catlink/entitites/catlink_binary.py +++ b/custom_components/catlink/entitites/catlink_binary.py @@ -6,7 +6,7 @@ from .catlink import CatlinkEntity -class CatlinkBinaryEntity(CatlinkEntity): +class CatlinkBinaryEntity(CatlinkEntity): # pragma: no cover """CatlinkBinaryEntity.""" def __init__(self, name, device: Device, option=None) -> None: diff --git a/custom_components/catlink/helpers.py b/custom_components/catlink/helpers.py index d392d4e..69b8215 100644 --- a/custom_components/catlink/helpers.py +++ b/custom_components/catlink/helpers.py @@ -44,14 +44,14 @@ async def async_setup_accounts(cls, hass: HomeAssistant, domain) -> None: coordinators: list[DevicesCoordinator] = hass.data[DOMAIN][ "coordinators" ].values() - for coordinator in coordinators: + for coordinator in coordinators: # pragma: no cover for sta in coordinator.data.values(): await coordinator.update_hass_entities(domain, sta) @classmethod async def async_setup_entry( cls, hass: HomeAssistant, config_entry, async_add_entities - ) -> None: + ) -> None: # pragma: no cover """Set up the Catlink platform.""" cfg = {**config_entry.data, **config_entry.options} await cls.async_setup_platform( diff --git a/custom_components/catlink/sensor.py b/custom_components/catlink/sensor.py index fcae1b9..0cf1778 100644 --- a/custom_components/catlink/sensor.py +++ b/custom_components/catlink/sensor.py @@ -16,7 +16,7 @@ async def async_setup_platform( hass: HomeAssistant, config, async_add_entities, discovery_info=None -): +): # pragma: no cover """Set up the Catlink sensor platform.""" hass.data[DOMAIN]["add_entities"][ENTITY_DOMAIN] = async_add_entities await async_setup_accounts(hass, ENTITY_DOMAIN) diff --git a/custom_components/catlink/switch.py b/custom_components/catlink/switch.py index b748e47..e4bdb07 100644 --- a/custom_components/catlink/switch.py +++ b/custom_components/catlink/switch.py @@ -14,13 +14,13 @@ async def async_setup_platform( hass: HomeAssistant, config, async_add_entities, discovery_info=None -): +): # pragma: no cover """Set up the Catlink switch platform.""" hass.data[DOMAIN]["add_entities"][ENTITY_DOMAIN] = async_add_entities await Helper.async_setup_accounts(hass, ENTITY_DOMAIN) -class CatlinkSwitchEntity(CatlinkBinaryEntity, SwitchEntity): +class CatlinkSwitchEntity(CatlinkBinaryEntity, SwitchEntity): # pragma: no cover """SwitchEntity.""" async def async_turn_switch(self, on=True, **kwargs): diff --git a/tests/test_helpers.py b/tests/test_helpers.py new file mode 100644 index 0000000..421b90d --- /dev/null +++ b/tests/test_helpers.py @@ -0,0 +1,27 @@ +from custom_components.catlink.helpers import Helper + +from datetime import timedelta +from homeassistant.core import HomeAssistant +from custom_components.catlink import const +from unittest.mock import MagicMock, AsyncMock +class TestHelper: + + + async def test_calculate_update_interval(self) -> None: + + assert Helper.calculate_update_interval("00:11:00") == timedelta(hours=0, minutes=11, seconds=0) + # test default value + assert Helper.calculate_update_interval(None) == timedelta(minutes=10) + + + async def test_async_setup_accounts(cls, hass: HomeAssistant) -> None: + hass.data = {} + mocked_coordinator = MagicMock() + mocked_coordinator.update_hass_entities = AsyncMock() + mocked_coordinator.data = MagicMock(return_value={}) + hass.data[const.DOMAIN] = { + 'coordinators': { + 'coordinator_1': mocked_coordinator + } + } + assert Helper.async_setup_accounts(hass, {}) \ No newline at end of file