mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-28 11:36:32 +00:00
Update gdbus.py
This commit is contained in:
parent
2efa9f9483
commit
0f4e557552
@ -2,6 +2,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import shlex
|
import shlex
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -11,9 +12,17 @@ CALL = ("gdbus call --system --dest {bus} --object-path {obj} "
|
|||||||
|
|
||||||
|
|
||||||
class DbusError(Exception):
|
class DbusError(Exception):
|
||||||
|
"""Dbus generic error."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class DbusFatalError(DbusError):
|
||||||
"""Dbus call going wrong."""
|
"""Dbus call going wrong."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class DbusReturnError(DbusError):
|
||||||
|
"""Dbus return error."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Dbus(object):
|
class Dbus(object):
|
||||||
"""Dbus handler."""
|
"""Dbus handler."""
|
||||||
@ -50,6 +59,17 @@ class Dbus(object):
|
|||||||
args=" ".join(map(str, args))
|
args=" ".join(map(str, args))
|
||||||
))
|
))
|
||||||
|
|
||||||
|
# Run command
|
||||||
|
try:
|
||||||
|
data = await self._send(command)
|
||||||
|
except DBusError:
|
||||||
|
_LOGGER.w
|
||||||
|
|
||||||
|
# Parse and return data
|
||||||
|
return self._gvariant(data)
|
||||||
|
|
||||||
|
async def _send(self, command):
|
||||||
|
"""Send command over dbus."""
|
||||||
# Run command
|
# Run command
|
||||||
try:
|
try:
|
||||||
proc = await asyncio.create_subprocess_exec(
|
proc = await asyncio.create_subprocess_exec(
|
||||||
@ -61,16 +81,14 @@ class Dbus(object):
|
|||||||
|
|
||||||
data, _ = await proc.communicate()
|
data, _ = await proc.communicate()
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
_LOGGER.error("Can't send dbus command %s: %s", method, err)
|
raise DbusFatalError() from None
|
||||||
raise DbusError() from None
|
|
||||||
|
|
||||||
# Success?
|
# Success?
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
_LOGGER.info("Error %s.%s: %s", self.object_path, method, data)
|
raise DbusReturnError()
|
||||||
raise DbusError()
|
|
||||||
|
|
||||||
# Parse and return data
|
# End
|
||||||
return self._gvariant(data)
|
return data.decode()
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
"""Mapping to dbus method."""
|
"""Mapping to dbus method."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user