Skip to content

Commit

Permalink
use PEP8 names
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdavb committed Aug 31, 2024
1 parent df2a452 commit 245b7c4
Show file tree
Hide file tree
Showing 39 changed files with 596 additions and 656 deletions.
22 changes: 11 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@
"ANN", # flake8-annotations
# "ARG", # flake8-unused-arguments
"ASYNC", # flake8-async
"B", # flake8-bugbear
"B", # flake8-bugbear # desirable
"BLE", # blind-except
"C", # convention
"C", # convention # desirable
"C4", # flake8-comprehensions
"C90", # mcabe
"COM", # flake8-commas
Expand All @@ -171,30 +171,30 @@
"EXE", # flake8-executable
"F", # Pyflakes
"FA", # flake8-future-annotations
"FBT", # flake8-boolean-trap
"FBT", # flake8-boolean-trap # desirable
# "FURB", # refurb
"G", # flake8-logging-format
"I", # isort
"ICN", # flake8-import-conventions
"ICN", # flake8-import-conventions # desirable
"INP", # flake8-no-pep420
"LOG", # flake8-logging
# "N", # pep8-naming
"N", # pep8-naming # desirable
# "PERF", # perflint
"PGH", # pygrep hooks
"PIE", # flake8-pie
"PIE", # flake8-pie # desirable
# "PL", # pylint
# "PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
# "PT", # flake8-pytest-style # desirable
"PTH", # flake8-use-pathlib # desirable
"PYI", # flake8-pyi
"Q", # flake8-quotes
"RET", # flake8-return
"RET", # flake8-return # desirable
"RSE", # flake8-raise
"RUF", # Ruff-specific rules
"S", # flake8-bandit
"SIM", # flake8-simplify
"SIM", # flake8-simplify # desirable
# "SLF", # flake8-self
"SLOT", # flake8-slot
"TCH", # flake8-type-checking
"TCH", # flake8-type-checking # desirable
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle
Expand Down
2 changes: 1 addition & 1 deletion src/evohomeasync2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def _get_single_tcs(self) -> ControlSystem:
@property
def system_id(self) -> _SystemIdT: # an evohome-client anachronism, deprecate?
"""Return the ID of the default TCS (assumes only one loc/gwy/TCS)."""
return self._get_single_tcs().systemId
return self._get_single_tcs().system_id

async def reset_mode(self) -> None:
"""Reset the mode of the default TCS and its zones."""
Expand Down
51 changes: 23 additions & 28 deletions src/evohomeasync2/controlsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from .hotwater import HotWater
from .schema import SCH_TCS_STATUS
from .schema.const import (
SZ_ACTIVE_FAULTS,
SZ_ALLOWED_SYSTEM_MODES,
SZ_DHW,
SZ_DHW_ID,
Expand Down Expand Up @@ -149,23 +148,23 @@ def __init__(self, gateway: Gateway, config: _EvoDictT, /) -> None:
else:
self._zones.append(zone)
self.zones[zone.name] = zone
self.zones_by_id[zone.zoneId] = zone
self.zones_by_id[zone.zone_id] = zone

dhw_config: _EvoDictT
if dhw_config := config.get(SZ_DHW): # type: ignore[assignment]
self.hotwater = HotWater(self, dhw_config)

@property
def systemId(self) -> _SystemIdT:
def system_id(self) -> _SystemIdT:
return self._id

@property
def allowedSystemModes(self) -> _EvoListT:
def allowed_system_modes(self) -> _EvoListT:
ret: _EvoListT = self._config[SZ_ALLOWED_SYSTEM_MODES]
return ret

@property
def modelType(self) -> str:
def model_type(self) -> str:
ret: str = self._config[SZ_MODEL_TYPE]
return ret

Expand Down Expand Up @@ -199,18 +198,14 @@ def _update_status(self, status: _EvoDictT) -> None:
)

@property
def activeFaults(self) -> _EvoListT | None:
return self._status.get(SZ_ACTIVE_FAULTS)

@property
def systemModeStatus(self) -> _EvoDictT | None:
def system_mode_status(self) -> _EvoDictT | None:
return self._status.get(SZ_SYSTEM_MODE_STATUS)

@property # status attr for convenience (new)
def system_mode(self) -> str | None:
if self.systemModeStatus is None:
if self.system_mode_status is None:
return None
ret: str = self.systemModeStatus[SZ_MODE]
ret: str = self.system_mode_status[SZ_MODE]
return ret

