Skip to content

Commit

Permalink
chore: precommit task, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ml1nk committed Dec 28, 2023
1 parent 876ca7e commit ee4b9a5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"python.analysis.typeCheckingMode": "basic",
"python.testing.pytestArgs": [
".",
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
Expand Down
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"problemMatcher": []
},
{
"label": "Run lint",
"label": "Run precommit",
"type": "shell",
"command": "scripts/lint",
"command": "scripts/precommit",
"problemMatcher": []
}
]
Expand Down
23 changes: 14 additions & 9 deletions custom_components/mypyllant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
version("dacite"),
version("aiohttp"),
)
username: str = entry.data.get("username") # type: ignore
password: str = entry.data.get("password") # type: ignore
username: str = entry.data.get("username") # type: ignore
password: str = entry.data.get("password") # type: ignore
update_interval = entry.options.get(OPTION_UPDATE_INTERVAL, DEFAULT_UPDATE_INTERVAL)
country = entry.options.get(
OPTION_COUNTRY, entry.data.get(OPTION_COUNTRY, DEFAULT_COUNTRY)
Expand Down Expand Up @@ -129,7 +129,10 @@ def hass_data(self):
return self.hass.data[DOMAIN][self.entry.entry_id]

async def _refresh_session(self):
if self.api.oauth_session_expires is None or self.api.oauth_session_expires < datetime.now() + timedelta(seconds=180):
if (
self.api.oauth_session_expires is None
or self.api.oauth_session_expires < datetime.now() + timedelta(seconds=180)
):
_LOGGER.debug("Refreshing token for %s", self.api.username)
await self.api.refresh_token()
else:
Expand Down Expand Up @@ -234,10 +237,12 @@ async def _async_update_data(self) -> list[System]:
self._raise_api_down(e)
return [] # mypy


class SystemWithDeviceData(TypedDict):
home_name: str
devices_data: list[list[DeviceData]]


class DailyDataCoordinator(MyPyllantCoordinator):
data: dict[str, SystemWithDeviceData]

Expand All @@ -253,16 +258,16 @@ async def _async_update_data(self) -> dict[str, SystemWithDeviceData]:
async for system in await self.hass.async_add_executor_job(
self.api.get_systems
):
if len(system.devices) == 0: continue
data[system.id] = {
'home_name': system.home.name,
'devices_data': []
}
if len(system.devices) == 0:
continue
data[system.id] = {"home_name": system.home.name, "devices_data": []}
for device in system.devices:
device_data = self.api.get_data_by_device(
device, DeviceDataBucketResolution.DAY, start, end
)
data[system.id]['devices_data'].append([da async for da in device_data])
data[system.id]["devices_data"].append(
[da async for da in device_data]
)
return data
except ClientResponseError as e:
self._set_quota_and_raise(e)
Expand Down
3 changes: 3 additions & 0 deletions custom_components/mypyllant/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def entity_category(self) -> EntityCategory | None:
def device_info(self) -> DeviceInfo | None:
return {"identifiers": {(DOMAIN, f"home_{self.system.id}")}}


class ControlError(SystemControlEntity):
def __init__(
self,
Expand Down Expand Up @@ -147,6 +148,7 @@ def unique_id(self) -> str:
def device_class(self) -> BinarySensorDeviceClass | None:
return BinarySensorDeviceClass.UPDATE


class FirmwareUpdateEnabled(SystemControlEntity):
def __init__(
self,
Expand All @@ -167,6 +169,7 @@ def name(self) -> str:
def unique_id(self) -> str:
return f"{get_unique_id_prefix(self.system.id)}firmware_update_enabled"


class CircuitEntity(CoordinatorEntity, BinarySensorEntity):
def __init__(
self,
Expand Down
4 changes: 3 additions & 1 deletion custom_components/mypyllant/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from asyncio.exceptions import CancelledError

from aiohttp.client_exceptions import ClientResponseError
from myPyllant.models import System
from custom_components.mypyllant.const import DOMAIN


def get_unique_id_prefix(system_id: str) -> str:
return f"{DOMAIN}_{system_id}_"


def get_name_prefix(home: str) -> str:
return f"{home} "


def is_quota_exceeded_exception(exc_info: Exception) -> bool:
"""
Returns True if the exception is a quota exceeded ClientResponseError
Expand Down
5 changes: 4 additions & 1 deletion custom_components/mypyllant/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ def domestic_hot_water(self) -> DomesticHotWater:
def device_info(self) -> DeviceInfo:
return DeviceInfo(
identifiers={
(DOMAIN, f"domestic_hot_water_{self.system.id}_{self.domestic_hot_water.index}")
(
DOMAIN,
f"domestic_hot_water_{self.system.id}_{self.domestic_hot_water.index}",
)
},
name=self.name,
manufacturer=self.system.brand_name,
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint → scripts/precommit
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e

cd "$(dirname "$0")/.."

SKIP=pytest pre-commit run
pre-commit run --all-files

0 comments on commit ee4b9a5

Please sign in to comment.