Skip to content

Commit

Permalink
Refactored to pydantic ConfigDict, added asyncio_default_fixture_loop…
Browse files Browse the repository at this point in the history
…_scope setting
  • Loading branch information
signalkraft committed Jan 4, 2025
1 parent 7ecf831 commit 37d43f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pythonpath = [
]
addopts = "-n4 --cov=src"
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
testpaths = [
"src/myPyllant/tests",
]
Expand Down
59 changes: 28 additions & 31 deletions src/myPyllant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from collections.abc import Iterator
from dataclasses import asdict, fields, field
from typing import TypeVar, Any, Iterable

from pydantic import ConfigDict
from pydantic.dataclasses import dataclass

from myPyllant.const import BRANDS
Expand Down Expand Up @@ -33,15 +35,10 @@
T = TypeVar("T", bound="MyPyllantDataClass")


class MyPyllantConfig:
"""
Necessary for timezone field
"""

arbitrary_types_allowed = True
config = ConfigDict(arbitrary_types_allowed=True)


@dataclass(kw_only=True, config=MyPyllantConfig)
@dataclass(kw_only=True, config=config)
class MyPyllantDataClass:
"""
Base class that runs type validation in __init__ and can create an instance from API values
Expand Down Expand Up @@ -87,7 +84,7 @@ def prepare_dict(self) -> dict:
return prepare_field_value_for_dict(data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class Home(MyPyllantDataClass):
country_code: str
timezone: datetime.tzinfo
Expand All @@ -109,7 +106,7 @@ def name(self):
return f"{self.home_name} {self.nomenclature}"


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class BaseTimeProgramDay(MyPyllantDataClass):
index: int
weekday_name: str
Expand Down Expand Up @@ -152,7 +149,7 @@ def end_datetime(self, date) -> datetime.datetime:
) + datetime.timedelta(days=days)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class BaseTimeProgram(MyPyllantDataClass):
monday: list
tuesday: list
Expand Down Expand Up @@ -233,7 +230,7 @@ def from_api(cls, **data):
return super().from_api(**data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class ZoneTimeProgramDay(BaseTimeProgramDay):
setpoint: float | None = None

Expand All @@ -250,7 +247,7 @@ def __eq__(self, other):
)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class ZoneTimeProgram(BaseTimeProgram):
monday: list[ZoneTimeProgramDay]
tuesday: list[ZoneTimeProgramDay]
Expand Down Expand Up @@ -284,7 +281,7 @@ def set_setpoint(
d.setpoint = temperature


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class ZoneHeating(MyPyllantDataClass):
control_identifier: ControlIdentifier
operation_mode_heating: ZoneOperatingMode | ZoneOperatingModeVRC700
Expand Down Expand Up @@ -312,7 +309,7 @@ def from_api(cls, **data):
return super().from_api(**data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class ZoneCooling(MyPyllantDataClass):
control_identifier: ControlIdentifier
setpoint_cooling: float
Expand All @@ -339,7 +336,7 @@ def from_api(cls, **data):
return super().from_api(**data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class ZoneGeneral(MyPyllantDataClass):
name: str
timezone: datetime.tzinfo
Expand Down Expand Up @@ -380,7 +377,7 @@ def holiday_remaining(self) -> datetime.timedelta | None:
)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class Circuit(MyPyllantDataClass):
system_id: str
index: int
Expand All @@ -398,7 +395,7 @@ class Circuit(MyPyllantDataClass):
calculated_energy_manager_state: str | None = None


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class Zone(MyPyllantDataClass):
system_id: str
general: ZoneGeneral
Expand Down Expand Up @@ -523,7 +520,7 @@ def active_operation_mode(
return None


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class DHWTimeProgramDay(BaseTimeProgramDay):
def __eq__(self, other):
"""
Expand All @@ -534,7 +531,7 @@ def __eq__(self, other):
return self.start_time == other.start_time and self.end_time == other.end_time


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class DHWTimeProgram(BaseTimeProgram):
monday: list[DHWTimeProgramDay]
tuesday: list[DHWTimeProgramDay]
Expand All @@ -549,7 +546,7 @@ def create_day_from_api(cls, **kwargs):
return DHWTimeProgramDay(**kwargs)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class DomesticHotWater(MyPyllantDataClass):
system_id: str
index: int
Expand Down Expand Up @@ -592,7 +589,7 @@ def from_api(cls, **data):
return super().from_api(**data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class Ventilation(MyPyllantDataClass):
system_id: str
index: int
Expand All @@ -617,14 +614,14 @@ def from_api(cls, **data):
return super().from_api(**data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class DeviceDataBucket(MyPyllantDataClass):
start_date: datetime.datetime
end_date: datetime.datetime
value: float | None = None


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class DeviceData(MyPyllantDataClass):
operation_mode: str
skip_data_update: bool = False
Expand Down Expand Up @@ -662,7 +659,7 @@ def from_api(cls, **data):
return super().from_api(**data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class Device(MyPyllantDataClass):
system_id: str
timezone: datetime.tzinfo
Expand Down Expand Up @@ -738,7 +735,7 @@ def from_api(cls, **data):
return super().from_api(**data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class RoomTimeProgramDay(BaseTimeProgramDay):
temperature_setpoint: float | None = None

Expand Down Expand Up @@ -766,7 +763,7 @@ def __eq__(self, other):
)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class RoomTimeProgram(BaseTimeProgram):
monday: list[RoomTimeProgramDay]
tuesday: list[RoomTimeProgramDay]
Expand Down Expand Up @@ -855,7 +852,7 @@ def create_day_from_api(cls, **kwargs):
return RoomTimeProgramDay(**kwargs)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class AmbisenseDevice(MyPyllantDataClass):
device_type: str
name: str
Expand All @@ -866,7 +863,7 @@ class AmbisenseDevice(MyPyllantDataClass):
rssi_peer: int | None = None


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class AmbisenseRoomConfiguration(MyPyllantDataClass):
name: str
timezone: datetime.tzinfo
Expand All @@ -889,7 +886,7 @@ def from_api(cls, **data):
return super().from_api(**data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class AmbisenseRoom(MyPyllantDataClass):
system_id: str
room_index: int
Expand All @@ -910,7 +907,7 @@ def from_api(cls, **data):
return super().from_api(**data)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class System(MyPyllantDataClass):
id: str
state: dict
Expand Down Expand Up @@ -1263,7 +1260,7 @@ def manual_cooling_remaining(self) -> datetime.timedelta | None:
)


@dataclass(config=MyPyllantConfig)
@dataclass(config=config)
class SystemReport(MyPyllantDataClass):
file_name: str
file_content: str

0 comments on commit 37d43f5

Please sign in to comment.