pynintendoparental 1.1.0__tar.gz → 1.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/PKG-INFO +1 -1
  2. pynintendoparental-1.1.2/pynintendoparental/_version.py +1 -0
  3. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/device.py +29 -11
  4. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/exceptions.py +16 -5
  5. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental.egg-info/PKG-INFO +1 -1
  6. pynintendoparental-1.1.0/pynintendoparental/_version.py +0 -1
  7. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/LICENSE +0 -0
  8. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/README.md +0 -0
  9. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/__init__.py +0 -0
  10. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/api.py +0 -0
  11. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/application.py +0 -0
  12. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/authenticator/__init__.py +0 -0
  13. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/authenticator/const.py +0 -0
  14. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/const.py +0 -0
  15. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/enum.py +0 -0
  16. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/player.py +0 -0
  17. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/py.typed +0 -0
  18. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental/utils.py +0 -0
  19. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental.egg-info/SOURCES.txt +0 -0
  20. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental.egg-info/dependency_links.txt +0 -0
  21. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental.egg-info/requires.txt +0 -0
  22. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pynintendoparental.egg-info/top_level.txt +0 -0
  23. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/pyproject.toml +0 -0
  24. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/setup.cfg +0 -0
  25. {pynintendoparental-1.1.0 → pynintendoparental-1.1.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pynintendoparental
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: A Python module to interact with Nintendo Parental Controls
5
5
  Home-page: http://github.com/pantherale0/pynintendoparental
6
6
  Author: pantherale0
@@ -0,0 +1 @@
1
+ __version__ = "1.1.2"
@@ -8,7 +8,7 @@ from typing import Callable
8
8
 
9
9
  from .api import Api
10
10
  from .const import _LOGGER, DAYS_OF_WEEK
11
- from .exceptions import HttpException, BedtimeOutOfRangeError
11
+ from .exceptions import HttpException, BedtimeOutOfRangeError, DailyPlaytimeOutOfRangeError
12
12
  from .enum import AlarmSettingState, RestrictionMode
13
13
  from .player import Player
14
14
  from .utils import is_awaitable
@@ -49,6 +49,20 @@ class Device:
49
49
  self._callbacks: list[Callable] = []
50
50
  _LOGGER.debug("Device init complete for %s", self.device_id)
51
51
 
52
+ @property
53
+ def model(self) -> str:
54
+ """Return the model."""
55
+ model_map = {
56
+ "P00": "Switch",
57
+ "P01": "Switch 2"
58
+ }
59
+ return model_map.get(self.generation, "Unknown")
60
+
61
+ @property
62
+ def generation(self) -> str | None:
63
+ """Return the generation."""
64
+ return self.extra.get("platformGeneration", None)
65
+
52
66
  async def update(self):
53
67
  """Update data."""
54
68
  _LOGGER.debug(">> Device.update()")
@@ -158,12 +172,14 @@ class Device:
158
172
  self._calculate_times()
159
173
  await self._execute_callbacks()
160
174
 
161
- async def update_max_daily_playtime(self, minutes: int = 0):
175
+ async def update_max_daily_playtime(self, minutes: int | float = 0):
162
176
  """Updates the maximum daily playtime of a device."""
163
177
  _LOGGER.debug(">> Device.update_max_daily_playtime(minutes=%s)",
164
178
  minutes)
165
- if minutes > 360:
166
- raise ValueError("Only values up to 360 minutes (6 hours) are accepted.")
179
+ if isinstance(minutes, float):
180
+ minutes = int(minutes)
181
+ if minutes > 360 or minutes < -1:
182
+ raise DailyPlaytimeOutOfRangeError(minutes)
167
183
  ttpiod = True
168
184
  if minutes == -1:
169
185
  ttpiod = False
@@ -219,10 +235,12 @@ class Device:
219
235
  current_day = day_of_week_regs.get(DAYS_OF_WEEK[datetime.now().weekday()], {})
220
236
  self.timer_mode = self.parental_control_settings["playTimerRegulations"]["timerMode"]
221
237
  if self.timer_mode == "EACH_DAY_OF_THE_WEEK":
222
- self.limit_time = current_day.get("timeToPlayInOneDay", {}).get("limitTime", None)
238
+ regulations = current_day
223
239
  else:
224
- self.limit_time = self.parental_control_settings.get("playTimerRegulations", {}).get(
225
- "dailyRegulations", {}).get("timeToPlayInOneDay", {}).get("limitTime", None)
240
+ regulations = self.parental_control_settings.get("playTimerRegulations", {}).get("dailyRegulations", {})
241
+
242
+ limit_time = regulations.get("timeToPlayInOneDay", {}).get("limitTime")
243
+ self.limit_time = limit_time if limit_time is not None else -1
226
244
 
227
245
  if self.timer_mode == "EACH_DAY_OF_THE_WEEK":
228
246
  if current_day["bedtime"]["enabled"]:
@@ -230,7 +248,7 @@ class Device:
230
248
  current_day["bedtime"]["endingTime"]["hour"],
231
249
  minute=current_day["bedtime"]["endingTime"]["minute"])
