Browse Source

explicit timestamp type specification to avoid OverflowError

Fabian Peter Hammerle 3 years ago
parent
commit
36b80ed4be
3 changed files with 7 additions and 1 deletions
  1. 4 0
      CHANGELOG.md
  2. 2 1
      systemctl_mqtt/__init__.py
  3. 1 0
      tests/test_dbus.py

+ 4 - 0
CHANGELOG.md

@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
   to `systemctl/hostname/preparing-for-shutdown`
 - log shutdown [inhibitor locks](https://www.freedesktop.org/wiki/Software/systemd/inhibit/)
 
+### Fixed
+- explicit timestamp type specification to avoid
+  `OverflowError: Python int too large to convert to C long`
+
 ## [0.1.1] - 2020-06-18
 ### Fixed
 - compatibility with python3.5:

+ 2 - 1
systemctl_mqtt/__init__.py

@@ -85,7 +85,8 @@ def _schedule_shutdown(action: str) -> None:
     _LOGGER.info(
         "scheduling %s for %s", action, shutdown_datetime.strftime("%Y-%m-%d %H:%M:%S"),
     )
-    shutdown_epoch_usec = int(shutdown_datetime.timestamp() * 10 ** 6)
+    # https://dbus.freedesktop.org/doc/dbus-python/tutorial.html?highlight=signature#basic-types
+    shutdown_epoch_usec = dbus.UInt64(shutdown_datetime.timestamp() * 10 ** 6)
     login_manager = _get_login_manager()
     try:
         # $ gdbus introspect --system --dest org.freedesktop.login1 \

+ 1 - 0
tests/test_dbus.py

@@ -108,6 +108,7 @@ def test__schedule_shutdown(action):
     schedule_args, schedule_kwargs = login_manager_mock.ScheduleShutdown.call_args
     assert len(schedule_args) == 2
     assert schedule_args[0] == action
+    assert isinstance(schedule_args[1], dbus.UInt64)
     shutdown_datetime = datetime.datetime.fromtimestamp(
         schedule_args[1] / 10 ** 6, tz=_UTC,
     )