Skip to content

Commit

Permalink
added pragmas not to cover already covered by ha
Browse files Browse the repository at this point in the history
  • Loading branch information
Miloš Ljubenović committed Sep 4, 2024
1 parent 96b4946 commit ea9fea5
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions custom_components/catlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
2 changes: 1 addition & 1 deletion custom_components/catlink/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/catlink/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

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 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')
Expand Down
2 changes: 1 addition & 1 deletion custom_components/catlink/entitites/catlink_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/catlink/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/catlink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/catlink/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
27 changes: 27 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -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, {})

0 comments on commit ea9fea5

Please sign in to comment.