Skip to content

Commit

Permalink
Fix more linting errors (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner authored Mar 1, 2024
1 parent f38066f commit 6ccd7df
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Home-Assistant Custom Components

[![CI](https://github.com/matthewturner/salusfy/actions/workflows/ci.yml/badge.svg)](https://github.com/matthewturner/salusfy/actions/workflows/ci.yml)

Custom Components for Home-Assistant (http://www.home-assistant.io)

# Salus Thermostat Climate Component
Expand Down
6 changes: 4 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
# 3 Run with `python run.py`

import asyncio
import logging

from homeassistant.components.climate.const import HVACMode

from salusfy import climate
from tests.test_climate import MockHass
from tests.config_adapter import ConfigAdapter
from tests.entity_registry import EntityRegistry

from homeassistant.components.climate.const import HVACMode

import config

import logging
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)


Expand Down
21 changes: 10 additions & 11 deletions salusfy/web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import time
import logging
import re
import aiohttp
import json

from .state import State
import aiohttp

from homeassistant.components.climate.const import (
HVACMode,
HVACAction,
)

from .state import State

_LOGGER = logging.getLogger(__name__)

Expand All @@ -31,13 +30,13 @@
class WebClient:
"""Adapter around Salus IT500 web application."""

def __init__(self, username, password, id):
def __init__(self, username: str, password: str, device_id: str):
"""Initialize the client."""
self._username = username
self._password = password
self._id = id
self._id = device_id
self._token = None
self._tokenRetrievedAt = None
self._token_retrieved_at = None

async def set_temperature(self, temperature: float) -> None:
"""Set new target temperature, via URL commands."""
Expand Down Expand Up @@ -95,7 +94,7 @@ async def obtain_token(self, session: str) -> str:
await self.get_token(session)
return self._token

if self._tokenRetrievedAt > time.time() - MAX_TOKEN_AGE_SECONDS:
if self._token_retrieved_at > time.time() - MAX_TOKEN_AGE_SECONDS:
_LOGGER.info("Using cached token...")
return self._token

Expand All @@ -118,16 +117,16 @@ async def get_token(self, session: str) -> None:
try:
await session.post(URL_LOGIN, data=payload, headers=headers)
params = {"devId": self._id}
getTkoken = await session.get(URL_GET_TOKEN, params=params)
body = await getTkoken.text()
token_response = await session.get(URL_GET_TOKEN, params=params)
body = await token_response.text()
result = re.search(
'<input id="token" type="hidden" value="(.*)" />', body)
_LOGGER.info("Salusfy get_token OK")
self._token = result.group(1)
self._tokenRetrievedAt = time.time()
self._token_retrieved_at = time.time()
except Exception as e:
self._token = None
self._tokenRetrievedAt = None
self._token_retrieved_at = None
_LOGGER.error("Error getting the session token.")
_LOGGER.error(e)

Expand Down
22 changes: 13 additions & 9 deletions tests/config_adapter.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
class ConfigAdapter:
"""Simulates how Home Assistant loads configuration"""

def __init__(self, config):
self._config = config

def get(self, key: str) -> any:
if (key == 'name'):
"""Returns the config value based on the Home Assistant key"""

if key == 'name':
return 'Simulator'

if (key == 'id'):
if key == 'id':
return self._config.DEVICE_ID

if (key == 'username'):
if key == 'username':
return self._config.USERNAME

if (key == 'password'):
if key == 'password':
return self._config.PASSWORD

if (key == 'simulator'):
if key == 'simulator':
if hasattr(self._config, 'SIMULATOR'):
return self._config.SIMULATOR
return False

if (key == 'enable_temperature_client'):
if key == 'enable_temperature_client':
if hasattr(self._config, 'ENABLE_TEMPERATURE_CLIENT'):
return self._config.ENABLE_TEMPERATURE_CLIENT
return False

if (key == 'host'):
if key == 'host':
return self._config.HOST

if (key == 'entity_id'):
if key == 'entity_id':
return self._config.ENTITY_ID

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

0 comments on commit 6ccd7df

Please sign in to comment.