Skip to content

Commit

Permalink
remove superfluous TZ/DST attrs
Browse files Browse the repository at this point in the history
zxdavb committed Jan 26, 2025
1 parent 1cd1d9e commit 2d88803
Showing 4 changed files with 33 additions and 114 deletions.
13 changes: 7 additions & 6 deletions src/evohomeasync2/control_system.py
Original file line number Diff line number Diff line change
@@ -74,18 +74,17 @@ def __init__(self, gateway: Gateway, config: EvoTcsConfigResponseT) -> None:
self.gateway = gateway # parent
self.location: Location = gateway.location

# break the TypedDict into its parts (so, ignore[misc])...
self._config: Final[EvoTcsConfigEntryT] = { # type: ignore[assignment, misc]
k: v for k, v in config.items() if k not in (SZ_DHW, SZ_ZONES)
}
self._status: EvoTcsStatusResponseT | None = None

# children
self.zones: list[Zone] = []
self.zone_by_id: dict[str, Zone] = {}

self.hotwater: HotWater | None = None

# break the config TypedDict into its parts...
self._config: Final[EvoTcsConfigEntryT] = { # type: ignore[assignment, misc]
k: v for k, v in config.items() if k not in (SZ_DHW, SZ_ZONES)
}

for zon_entry in config[SZ_ZONES]:
try:
zone = Zone(self, zon_entry)
@@ -100,6 +99,8 @@ def __init__(self, gateway: Gateway, config: EvoTcsConfigResponseT) -> None:
if dhw_entry := config.get(SZ_DHW):
self.hotwater = HotWater(self, dhw_entry)

self._status: EvoTcsStatusResponseT | None = None

@property
def zone_by_name(self) -> dict[str, Zone]:
"""Return the zones by name (names are not fixed attrs)."""
7 changes: 4 additions & 3 deletions src/evohomeasync2/gateway.py
Original file line number Diff line number Diff line change
@@ -46,19 +46,20 @@ def __init__(self, location: Location, config: EvoGwyConfigResponseT) -> None:
self.location = location # parent
#

self._config: Final[EvoGwyConfigEntryT] = config[SZ_GATEWAY_INFO] # type: ignore[misc]
self._status: EvoGwyStatusResponseT | None = None

# children
self.systems: list[ControlSystem] = []
self.system_by_id: dict[str, ControlSystem] = {} # tcs by id

self._config: Final[EvoGwyConfigEntryT] = config[SZ_GATEWAY_INFO] # type: ignore[misc]

for tcs_entry in config[SZ_TEMPERATURE_CONTROL_SYSTEMS]:
tcs = ControlSystem(self, tcs_entry)

self.systems.append(tcs)
self.system_by_id[tcs.id] = tcs

self._status: EvoGwyStatusResponseT | None = None

# Config attrs...

@cached_property # RENAMED val: was mac
62 changes: 22 additions & 40 deletions src/evohomeasync2/location.py
Original file line number Diff line number Diff line change
@@ -121,24 +121,25 @@ def __init__(
self.client = client # proxy for parent
#

self._config: EvoLocConfigEntryT = config[SZ_LOCATION_INFO]
self._status: EvoLocStatusResponseT | None = None
# children
self.gateways: list[Gateway] = []
self.gateway_by_id: dict[str, Gateway] = {}

self._config: EvoLocConfigEntryT = config[SZ_LOCATION_INFO] # ?exclude TZ/DST

self._tzinfo = tzinfo or EvoZoneInfo(
time_zone_info=self.time_zone_info,
use_dst_switching=self.dst_enabled,
time_zone_info=config[SZ_LOCATION_INFO][SZ_TIME_ZONE],
use_dst_switching=config[SZ_LOCATION_INFO][SZ_USE_DAYLIGHT_SAVE_SWITCHING],
)

# children
self.gateways: list[Gateway] = []
self.gateway_by_id: dict[str, Gateway] = {} # gwy by id

for gwy_entry in config[SZ_GATEWAYS]:
gwy = Gateway(self, gwy_entry)

self.gateways.append(gwy)
self.gateway_by_id[gwy.id] = gwy

self._status: EvoLocStatusResponseT | None = None

def __str__(self) -> str:
"""Return a string representation of the entity."""
return f"{self.__class__.__name__}(id='{self._id}', tzinfo='{self.tzinfo}')"
@@ -159,55 +160,36 @@ def name(self) -> str:
return self._config[SZ_NAME]

async def _get_config(self) -> EvoLocConfigResponseT:
"""Get the latest state of the gateway and update its status attr.
"""Get the latest config of the location and update its TZ/DST attrs.
Usually called when DST starts/stops or the location's DST config changes (i.e.
there is no _update_config() method). Returns the raw JSON of the latest config.
"""

# it is assumed that only the location's TZ/DST info can change
# so no ?includeTemperatureControlSystems=True
# it is assumed that *only* the location's TZ/DST info can change
# so don't need ?includeTemperatureControlSystems=True

config: EvoLocConfigResponseT = await self._auth.get(
f"location/{self._id}/installationInfo" # TODO: add schema
) # type: ignore[assignment]

self._config = config[SZ_LOCATION_INFO]
self._config = config[SZ_LOCATION_INFO] # ?exclude TZ/DST

# new TzInfo object, or update the existing one?
self._tzinfo = await _create_tzinfo(
self.time_zone_info, use_dst_switching=self.dst_enabled
config[SZ_LOCATION_INFO][SZ_TIME_ZONE],
use_dst_switching=config[SZ_LOCATION_INFO][SZ_USE_DAYLIGHT_SAVE_SWITCHING],
)
# lf._tzinfo._update(time_zone_info=time_zone_info, use_dst_switching=use_dst_switching)
# self._tzinfo._update( # but, only for EvoZoneInfo...
# time_zone_info=config[SZ_LOCATION_INFO][SZ_TIME_ZONE],
# use_dst_switching=config[SZ_LOCATION_INFO][SZ_USE_DAYLIGHT_SAVE_SWITCHING],
# )

return config

@property
def dst_enabled(self) -> bool:
"""Return True if the location uses daylight saving time.
Not the same as the location's TZ supporting DST, nor the current DST status.
"""
return self._config[SZ_USE_DAYLIGHT_SAVE_SWITCHING]

@property # NOTE: renamed config key: was time_zone
def time_zone_info(self) -> EvoTimeZoneInfoT:
"""Return the time zone information for the location.
The time zone id is not IANA-compliant, but is based upon the Windows scheme.
"""

"""
"timeZone": {
"timeZoneId": "GMTStandardTime",
"displayName": "(UTC+00:00) Dublin, Edinburgh, Lisbon, London",
"offsetMinutes": 0,
"currentOffsetMinutes": 60,
"supportsDaylightSaving": true
}
"""

return self._config[SZ_TIME_ZONE]
def _update_config(self, config: EvoLocConfigResponseT) -> None:
"""Update the LOC's config and cascade to its descendants."""
# pass

