Skip to content

Commit 0d36ec2

Browse files
authored
Merge pull request #116 from mariusz-ostoja-swierczynski/pylint
🚨 Satisfy Ruff and Pylint
2 parents e7f715e + 53ad64e commit 0d36ec2

11 files changed

Lines changed: 176 additions & 147 deletions

File tree

custom_components/tech/__init__.py

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,32 @@
11
"""The Tech Controllers integration."""
22

3-
import asyncio
43
import logging
54

6-
from aiohttp import ClientSession
7-
85
from homeassistant.config_entries import ConfigEntry
9-
from homeassistant.const import CONF_NAME, CONF_TOKEN
6+
from homeassistant.const import CONF_TOKEN
107
from homeassistant.core import HomeAssistant
11-
from homeassistant.exceptions import ConfigEntryAuthFailed
128
from homeassistant.helpers import config_validation as cv
139
from homeassistant.helpers.aiohttp_client import async_get_clientsession
14-
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
10+
from homeassistant.helpers.typing import ConfigType
1511

1612
from . import assets
17-
from .const import (
18-
API_TIMEOUT,
19-
CONTROLLER,
20-
DOMAIN,
21-
PLATFORMS,
22-
SCAN_INTERVAL,
23-
UDID,
24-
USER_ID,
25-
)
26-
from .tech import Tech, TechError, TechLoginError
13+
from .const import DOMAIN, PLATFORMS, USER_ID
14+
from .coordinator import TechCoordinator
15+
from .tech import Tech
2716

2817
_LOGGER = logging.getLogger(__name__)
2918

3019
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
3120

3221

33-
async def async_setup(hass: HomeAssistant, config: dict): # pylint: disable=unused-argument
22+
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # pylint: disable=unused-argument
3423
"""Set up the Tech Controllers component."""
3524
return True
3625

3726

