mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-17 14:16:29 +00:00
Add version endpoint (#718)
* Add version endpoint * Update API.md * Update const.py * Create version.py * Update __init__.py * Update security.py * Update version.py
This commit is contained in:
parent
f2a5512bbf
commit
61eefea358
14
API.md
14
API.md
@ -660,3 +660,17 @@ This service performs an auto discovery to Home-Assistant.
|
|||||||
```
|
```
|
||||||
|
|
||||||
- DEL `/services/mqtt`
|
- DEL `/services/mqtt`
|
||||||
|
|
||||||
|
### Misc
|
||||||
|
|
||||||
|
- GET `/version`
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"supervisor": "version",
|
||||||
|
"homeassistant": "version",
|
||||||
|
"hassos": "null|version",
|
||||||
|
"machine": "type",
|
||||||
|
"arch": "arch",
|
||||||
|
"channel": "stable|beta|dev"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
@ -14,6 +14,7 @@ from .proxy import APIProxy
|
|||||||
from .supervisor import APISupervisor
|
from .supervisor import APISupervisor
|
||||||
from .snapshots import APISnapshots
|
from .snapshots import APISnapshots
|
||||||
from .services import APIServices
|
from .services import APIServices
|
||||||
|
from .version import APIVersion
|
||||||
from .security import SecurityMiddleware
|
from .security import SecurityMiddleware
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ class RestAPI(CoreSysAttributes):
|
|||||||
self._register_snapshots()
|
self._register_snapshots()
|
||||||
self._register_discovery()
|
self._register_discovery()
|
||||||
self._register_services()
|
self._register_services()
|
||||||
|
self._register_version()
|
||||||
|
|
||||||
def _register_host(self):
|
def _register_host(self):
|
||||||
"""Register hostcontrol functions."""
|
"""Register hostcontrol functions."""
|
||||||
@ -90,6 +92,15 @@ class RestAPI(CoreSysAttributes):
|
|||||||
web.get('/hardware/audio', api_hardware.audio),
|
web.get('/hardware/audio', api_hardware.audio),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def _register_version(self):
|
||||||
|
"""Register version functions."""
|
||||||
|
api_version = APIVersion()
|
||||||
|
api_version.coresys = self.coresys
|
||||||
|
|
||||||
|
self.webapp.add_routes([
|
||||||
|
web.get('/version', api_version.info),
|
||||||
|
])
|
||||||
|
|
||||||
def _register_supervisor(self):
|
def _register_supervisor(self):
|
||||||
"""Register Supervisor functions."""
|
"""Register Supervisor functions."""
|
||||||
api_supervisor = APISupervisor()
|
api_supervisor = APISupervisor()
|
||||||
|
@ -34,6 +34,7 @@ NO_SECURITY_CHECK = re.compile(
|
|||||||
ADDONS_API_BYPASS = re.compile(
|
ADDONS_API_BYPASS = re.compile(
|
||||||
r"^(?:"
|
r"^(?:"
|
||||||
r"|/addons/self/(?!security)[^/]+)?"
|
r"|/addons/self/(?!security)[^/]+)?"
|
||||||
|
r"|/version"
|
||||||
r")$"
|
r")$"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
26
hassio/api/version.py
Normal file
26
hassio/api/version.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
"""Init file for Hass.io version RESTful API."""
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from .utils import api_process
|
||||||
|
from ..const import (
|
||||||
|
ATTR_HOMEASSISTANT, ATTR_SUPERVISOR, ATTR_MACHINE, ATTR_ARCH, ATTR_HASSOS,
|
||||||
|
ATTR_CHANNEL)
|
||||||
|
from ..coresys import CoreSysAttributes
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class APIVersion(CoreSysAttributes):
|
||||||
|
"""Handle RESTful API for version functions."""
|
||||||
|
|
||||||
|
@api_process
|
||||||
|
async def info(self, request):
|
||||||
|
"""Show version info."""
|
||||||
|
return {
|
||||||
|
ATTR_SUPERVISOR: self.sys_supervisor.version,
|
||||||
|
ATTR_HOMEASSISTANT: self.sys_homeassistant.version,
|
||||||
|
ATTR_HASSOS: self.sys_hassos.version,
|
||||||
|
ATTR_MACHINE: self.sys_machine,
|
||||||
|
ATTR_ARCH: self.sys_arch,
|
||||||
|
ATTR_CHANNEL: self.sys_channel,
|
||||||
|
}
|
@ -185,6 +185,7 @@ ATTR_FULL_ACCESS = 'full_access'
|
|||||||
ATTR_PROTECTED = 'protected'
|
ATTR_PROTECTED = 'protected'
|
||||||
ATTR_RATING = 'rating'
|
ATTR_RATING = 'rating'
|
||||||
ATTR_HASSIO_ROLE = 'hassio_role'
|
ATTR_HASSIO_ROLE = 'hassio_role'
|
||||||
|
ATTR_SUPERVISOR = 'supervisor'
|
||||||
|
|
||||||
SERVICE_MQTT = 'mqtt'
|
SERVICE_MQTT = 'mqtt'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user