mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-27 02:56:31 +00:00
Fix charset and timeout handling for HostControll
This commit is contained in:
parent
00dd19c292
commit
4fb2a88e1e
@ -9,6 +9,8 @@ from .const import SOCKET_HC
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
TIMEOUT = 15
|
||||||
|
|
||||||
|
|
||||||
class HostControll(object):
|
class HostControll(object):
|
||||||
"""Client for host controll."""
|
"""Client for host controll."""
|
||||||
@ -33,11 +35,13 @@ class HostControll(object):
|
|||||||
reader, writer = await asyncio.open_unix_connection(
|
reader, writer = await asyncio.open_unix_connection(
|
||||||
SOCKET_HC, loop=self.loop)
|
SOCKET_HC, loop=self.loop)
|
||||||
|
|
||||||
|
try:
|
||||||
# send
|
# send
|
||||||
_LOGGER.info("Send '%s' to HostControll.", command)
|
_LOGGER.info("Send '%s' to HostControll.", command)
|
||||||
writer.write(command.encode())
|
writer.write("{}\n".format(command).encode())
|
||||||
|
|
||||||
# receive
|
# receive
|
||||||
|
with async_timeout.timeout(TIMEOUT, loop=self.loop):
|
||||||
data = await reader.readline()
|
data = await reader.readline()
|
||||||
response = data.decode().Upper()
|
response = data.decode().Upper()
|
||||||
_LOGGER.info("Receive from HostControll: %s.", response)
|
_LOGGER.info("Receive from HostControll: %s.", response)
|
||||||
@ -49,6 +53,12 @@ class HostControll(object):
|
|||||||
else:
|
else:
|
||||||
return json.loads(response)
|
return json.loads(response)
|
||||||
|
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
_LOGGER.error("Timeout from HostControll!")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
writer.close()
|
||||||
|
|
||||||
def info(self):
|
def info(self):
|
||||||
"""Return Info from host.
|
"""Return Info from host.
|
||||||
|
|
||||||
@ -76,7 +86,7 @@ class HostControll(object):
|
|||||||
Return a coroutine.
|
Return a coroutine.
|
||||||
"""
|
"""
|
||||||
if version:
|
if version:
|
||||||
return self._send_command("host-update " + version)
|
return self._send_command("host-update {}".format(version))
|
||||||
return self._send_command("host-update")
|
return self._send_command("host-update")
|
||||||
|
|
||||||
def supervisor_update(self, version=None):
|
def supervisor_update(self, version=None):
|
||||||
@ -85,5 +95,5 @@ class HostControll(object):
|
|||||||
Return a coroutine.
|
Return a coroutine.
|
||||||
"""
|
"""
|
||||||
if version:
|
if version:
|
||||||
return self._send_command("supervisor-update " + version)
|
return self._send_command("supervisor-update {}".format(version))
|
||||||
return self._send_command("supervisor-update")
|
return self._send_command("supervisor-update")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user