Add OS attribute for hostcontrol (#16)

* Add OS attribute for hostcontrol

* fix lint
This commit is contained in:
Pascal Vizeli 2017-04-26 22:14:58 +02:00 committed by GitHub
parent 139cf4fae4
commit aad9ae6997
4 changed files with 8 additions and 2 deletions

1
API.md
View File

@ -82,6 +82,7 @@ See HostControl info command.
"last_version": "", "last_version": "",
"features": ["shutdown", "reboot", "update", "network_info", "network_control"], "features": ["shutdown", "reboot", "update", "network_info", "network_control"],
"hostname": "", "hostname": "",
"os": ""
} }
``` ```

View File

@ -5,7 +5,8 @@ import voluptuous as vol
from .util import api_process_hostcontrol, api_process, api_validate from .util import api_process_hostcontrol, api_process, api_validate
from ..const import ( from ..const import (
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_TYPE, ATTR_HOSTNAME, ATTR_FEATURES) ATTR_VERSION, ATTR_LAST_VERSION, ATTR_TYPE, ATTR_HOSTNAME, ATTR_FEATURES,
ATTR_OS)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -32,6 +33,7 @@ class APIHost(object):
ATTR_LAST_VERSION: self.host_control.last, ATTR_LAST_VERSION: self.host_control.last,
ATTR_FEATURES: self.host_control.features, ATTR_FEATURES: self.host_control.features,
ATTR_HOSTNAME: self.host_control.hostname, ATTR_HOSTNAME: self.host_control.hostname,
ATTR_OS: self.host_control.os_info,
} }
@api_process_hostcontrol @api_process_hostcontrol

View File

@ -32,6 +32,7 @@ RESULT_ERROR = 'error'
RESULT_OK = 'ok' RESULT_OK = 'ok'
ATTR_HOSTNAME = 'hostname' ATTR_HOSTNAME = 'hostname'
ATTR_OS = 'os'
ATTR_TYPE = 'type' ATTR_TYPE = 'type'
ATTR_FEATURES = 'features' ATTR_FEATURES = 'features'
ATTR_ADDONS = 'addons' ATTR_ADDONS = 'addons'

View File

@ -9,7 +9,7 @@ import async_timeout
from .const import ( from .const import (
SOCKET_HC, ATTR_LAST_VERSION, ATTR_VERSION, ATTR_TYPE, ATTR_FEATURES, SOCKET_HC, ATTR_LAST_VERSION, ATTR_VERSION, ATTR_TYPE, ATTR_FEATURES,
ATTR_HOSTNAME) ATTR_HOSTNAME, ATTR_OS)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -35,6 +35,7 @@ class HostControl(object):
self.type = UNKNOWN self.type = UNKNOWN
self.features = [] self.features = []
self.hostname = UNKNOWN self.hostname = UNKNOWN
self.os_info = UNKNOWN
mode = os.stat(SOCKET_HC)[stat.ST_MODE] mode = os.stat(SOCKET_HC)[stat.ST_MODE]
if stat.S_ISSOCK(mode): if stat.S_ISSOCK(mode):
@ -94,6 +95,7 @@ class HostControl(object):
self.type = info.get(ATTR_TYPE, UNKNOWN) self.type = info.get(ATTR_TYPE, UNKNOWN)
self.features = info.get(ATTR_FEATURES, []) self.features = info.get(ATTR_FEATURES, [])
self.hostname = info.get(ATTR_HOSTNAME, UNKNOWN) self.hostname = info.get(ATTR_HOSTNAME, UNKNOWN)
self.os_info = info.get(ATTR_OS, UNKNOWN)
def reboot(self): def reboot(self):
"""Reboot the host system. """Reboot the host system.