3827
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
3928
"""Set up Tech Controllers from a config entry."""
40-
_LOGGER.debug("Setting up component's entry.")
29+
_LOGGER.debug("Setting up component's entry")
4130
_LOGGER.debug("Entry id: %s", str(entry.entry_id))
4231
_LOGGER.debug(
4332
"Entry -> title: %s, data: %s, id: %s, domain: %s",
@@ -73,40 +62,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
7362
hass.data[DOMAIN].pop(entry.entry_id)
7463

7564
return unload_ok
76-
77-
78-
class TechCoordinator(DataUpdateCoordinator):
79-
"""TECH API data update coordinator."""
80-
81-
config_entry: ConfigEntry
82-
83-
def __init__(
84-
self, hass: HomeAssistant, session: ClientSession, user_id: str, token: str
85-
) -> None:
86-
"""Initialize my coordinator."""
87-
super().__init__(
88-
hass,
89-
_LOGGER,
90-
# Name of the data. For logging purposes.
91-
name=DOMAIN,
92-
# Polling interval. Will only be polled if there are subscribers.
93-
update_interval=SCAN_INTERVAL,
94-
)
95-
self.api = Tech(session, user_id, token)
96-
97-
async def _async_update_data(self):
98-
"""Fetch data from TECH API endpoint(s)."""
99-
100-
_LOGGER.debug(
101-
"Updating data for: %s", str(self.config_entry.data[CONTROLLER][CONF_NAME])
102-
)
103-
104-
try:
105-
async with asyncio.timeout(API_TIMEOUT):
106-
return await self.api.module_data(
107-
self.config_entry.data[CONTROLLER][UDID]
108-
)
109-
except TechLoginError as err:
110-
raise ConfigEntryAuthFailed from err
111-
except TechError as err:
112-
raise UpdateFailed(f"Error communicating with API: {err}") from err

custom_components/tech/assets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def load_subtitles(language: str, api):
3939
None
4040
4141
"""
42-
global TRANSLATIONS # noqa: PLW0603
42+
global TRANSLATIONS # noqa: PLW0603 # pylint: disable=global-statement
4343
TRANSLATIONS = await api.get_translations(language)
4444

4545

custom_components/tech/binary_sensor.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import logging
44

55
from homeassistant.components import binary_sensor
6+
from homeassistant.config_entries import ConfigEntry
67
from homeassistant.const import (
78
CONF_PARAMS,
89
CONF_TYPE,
910
STATE_OFF,
1011
STATE_ON,
1112
EntityCategory,
1213
)
14+
from homeassistant.core import HomeAssistant
15+
from homeassistant.helpers.entity_platform import AddEntitiesCallback
16+
from homeassistant.helpers.typing import StateType, UndefinedType
1317

1418
from . import TechCoordinator, assets
1519
from .const import (
@@ -26,9 +30,13 @@
2630
_LOGGER = logging.getLogger(__name__)
2731

2832

29-
async def async_setup_entry(hass, config_entry, async_add_entities):
33+
async def async_setup_entry(
34+
hass: HomeAssistant,
35+
config_entry: ConfigEntry,
36+
async_add_entities: AddEntitiesCallback,
37+
) -> None:
3038
"""Set up entry."""
31-
_LOGGER.debug("Setting up entry for sensors...")
39+
_LOGGER.debug("Setting up entry for sensors")
3240
controller = config_entry.data[CONTROLLER]
3341
coordinator = hass.data[DOMAIN][config_entry.entry_id]
3442

@@ -72,12 +80,12 @@ def unique_id(self) -> str:
7280
return f"{self._unique_id}_tile_binary_sensor"
7381

7482
@property
75-
def name(self):
83+
def name(self) -> str | UndefinedType | None:
7684
"""Return the name of the device."""
7785
return self._name
7886

7987
@property
80-
def state(self):
88+
def state(self) -> str | int | float | StateType | None:
8189
"""Get the state of the binary sensor."""
8290
return STATE_ON if self._state else STATE_OFF
8391

@@ -87,7 +95,7 @@ class RelaySensor(TileBinarySensor):
8795

8896
def __init__(
8997
self, device, coordinator: TechCoordinator, config_entry, device_class=None
90-
):
98+
) -> None:
9199
"""Initialize the tile relay sensor."""
92100
TileBinarySensor.__init__(self, device, coordinator, config_entry)
93101
self._attr_device_class = device_class

custom_components/tech/climate.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
"""Support for Tech HVAC system."""
1+
"""The Tech Controllers Coordinator."""
22

33
import logging
44
from typing import Any
55

6-
from custom_components.tech import TechCoordinator
76
from homeassistant.components.climate import ClimateEntity
87
from homeassistant.components.climate.const import (
98
ClimateEntityFeature,
@@ -24,10 +23,13 @@
2423
STATE_ON,
2524
UnitOfTemperature,
2625
)
27-
from homeassistant.core import callback
26+
from homeassistant.core import HomeAssistant, callback
27+
from homeassistant.helpers.device_registry import DeviceInfo
28+
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2829
from homeassistant.helpers.update_coordinator import CoordinatorEntity
2930

3031
from .const import CONTROLLER, DOMAIN, INCLUDE_HUB_IN_NAME, MANUFACTURER, UDID, VER
32+
from .coordinator import TechCoordinator
3133

3234
_LOGGER = logging.getLogger(__name__)
3335

@@ -36,7 +38,11 @@
3638
SUPPORT_HVAC = [HVACMode.HEAT, HVACMode.OFF]
3739

3840

39-
async def async_setup_entry(hass, config_entry, async_add_entities):
41+
async def async_setup_entry(
42+
hass: HomeAssistant,
43+
config_entry: ConfigEntry,
44+
async_add_entities: AddEntitiesCallback,
45+
) -> None:
4046
"""Set up entry."""
4147
udid = config_entry.data[CONTROLLER][UDID]
4248
coordinator = hass.data[DOMAIN][config_entry.entry_id]
@@ -55,9 +61,11 @@ class TechThermostat(ClimateEntity, CoordinatorEntity):
5561
_attr_has_entity_name = True
5662
_attr_name = None
5763

58-
def __init__(self, device, coordinator: TechCoordinator, config_entry: ConfigEntry):
64+
def __init__(
65+
self, device, coordinator: TechCoordinator, config_entry: ConfigEntry
66+
) -> None:
5967
"""Initialize the Tech device."""
60-
_LOGGER.debug("Init TechThermostat...")
68+
_LOGGER.debug("Init TechThermostat")
6169
super().__init__(coordinator)
6270
self._config_entry = config_entry
6371
self._udid = config_entry.data[CONTROLLER][UDID]
@@ -77,12 +85,13 @@ def __init__(self, device, coordinator: TechCoordinator, config_entry: ConfigEnt
7785
+ config_entry.data[CONTROLLER][VER]
7886
)
7987
self._temperature = None
88+
self._target_temperature = None
8089
self.update_properties(device)
8190
# Remove the line below after HA 2025.1
8291
self._enable_turn_on_off_backwards_compatibility = False
8392

8493
@property
85-
def device_info(self):
94+
def device_info(self) -> DeviceInfo | None:
8695
"""Returns device information in a dictionary format."""
8796
return {
8897
ATTR_IDENTIFIERS: {
@@ -163,7 +172,7 @@ def unique_id(self) -> str:
163172
return f"{self._unique_id}_zone_climate"
164173

165174
@property
166-
def supported_features(self):
175+
def supported_features(self) -> ClimateEntityFeature:
167176
"""Return the list of supported features."""
168177
return (
169178
ClimateEntityFeature.TARGET_TEMPERATURE
@@ -172,46 +181,46 @@ def supported_features(self):
172181
)
173182

174183
@property
175-
def hvac_mode(self):
184+
def hvac_mode(self) -> HVACMode:
176185
"""Return hvac operation ie. heat, cool mode.
177186
178187
Need to be one of HVAC_MODE_*.
179188
"""
180189
return self._mode
181190

182191
@property
183-
def hvac_modes(self):
192+
def hvac_modes(self) -> list[HVACMode]:
184193
"""Return the list of available hvac operation modes.
185194
186195
Need to be a subset of HVAC_MODES.
187196
"""
188197
return SUPPORT_HVAC
189198

190199
@property
191-
def hvac_action(self) -> str | None:
200+
def hvac_action(self) -> HVACAction | None:
192201
"""Return the current running hvac operation if supported.
193202
194203
Need to be one of CURRENT_HVAC_*.
195204
"""
196205
return self._state
197206

198207
@property
199-
def temperature_unit(self):
208+
def temperature_unit(self) -> str:
200209
"""Return the unit of measurement."""
201210
return UnitOfTemperature.CELSIUS
202211

203212
@property
204-
def target_temperature_step(self):
213+
def target_temperature_step(self) -> float | None:
205214
"""Return the supported step of target temperature."""
206215
return 0.1
207216

208217
@property
209-
def current_temperature(self):
218+
def current_temperature(self) -> float | None:
210219
"""Return the current temperature."""
211220
return self._temperature
212221

213222
@property
214-
def current_humidity(self):
223+
def current_humidity(self) -> float | None:
215224
"""Return current humidity."""
216225
return self._humidity
217226

@@ -226,11 +235,11 @@ def max_temp(self) -> float:
226235
return DEFAULT_MAX_TEMP
227236

228237
@property
229-
def target_temperature(self):
238+
def target_temperature(self) -> float | None:
230239
"""Return the temperature we try to reach."""
231240
return self._target_temperature
232241

233-
async def async_set_temperature(self, **kwargs):
242+
async def async_set_temperature(self, **kwargs: Any) -> None:
234243
"""Set new target temperatures."""
235244
temperature = kwargs.get(ATTR_TEMPERATURE)
236245
if temperature:
@@ -244,7 +253,7 @@ async def async_set_temperature(self, **kwargs):
244253
self._target_temperature = temperature
245254
await self.coordinator.async_request_refresh()
246255

247-
async def async_set_hvac_mode(self, hvac_mode):
256+
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
248257
"""Set new target hvac mode."""
249258
_LOGGER.debug("%s: Setting hvac mode to %s", self.device_name, hvac_mode)
250259
if hvac_mode == HVACMode.OFF:

custom_components/tech/config_flow.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import voluptuous as vol
77

88
from homeassistant import config_entries, core, exceptions
9-
from homeassistant.config_entries import SOURCE_USER, ConfigEntry
9+
from homeassistant.config_entries import SOURCE_USER, ConfigEntry, ConfigFlowResult
1010
from homeassistant.const import (
1111
ATTR_ID,
1212
CONF_NAME,
@@ -166,11 +166,12 @@ async def _async_finish_controller(self, user_input: dict[str, str]) -> FlowResu
166166
)[CONTROLLER][CONF_NAME],
167167
data=controller,
168168
)
169+
return None
169170

170171
async def async_step_select_controllers(
171172
self,
172173
user_input: dict[str, str] | None = None,
173-
) -> FlowResult:
174+
) -> ConfigFlowResult:
174175
"""Handle the selection of controllers."""
175176
if not user_input:
176177
self._controllers = self._create_controllers_array(
@@ -184,7 +185,9 @@ async def async_step_select_controllers(
184185

185186
return await self._async_finish_controller(user_input)
186187

187-
async def async_step_user(self, user_input: dict[str, str] | None = None):
188+
async def async_step_user(
189+
self, user_input: dict[str, str] | None = None
190+
) -> ConfigFlowResult:
188191
"""Handle the initial step."""
189192
errors = {}
190193
if user_input is not None:

custom_components/tech/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
DEFAULT_ICON = "mdi:eye"
2929

30-
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR, Platform.CLIMATE]
30+
PLATFORMS = [Platform.BINARY_SENSOR, Platform.CLIMATE, Platform.SENSOR]
3131

3232
SCAN_INTERVAL: Final = timedelta(seconds=60)
3333
API_TIMEOUT: Final = 60

0 commit comments

Comments
 (0)