@property
def tzinfo(self) -> tzinfo:
65 changes: 0 additions & 65 deletions tests/tests/__snapshots__/test_v2_installs.ambr
Original file line number Diff line number Diff line change
@@ -412,11 +412,6 @@
UnitedKingdom
...

''',
'dst_enabled': '''
true
...

''',
'id': '''
'2738909'
@@ -430,14 +425,6 @@
'status': '''
location_id: '2738909'

''',
'time_zone_info': '''
current_offset_minutes: 60
display_name: (UTC+00:00) Dublin, Edinburgh, Lisbon, London
offset_minutes: 0
supports_daylight_saving: true
time_zone_id: GMTStandardTime

''',
'tzinfo': '''
!!python/object/apply:None._unpickle
@@ -2213,11 +2200,6 @@
UnitedKingdom
...

''',
'dst_enabled': '''
true
...

''',
'id': '''
'2738909'
@@ -2231,14 +2213,6 @@
'status': '''
location_id: '2738909'

''',
'time_zone_info': '''
current_offset_minutes: 60
display_name: (UTC+00:00) Dublin, Edinburgh, Lisbon, London
offset_minutes: 0
supports_daylight_saving: true
time_zone_id: GMTStandardTime

''',
'tzinfo': '''
!!python/object/apply:None._unpickle
@@ -4016,11 +3990,6 @@
UnitedKingdom
...

''',
'dst_enabled': '''
true
...

''',
'id': '''
'2738909'
@@ -4034,14 +4003,6 @@
'status': '''
location_id: '2738909'

''',
'time_zone_info': '''
current_offset_minutes: 60
display_name: (UTC+00:00) Dublin, Edinburgh, Lisbon, London
offset_minutes: 0
supports_daylight_saving: true
time_zone_id: GMTStandardTime

''',
'tzinfo': '''
!!python/object/apply:None._unpickle
@@ -5561,11 +5522,6 @@
CzechRepublic
...

''',
'dst_enabled': '''
true
...

''',
'id': '''
'2664492'
@@ -5579,14 +5535,6 @@
'status': '''
location_id: '2664492'

''',
'time_zone_info': '''
current_offset_minutes: 120
display_name: "(UTC+01:00) Praha, Bratislava, Budape\u0161\u0165, B\u011Blehrad, Lubla\u0148"
offset_minutes: 60
supports_daylight_saving: true
time_zone_id: CentralEuropeStandardTime

''',
'tzinfo': '''
!!python/object/apply:None._unpickle
@@ -6024,11 +5972,6 @@
Belgium
...

''',
'dst_enabled': '''
true
...

''',
'id': '''
'0001'
@@ -6042,14 +5985,6 @@
'status': '''
location_id: '0002'

''',
'time_zone_info': '''
current_offset_minutes: 60
display_name: (UTC+01:00) Brussels, Copenhagen, Madrid, Paris
offset_minutes: 60
supports_daylight_saving: true
time_zone_id: RomanceStandardTime

''',
'tzinfo': '''
!!python/object/apply:None._unpickle

0 comments on commit 2d88803

Please sign in to comment.