async def _set_mode(self, mode: dict[str, str | bool]) -> None:
Expand All @@ -226,7 +221,7 @@ async def set_mode(self, mode: SystemMode, /, *, until: dt | None = None) -> Non

request: _EvoDictT

if mode not in [m[SZ_SYSTEM_MODE] for m in self.allowedSystemModes]:
if mode not in [m[SZ_SYSTEM_MODE] for m in self.allowed_system_modes]:
raise exc.InvalidParameterError(f"{self}: Unsupported/unknown mode: {mode}")

if until is None:
Expand Down Expand Up @@ -278,38 +273,38 @@ async def temperatures(self) -> _EvoListT:
if dhw := self.hotwater:
dhw_status = {
SZ_THERMOSTAT: "DOMESTIC_HOT_WATER",
SZ_ID: dhw.dhwId,
SZ_ID: dhw.dhw_id,
SZ_NAME: dhw.name,
SZ_TEMP: None,
}

if (
isinstance(dhw.temperatureStatus, dict)
and dhw.temperatureStatus[SZ_IS_AVAILABLE]
isinstance(dhw.temperature_status, dict)
and dhw.temperature_status[SZ_IS_AVAILABLE]
):
dhw_status[SZ_TEMP] = dhw.temperatureStatus[SZ_TEMPERATURE]
dhw_status[SZ_TEMP] = dhw.temperature_status[SZ_TEMPERATURE]

result.append(dhw_status)

for zone in self._zones:
zone_status = {
SZ_THERMOSTAT: "EMEA_ZONE",
SZ_ID: zone.zoneId,
SZ_ID: zone.zone_id,
SZ_NAME: zone.name,
SZ_SETPOINT: None,
SZ_TEMP: None,
}

