mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-09 18:26:30 +00:00
update handling
This commit is contained in:
parent
f1237f124f
commit
0de3e9a233
@ -1,5 +1,6 @@
|
|||||||
"""Core Exceptions."""
|
"""Core Exceptions."""
|
||||||
|
|
||||||
|
|
||||||
class HassioError(Exception):
|
class HassioError(Exception):
|
||||||
"""Root exception."""
|
"""Root exception."""
|
||||||
pass
|
pass
|
||||||
@ -13,3 +14,25 @@ class HassioInternalError(HassioError):
|
|||||||
class HassioNotSupportedError(HassioError):
|
class HassioNotSupportedError(HassioError):
|
||||||
"""Function is not supported."""
|
"""Function is not supported."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# utils/gdbus
|
||||||
|
|
||||||
|
class DBusError(HassioError):
|
||||||
|
"""DBus generic error."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DBusFatalError(DBusError):
|
||||||
|
"""DBus call going wrong."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DBusReturnError(DBusError):
|
||||||
|
"""DBus return error."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DBusParseError(DBusError):
|
||||||
|
"""DBus parse error."""
|
||||||
|
pass
|
||||||
|
@ -4,6 +4,8 @@ import logging
|
|||||||
import shlex
|
import shlex
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
from ..exceptions import DBusFatalError, DBusReturnError, DBusParseError
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
INTROSPECT = ("gdbus introspect --system --dest {bus} "
|
INTROSPECT = ("gdbus introspect --system --dest {bus} "
|
||||||
@ -12,26 +14,6 @@ CALL = ("gdbus call --system --dest {bus} --object-path {inf} "
|
|||||||
"--method {inf}.{method} {args}")
|
"--method {inf}.{method} {args}")
|
||||||
|
|
||||||
|
|
||||||
class DBusError(Exception):
|
|
||||||
"""DBus generic error."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class DBusFatalError(DBusError):
|
|
||||||
"""DBus call going wrong."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class DBusReturnError(DBusError):
|
|
||||||
"""DBus return error."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class DBusParseError(DBusError):
|
|
||||||
"""DBus parse error."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class DBus(object):
|
class DBus(object):
|
||||||
"""DBus handler."""
|
"""DBus handler."""
|
||||||
|
|
||||||
@ -58,19 +40,15 @@ class DBus(object):
|
|||||||
))
|
))
|
||||||
|
|
||||||
# Ask data
|
# Ask data
|
||||||
try:
|
_LOGGER.info("Introspect %s no %s", self.bus_name, self.object_path)
|
||||||
data = await self._send(command)
|
data = await self._send(command)
|
||||||
except DBusError:
|
|
||||||
_LOGGER.error(
|
|
||||||
"DBus fails connect to %s", self.object_path)
|
|
||||||
raise
|
|
||||||
|
|
||||||
# Parse XML
|
# Parse XML
|
||||||
try:
|
try:
|
||||||
xml = ET.fromstring(data)
|
xml = ET.fromstring(data)
|
||||||
except ET.ParseError as err:
|
except ET.ParseError as err:
|
||||||
_LOGGER.error("Can't parse introspect data: %s", err)
|
raise DBusParseError(
|
||||||
raise DBusParseError() from None
|
f"Can't parse introspect data: {err!s}") from None
|
||||||
|
|
||||||
# Read available methods
|
# Read available methods
|
||||||
for interface in xml.findall("/node/interface"):
|
for interface in xml.findall("/node/interface"):
|
||||||
@ -94,12 +72,8 @@ class DBus(object):
|
|||||||
))
|
))
|
||||||
|
|
||||||
# Run command
|
# Run command
|
||||||
try:
|
_LOGGER.info("Call %s no %s", method, interface)
|
||||||
data = await self._send(command)
|
data = await self._send(command)
|
||||||
except DBusError:
|
|
||||||
_LOGGER.error(
|
|
||||||
"DBus fails with %s on %s", method, self.object_path)
|
|
||||||
raise
|
|
||||||
|
|
||||||
# Parse and return data
|
# Parse and return data
|
||||||
return self._gvariant(data)
|
return self._gvariant(data)
|
||||||
@ -117,12 +91,11 @@ class DBus(object):
|
|||||||
|
|
||||||
data, _ = await proc.communicate()
|
data, _ = await proc.communicate()
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
_LOGGER.error("DBus fatal error: %s", err)
|
raise DBusFatalError(f"DBus fatal error: {err!s}") from None
|
||||||
raise DBusFatalError() from None
|
|
||||||
|
|
||||||
# Success?
|
# Success?
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise DBusReturnError()
|
raise DBusReturnError(f"DBus return error: {data!s}")
|
||||||
|
|
||||||
# End
|
# End
|
||||||
return data.decode()
|
return data.decode()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user