Skip to content

Commit

Permalink
Fix linting errors (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner authored Mar 2, 2024
1 parent fcdb1bc commit 2070cc8
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[MAIN]
ignore-paths=
config.py

disable=
missing-module-docstring
2 changes: 2 additions & 0 deletions salusfy/ha_temperature_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Reduces reliance on the Salus API"""
import aiohttp

# pylint: disable=too-few-public-methods


class HaTemperatureClient:
"""
Expand Down
2 changes: 1 addition & 1 deletion salusfy/web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async def get_state_data(self) -> dict:
return None
except BaseException:
_LOGGER.error(
"Error Getting the data from Web. Please check the connection to salus-it500.com manually.")
"Error Getting the data from Salus. Check the connection to salus-it500.com.")
return None

body = await r.text()
Expand Down
5 changes: 5 additions & 0 deletions tests/config_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# pylint: disable=too-few-public-methods
# pylint: disable=too-many-return-statements

class ConfigAdapter:
"""Simulates how Home Assistant loads configuration"""

Expand Down Expand Up @@ -37,3 +40,5 @@ def get(self, key: str) -> any:

if key == 'access_token':
return self._config.ACCESS_TOKEN

return 'Unknown'
13 changes: 11 additions & 2 deletions tests/entity_registry.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
class EntityRegistry:
"""Registry used for local and test executions."""

def __init__(self):
self._entities = []
self._update_before_add = False

def register(self, list, **kwargs):
def register(self, entities, **kwargs):
"""Registers the list of entities."""
self._update_before_add = kwargs.get('update_before_add')
self._entities.extend(list)
self._entities.extend(entities)

@property
def entities(self):
"""Returns the list of entries registered during configuration."""
return self._entities

@property
def first(self):
"""Returns the first entity registered."""
return self._entities[0]

@property
def update_before_add(self):
"""
Determines whether the update_before_add value
has been set during configuration.
"""
return self._update_before_add
26 changes: 18 additions & 8 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

from salusfy import (Client, State, WebClient, HaTemperatureClient)

# pylint: disable=missing-function-docstring

@pytest.fixture
def mock_client():

@pytest.fixture(name="mock_client")
def mock_client_fixture():
state = State()
state.current_temperature = 15.3
state.target_temperature = 33.3
Expand All @@ -21,8 +23,8 @@ def mock_client():
return mock


@pytest.fixture
def mock_ha_client():
@pytest.fixture(name="mock_ha_client")
def mock_ha_client_fixture():
mock = Mock(HaTemperatureClient)

mock.current_temperature.return_value = 21.1
Expand Down Expand Up @@ -110,7 +112,9 @@ async def test_client_sets_hvac_mode(mock_client, mock_ha_client):


@pytest.mark.asyncio
async def test_client_assumes_hvac_action_as_heat_when_mode_is_heat_and_target_temp_is_high(mock_client, mock_ha_client):
async def test_client_assumes_hvac_action_as_heat_when_mode_is_heat_and_target_temp_is_high(
mock_client, mock_ha_client):

target = Client(mock_client, mock_ha_client)

await target.get_state()
Expand All @@ -124,7 +128,9 @@ async def test_client_assumes_hvac_action_as_heat_when_mode_is_heat_and_target_t


@pytest.mark.asyncio
async def test_client_assumes_hvac_action_as_idle_when_mode_is_heat_and_target_temp_is_low(mock_client, mock_ha_client):
async def test_client_assumes_hvac_action_as_idle_when_mode_is_heat_and_target_temp_is_low(
mock_client, mock_ha_client):

target = Client(mock_client, mock_ha_client)

await target.get_state()
Expand All @@ -138,7 +144,9 @@ async def test_client_assumes_hvac_action_as_idle_when_mode_is_heat_and_target_t


@pytest.mark.asyncio
async def test_client_assumes_hvac_action_as_heat_when_mode_is_heat_and_target_temp_is_set_high(mock_client, mock_ha_client):
async def test_client_assumes_hvac_action_as_heat_when_mode_is_heat_and_target_temp_is_set_high(
mock_client, mock_ha_client):

target = Client(mock_client, mock_ha_client)

await target.get_state()
Expand All @@ -152,7 +160,9 @@ async def test_client_assumes_hvac_action_as_heat_when_mode_is_heat_and_target_t


@pytest.mark.asyncio
async def test_client_assumes_hvac_action_as_idle_when_mode_is_heat_and_target_temp_is_set_low(mock_client, mock_ha_client):
async def test_client_assumes_hvac_action_as_idle_when_mode_is_heat_and_target_temp_is_set_low(
mock_client, mock_ha_client):

target = Client(mock_client, mock_ha_client)

await target.get_state()
Expand Down
13 changes: 11 additions & 2 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

from . import mock_config

# pylint: disable=missing-function-docstring


class MockHass:
"""Mocks the HASS for use during unit tests."""
@property
def services(self):
return self

def has_service(self, domain, service):
def has_service(self,
domain, # pylint: disable=unused-argument
service, # pylint: disable=unused-argument
):
return False

def async_register(self, domain, service, admin_handler, schema):
Expand All @@ -23,7 +29,10 @@ def async_register(self, domain, service, admin_handler, schema):
async def setup_climate_platform():
registry = EntityRegistry()
config_adapter = ConfigAdapter(mock_config)
await climate.async_setup_platform(MockHass(), config_adapter, async_add_entities=registry.register, discovery_info=None)
await climate.async_setup_platform(MockHass(),
config_adapter,
async_add_entities=registry.register,
discovery_info=None)
return registry


Expand Down
12 changes: 7 additions & 5 deletions tests/test_thermostat_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

from salusfy import (ThermostatEntity, State, WebClient)

# pylint: disable=missing-function-docstring

@pytest.fixture
def mock_client():

@pytest.fixture(name="mock_client")
def mock_client_fixture():
state = State()
state.current_temperature = 15.3
state.target_temperature = 33.3
state.current_temperature = 15.2
state.target_temperature = 33.2

mock = Mock(WebClient)
mock.get_state.return_value = state
Expand All @@ -23,7 +25,7 @@ async def test_entity_returns_target_temp_from_web_client(mock_client):

await target.async_update()

assert target.target_temperature == 33.3
assert target.target_temperature == 33.2


@pytest.mark.asyncio
Expand Down
6 changes: 4 additions & 2 deletions tests/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

from salusfy import WebClient

# pylint: disable=missing-function-docstring

@pytest.fixture
def payload() -> dict:

@pytest.fixture(name="payload")
def payload_fixture() -> dict:
"""Returns the default data for the tests"""
return {
'CH1currentSetPoint': 20.1,
Expand Down

0 comments on commit 2070cc8

Please sign in to comment.