mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-23 09:06:29 +00:00
fix lint
This commit is contained in:
parent
a2ee2852a0
commit
1040a1624a
@ -1,4 +1,4 @@
|
|||||||
"""Dbus implementation with glib."""
|
"""DBus implementation with glib."""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import shlex
|
import shlex
|
||||||
@ -12,57 +12,59 @@ CALL = ("gdbus call --system --dest {bus} --object-path {obj} "
|
|||||||
"--method {obj}.{method} {args}")
|
"--method {obj}.{method} {args}")
|
||||||
|
|
||||||
|
|
||||||
class DbusError(Exception):
|
class DBusError(Exception):
|
||||||
"""Dbus generic error."""
|
"""DBus generic error."""
|
||||||
pass
|
|
||||||
|
|
||||||
class DbusFatalError(DbusError):
|
|
||||||
"""Dbus call going wrong."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
class DbusReturnError(DbusError):
|
|
||||||
"""Dbus return error."""
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Dbus(object):
|
class DBusFatalError(DBusError):
|
||||||
"""Dbus handler."""
|
"""DBus call going wrong."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DBusReturnError(DBusError):
|
||||||
|
"""DBus return error."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DBus(object):
|
||||||
|
"""DBus handler."""
|
||||||
|
|
||||||
def __init__(self, bus_name, object_path):
|
def __init__(self, bus_name, object_path):
|
||||||
"""Initialize dbus object."""
|
"""Initialize dbus object."""
|
||||||
self.bus_name = bus_name
|
self.bus_name = bus_name
|
||||||
self.object_path = object_path
|
self.object_path = object_path
|
||||||
self.methods = []
|
self.methods = []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def connect(bus_name, object_path):
|
async def connect(bus_name, object_path):
|
||||||
"""Read object data."""
|
"""Read object data."""
|
||||||
self = Dbus(bus_name, object_path)
|
self = DBus(bus_name, object_path)
|
||||||
self._init_proxy()
|
self._init_proxy() # pylint: disable=protected-access
|
||||||
|
|
||||||
_LOGGER.info("Connect to dbus: %s", bus_name)
|
_LOGGER.info("Connect to dbus: %s", bus_name)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def _init_proxy(self):
|
async def _init_proxy(self):
|
||||||
"""Read object data."""
|
"""Read object data."""
|
||||||
command = shlex.split(INTROSPECT.format(
|
command = shlex.split(INTROSPECT.format(
|
||||||
bus=self.bus_name,
|
bus=self.bus_name,
|
||||||
obj=self.object_path,
|
obj=self.object_path
|
||||||
))
|
))
|
||||||
|
|
||||||
# Ask data
|
# Ask data
|
||||||
try:
|
try:
|
||||||
data = await self._send(command)
|
data = await self._send(command)
|
||||||
except DBusError:
|
except DBusError:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Dbus fails connect to %s", self.object_path)
|
"DBus fails connect to %s", self.object_path)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# Parse XML
|
# Parse XML
|
||||||
xml = ET.fromstring(data)
|
xml = ET.fromstring(data)
|
||||||
for method in root.findall(".//method"):
|
for method in xml.findall(".//method"):
|
||||||
self.methods.append(method.get('name')
|
self.methods.append(method.get('name'))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _gvariant(raw):
|
def _gvariant(raw):
|
||||||
"""Parse GVariant input to python."""
|
"""Parse GVariant input to python."""
|
||||||
@ -82,7 +84,7 @@ class Dbus(object):
|
|||||||
data = await self._send(command)
|
data = await self._send(command)
|
||||||
except DBusError:
|
except DBusError:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Dbus fails with %s on %s", method, self.object_path)
|
"DBus fails with %s on %s", method, self.object_path)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# Parse and return data
|
# Parse and return data
|
||||||
@ -101,11 +103,12 @@ class Dbus(object):
|
|||||||
|
|
||||||
data, _ = await proc.communicate()
|
data, _ = await proc.communicate()
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
raise DbusFatalError() from None
|
_LOGGER.error("DBus fatal error: %s", err)
|
||||||
|
raise DBusFatalError() from None
|
||||||
|
|
||||||
# Success?
|
# Success?
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise DbusReturnError()
|
raise DBusReturnError()
|
||||||
|
|
||||||
# End
|
# End
|
||||||
return data.decode()
|
return data.decode()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user