-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
sdbus.utils.parse_properties_changed
function
Parses the properties changed data in to a simple dictionary there keys are translated to python names and invalidated properties will have value of None.
- Loading branch information
Showing
7 changed files
with
152 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Utilities | ||
========= | ||
|
||
Parsing utilities | ||
+++++++++++++++++ | ||
|
||
.. py:currentmodule:: sdbus.utils | ||
.. py:function:: parse_properties_changed(interface, properties_changed_data, on_unknown_member='error') | ||
Parse data from :py:meth:`properties_changed <sdbus.DbusInterfaceCommonAsync.properties_changed>` signal. | ||
|
||
Member names will be translated to python defined names. | ||
Invalidated properties will have a value of None. | ||
|
||
:param DbusInterfaceBaseAsync interface: Takes either D-Bus interface or interface class. | ||
:param Tuple properties_changed_data: Tuple caught from signal. | ||
:param str on_unknown_member: If an unknown D-Bus property was encountered | ||
either raise an ``"error"`` (default), ``"ignore"`` the property | ||
or ``"reuse"`` the D-Bus name for the member. | ||
:returns: Dictionary of changed properties with keys translated to python | ||
names. Invalidated properties will have value of None. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
# Copyright (C) 2023 igo95862 | ||
|
||
# This file is part of python-sdbus | ||
|
||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2.1 of the License, or (at your option) any later version. | ||
|
||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
|
||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with this library; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
from __future__ import annotations | ||
|
||
from typing import Any, Dict, Literal, Type, Union | ||
|
||
from .dbus_common_funcs import _parse_properties_vardict | ||
from .dbus_proxy_async_interface_base import DbusInterfaceBaseAsync | ||
from .dbus_proxy_async_interfaces import DBUS_PROPERTIES_CHANGED_TYPING | ||
|
||
|
||
def parse_properties_changed( | ||
interface: Union[DbusInterfaceBaseAsync, Type[DbusInterfaceBaseAsync]], | ||
properties_changed_data: DBUS_PROPERTIES_CHANGED_TYPING, | ||
on_unknown_member: Literal['error', 'ignore', 'reuse'] = 'error', | ||
) -> Dict[str, Any]: | ||
changed_properties_data = properties_changed_data[1] | ||
|
||
for invalidated_property in properties_changed_data[2]: | ||
changed_properties_data[invalidated_property] = ('0', None) | ||
|
||
return _parse_properties_vardict( | ||
interface._dbus_to_python_name_map, | ||
properties_changed_data[1], | ||
on_unknown_member, | ||
) | ||
|
||
|
||
__all__ = ( | ||
'parse_properties_changed', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters