"""systemd timedated mock template
This creates the expected methods and properties of the main
org.freedesktop.timedate object. You can specify D-Bus property values like
"Timezone" or "NTP" in "parameters".
"""
# SPDX-License-Identifier: LGPL-3.0-or-later
[docs]
__author__ = "Iain Lane"
[docs]
__copyright__ = """
(c) 2013 Canonical Ltd.
(c) 2017 - 2022 Martin Pitt <martin@piware.de>
"""
import dbus
[docs]
BUS_NAME = "org.freedesktop.timedate1"
[docs]
MAIN_OBJ = "/org/freedesktop/timedate1"
[docs]
MAIN_IFACE = "org.freedesktop.timedate1"
[docs]
def setProperty(prop):
return f'self.Set("{MAIN_IFACE}", "{prop}", args[0])'
[docs]
def load(mock, parameters):
mock.AddMethods(
MAIN_IFACE,
[
# There's nothing this can usefully do, but provide it for compatibility
("SetTime", "xbb", "", ""),
("SetTimezone", "sb", "", setProperty("Timezone")),
("SetLocalRTC", "bbb", "", setProperty("LocalRTC")),
("SetNTP", "bb", "", setProperty("NTP") + "; " + setProperty("NTPSynchronized")),
],
)
mock.AddProperties(
MAIN_IFACE,
dbus.Dictionary(
{
"Timezone": parameters.get("Timezone", "Etc/Utc"),
"LocalRTC": parameters.get("LocalRTC", False),
"NTP": parameters.get("NTP", True),
"NTPSynchronized": parameters.get("NTP", True),
"CanNTP": parameters.get("CanNTP", True),
},
signature="sv",
),
)