232
250
  else:
233
- self.bedtime_alarm = None
251
+ self.bedtime_alarm = time(hour=0, minute=0)
234
252
  else:
235
253
  bedtime_alarm = self.parental_control_settings["playTimerRegulations"]["dailyRegulations"]["bedtime"]
236
254
  if bedtime_alarm["enabled"]:
@@ -238,7 +256,7 @@ class Device:
238
256
  bedtime_alarm["endingTime"]["hour"],
239
257
  minute=bedtime_alarm["endingTime"]["minute"])
240
258
  else:
241
- self.bedtime_alarm = None
259
+ self.bedtime_alarm = time(hour=0, minute=0)
242
260
  return True
243
261
 
244
262
  def _parse_parental_control_setting(self, pcs: dict):
@@ -277,7 +295,7 @@ class Device:
277
295
  # 1. Calculate remaining time based on play limit
278
296
 
279
297
  time_remaining_by_play_limit = 0.0
280
- if self.limit_time is None:
298
+ if self.limit_time in (-1, None):
281
299
  # No specific play limit, effectively limited by end of day for this calculation step.
282
300
  time_remaining_by_play_limit = float(minutes_in_day - current_minutes_past_midnight)
283
301
  elif self.limit_time == 0:
@@ -291,7 +309,7 @@ class Device:
291
309
  effective_remaining_time = time_remaining_by_play_limit
292
310
 
293
311
  # 2. Factor in bedtime alarm, if any, to further constrain remaining time
294
- if self.bedtime_alarm is not None:
312
+ if self.bedtime_alarm not in (None, time(hour=0, minute=0)):
295
313
  bedtime_dt = datetime.combine(now.date(), self.bedtime_alarm)
296
314
  time_remaining_by_bedtime = 0.0
297
315
  if bedtime_dt > now: # Bedtime is in the future today
@@ -1,6 +1,12 @@
1
1
  """Nintendo Parental exceptions."""
2
2
 
3
- from datetime import time
3
+ from enum import StrEnum
4
+
5
+ class RangeErrorKeys(StrEnum):
6
+ """Keys for range errors."""
7
+
8
+ DAILY_PLAYTIME = "daily_playtime_out_of_range"
9
+ BEDTIME = "bedtime_alarm_out_of_range"
4
10
 
5
11
  class HttpException(Exception):
6
12
  """A HTTP error occured"""
@@ -27,11 +33,16 @@ class InputValidationError(Exception):
27
33
  value: object
28
34
  error_key: str
29
35
 
36
+ def __init__(self, value: object) -> None:
37
+ super().__init__(f"{self.__doc__} Received value: {value}")
38
+ self.value = value
39
+
30
40
  class BedtimeOutOfRangeError(InputValidationError):
31
41
  """Bedtime is outside of the allowed range."""
32
42
 
33
- error_key = "bedtime_alarm_out_of_range"
43
+ error_key = RangeErrorKeys.BEDTIME
34
44
 
35
- def __init__(self, value: object) -> None:
36
- super().__init__()
37
- self.value = value
45
+ class DailyPlaytimeOutOfRangeError(InputValidationError):
46
+ """Daily playtime is outside of the allowed range."""
47
+
48
+ error_key = RangeErrorKeys.DAILY_PLAYTIME
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pynintendoparental
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: A Python module to interact with Nintendo Parental Controls
5
5
  Home-page: http://github.com/pantherale0/pynintendoparental
6
6
  Author: pantherale0
@@ -1 +0,0 @@
1
- __version__ = "1.1.0"