if isinstance(zone.setpointStatus, dict):
zone_status[SZ_SETPOINT] = zone.setpointStatus[
if isinstance(zone.setpoint_status, dict):
zone_status[SZ_SETPOINT] = zone.setpoint_status[
SZ_TARGET_HEAT_TEMPERATURE
]

if (
isinstance(zone.temperatureStatus, dict)
and zone.temperatureStatus[SZ_IS_AVAILABLE]
isinstance(zone.temperature_status, dict)
and zone.temperature_status[SZ_IS_AVAILABLE]
):
zone_status[SZ_TEMP] = zone.temperatureStatus[SZ_TEMPERATURE]
zone_status[SZ_TEMP] = zone.temperature_status[SZ_TEMPERATURE]

result.append(zone_status)

Expand All @@ -328,19 +323,19 @@ async def get_schedule(child: HotWater | Zone) -> _ScheduleT:
return {}

self._logger.info(
f"Schedules: Backing up from {self.systemId} ({self.location.name})"
f"Schedules: Backing up from {self.system_id} ({self.location.name})"
)

schedules = {}

for zone in self._zones:
schedules[zone.zoneId] = {
schedules[zone.zone_id] = {
SZ_NAME: zone.name,
SZ_SCHEDULE: await get_schedule(zone),
}

if self.hotwater:
schedules[self.hotwater.dhwId] = {
schedules[self.hotwater.dhw_id] = {
SZ_NAME: self.hotwater.name,
SZ_SCHEDULE: await get_schedule(self.hotwater),
}
Expand All @@ -362,7 +357,7 @@ async def restore_by_id(

name = schedule.get(SZ_NAME)

if self.hotwater and self.hotwater.dhwId == child_id:
if self.hotwater and self.hotwater.dhw_id == child_id:
await self.hotwater.set_schedule(json.dumps(schedule[SZ_SCHEDULE]))

elif zone := self.zones_by_id.get(child_id):
Expand Down Expand Up @@ -401,7 +396,7 @@ async def restore_by_name(

self._logger.info(
f"Schedules: Restoring (matched by {'name' if match_by_name else 'id'})"
f" to {self.systemId} ({self.location.name})"
f" to {self.system_id} ({self.location.name})"
)

with_errors = False
Expand Down
6 changes: 3 additions & 3 deletions src/evohomeasync2/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def __init__(self, location: Location, config: _EvoDictT, /) -> None:
tcs = ControlSystem(self, tcs_config)

self._control_systems.append(tcs)
self.control_systems[tcs.systemId] = tcs
self.control_systems[tcs.system_id] = tcs

@property
def gatewayId(self) -> _GatewayIdT:
def gateway_id(self) -> _GatewayIdT:
return self._id

@property
Expand All @@ -61,7 +61,7 @@ def mac(self) -> str:
return ret

@property
def isWiFi(self) -> bool:
def is_wifi(self) -> bool:
ret: bool = self._config[SZ_IS_WI_FI]
return ret

Expand Down
24 changes: 12 additions & 12 deletions src/evohomeasync2/hotwater.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class HotWaterDeprecated: # pragma: no cover
"""Deprecated attributes and methods removed from the evohome-client namespace."""

@property
def zoneId(self) -> NoReturn:
def zoneId(self) -> NoReturn: # noqa: N802
raise exc.DeprecationError(
f"{self}: .zoneId is deprecated, use .dhwId (or ._id)"
f"{self}: .zoneId is deprecated, use .dhw_id (or ._id)"
)

async def get_dhw_state(self, *args: Any, **kwargs: Any) -> NoReturn:
Expand Down Expand Up @@ -77,44 +77,44 @@ def __init__(self, tcs: ControlSystem, config: _EvoDictT, /) -> None:
super().__init__(config[SZ_DHW_ID], tcs, config)

@property
def dhwId(self) -> _DhwIdT:
def dhw_id(self) -> _DhwIdT:
return self._id

@property
def dhwStateCapabilitiesResponse(self) -> _EvoDictT:
def dhw_state_capabilities_esponse(self) -> _EvoDictT:
ret: _EvoDictT = self._config[SZ_DHW_STATE_CAPABILITIES_RESPONSE]
return ret

@property
def scheduleCapabilitiesResponse(self) -> _EvoDictT:
def schedule_capabilities_response(self) -> _EvoDictT:
ret: _EvoDictT = self._config[SZ_SCHEDULE_CAPABILITIES_RESPONSE]
return ret

@property # for convenience (is not a top-level config attribute)
def allowedModes(self) -> _EvoListT:
ret: _EvoListT = self.dhwStateCapabilitiesResponse[SZ_ALLOWED_MODES]
def allowed_modes(self) -> _EvoListT:
ret: _EvoListT = self.dhw_state_capabilities_esponse[SZ_ALLOWED_MODES]
return ret

@property
def name(self) -> str:
return "Domestic Hot Water"

@property
def stateStatus(self) -> _EvoDictT | None:
def state_status(self) -> _EvoDictT | None:
return self._status.get(SZ_STATE_STATUS)

@property # status attr for convenience (new)
def mode(self) -> str | None:
if self.stateStatus is None:
if self.state_status is None:
return None
ret: str = self.stateStatus[SZ_MODE]
ret: str = self.state_status[SZ_MODE]
return ret

@property # status attr for convenience (new)
def state(self) -> str | None:
if self.stateStatus is None:
if self.state_status is None:
return None
ret: str = self.stateStatus[SZ_STATE]
ret: str = self.state_status[SZ_STATE]
return ret

def _next_setpoint(self) -> tuple[dt, str] | None: # WIP: for convenience (new)
Expand Down
12 changes: 6 additions & 6 deletions src/evohomeasync2/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def __init__(self, client: EvohomeClient, config: _EvoDictT, /) -> None:
gwy = Gateway(self, gwy_config)

self._gateways.append(gwy)
self.gateways[gwy.gatewayId] = gwy
self.gateways[gwy.gateway_id] = gwy

def __str__(self) -> str:
return f"{self.__class__.__name__}(id='{self._id}')"

@property
def locationId(self) -> _LocationIdT:
def location_id(self) -> _LocationIdT:
return self._id

@property
Expand All @@ -80,12 +80,12 @@ def country(self) -> str:
return ret

@property
def locationOwner(self) -> _EvoDictT:
def location_owner(self) -> _EvoDictT:
ret: _EvoDictT = self._config[SZ_LOCATION_OWNER]
return ret

@property
def locationType(self) -> str:
def location_type(self) -> str:
ret: str = self._config[SZ_LOCATION_TYPE]
return ret

Expand All @@ -95,12 +95,12 @@ def name(self) -> str:
return ret

@property
def timeZone(self) -> _EvoDictT:
def time_zone(self) -> _EvoDictT:
ret: _EvoDictT = self._config[SZ_TIME_ZONE]
return ret

@property
def useDaylightSaveSwitching(self) -> bool:
def use_daylight_save_switching(self) -> bool:
ret: bool = self._config[SZ_USE_DAYLIGHT_SAVE_SWITCHING]
return ret

Expand Down
Loading

0 comments on commit 245b7c4

Please sign in to comment.