Compare commits

...

5 Commits
132 ... 133

Author SHA1 Message Date
Pascal Vizeli
8beb723cc2 Merge pull request #736 from home-assistant/dev
Release 133
2018-10-01 19:07:17 +02:00
Pascal Vizeli
94fd24c251 Bugfix message handling (#735) 2018-10-01 18:57:31 +02:00
Pascal Vizeli
bf75a8a439 Cleanup discovery data (#734)
* Cleanup discovery data

* Update API.md

* Update validate.py

* Update discovery.py

* Update const.py
2018-10-01 16:17:46 +02:00
Pascal Vizeli
36cdb05387 Don't allow add-on to update itself (#733) 2018-10-01 15:22:26 +02:00
Pascal Vizeli
dccc652d42 Bump version 133 2018-09-30 20:16:42 +02:00
6 changed files with 15 additions and 32 deletions

10
API.md
View File

@@ -574,7 +574,7 @@ Write data to add-on stdin
}
```
### Service discovery
### discovery
- GET `/discovery`
```json
@@ -584,8 +584,6 @@ Write data to add-on stdin
"addon": "slug",
"service": "name",
"uuid": "uuid",
"component": "component",
"platform": "null|platform",
"config": {}
}
]
@@ -598,8 +596,6 @@ Write data to add-on stdin
"addon": "slug",
"service": "name",
"uuid": "uuid",
"component": "component",
"platform": "null|platform",
"config": {}
}
```
@@ -608,8 +604,6 @@ Write data to add-on stdin
```json
{
"service": "name",
"component": "component",
"platform": "null|platform",
"config": {}
}
```
@@ -623,6 +617,8 @@ return:
- DEL `/discovery/{UUID}`
### Services
- GET `/services`
```json
{

View File

@@ -3,8 +3,8 @@ import voluptuous as vol
from .utils import api_process, api_validate
from ..const import (
ATTR_ADDON, ATTR_UUID, ATTR_COMPONENT, ATTR_PLATFORM, ATTR_CONFIG,
ATTR_DISCOVERY, ATTR_SERVICE, REQUEST_FROM)
ATTR_ADDON, ATTR_UUID, ATTR_CONFIG, ATTR_DISCOVERY, ATTR_SERVICE,
REQUEST_FROM)
from ..coresys import CoreSysAttributes
from ..exceptions import APIError, APIForbidden
from ..validate import SERVICE_ALL
@@ -12,8 +12,6 @@ from ..validate import SERVICE_ALL
SCHEMA_DISCOVERY = vol.Schema({
vol.Required(ATTR_SERVICE): SERVICE_ALL,
vol.Required(ATTR_COMPONENT): vol.Coerce(str),
vol.Optional(ATTR_PLATFORM): vol.Maybe(vol.Coerce(str)),
vol.Optional(ATTR_CONFIG): vol.Maybe(dict),
})
@@ -44,8 +42,6 @@ class APIDiscovery(CoreSysAttributes):
ATTR_ADDON: message.addon,
ATTR_SERVICE: message.service,
ATTR_UUID: message.uuid,
ATTR_COMPONENT: message.component,
ATTR_PLATFORM: message.platform,
ATTR_CONFIG: message.config,
})
@@ -78,8 +74,6 @@ class APIDiscovery(CoreSysAttributes):
ATTR_ADDON: message.addon,
ATTR_SERVICE: message.service,
ATTR_UUID: message.uuid,
ATTR_COMPONENT: message.component,
ATTR_PLATFORM: message.platform,
ATTR_CONFIG: message.config,
}

View File

@@ -32,7 +32,7 @@ NO_SECURITY_CHECK = re.compile(
# Can called by every add-on
ADDONS_API_BYPASS = re.compile(
r"^(?:"
r"|/addons/self/(?!security)[^/]+"
r"|/addons/self/(?!security|update)[^/]+"
r"|/version"
r"|/services.*"
r"|/discovery.*"

View File

@@ -2,7 +2,7 @@
from pathlib import Path
from ipaddress import ip_network
HASSIO_VERSION = '132'
HASSIO_VERSION = '133'
URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons"
URL_HASSIO_VERSION = \
@@ -160,8 +160,6 @@ ATTR_HOST = 'host'
ATTR_USERNAME = 'username'
ATTR_PROTOCOL = 'protocol'
ATTR_DISCOVERY = 'discovery'
ATTR_PLATFORM = 'platform'
ATTR_COMPONENT = 'component'
ATTR_CONFIG = 'config'
ATTR_SERVICES = 'services'
ATTR_SERVICE = 'service'

View File

@@ -57,7 +57,7 @@ class Discovery(CoreSysAttributes, JsonConfig):
"""Return list of available discovery messages."""
return list(self.message_obj.values())
def send(self, addon, service, component, platform, config):
def send(self, addon, service, config):
"""Send a discovery message to Home Assistant."""
try:
DISCOVERY_SERVICES[service](config)
@@ -67,7 +67,7 @@ class Discovery(CoreSysAttributes, JsonConfig):
raise DiscoveryError() from None
# Create message
message = Message(addon.slug, service, component, platform, config)
message = Message(addon.slug, service, config)
# Already exists?
for old_message in self.list_messages:
@@ -76,8 +76,8 @@ class Discovery(CoreSysAttributes, JsonConfig):
_LOGGER.warning("Duplicate discovery message from %s", addon.slug)
return old_message
_LOGGER.info("Send discovery to Home Assistant %s/%s from %s",
component, platform, addon.slug)
_LOGGER.info("Send discovery to Home Assistant %s from %s",
service, addon.slug)
self.message_obj[message.uuid] = message
self.save()
@@ -89,8 +89,8 @@ class Discovery(CoreSysAttributes, JsonConfig):
self.message_obj.pop(message.uuid, None)
self.save()
_LOGGER.info("Delete discovery to Home Assistant %s/%s from %s",
message.component, message.platform, message.addon)
_LOGGER.info("Delete discovery to Home Assistant %s from %s",
message.service, message.addon)
self.sys_create_task(self._push_discovery(message, CMD_DEL))
async def _push_discovery(self, message, command):
@@ -115,9 +115,7 @@ class Discovery(CoreSysAttributes, JsonConfig):
@attr.s
class Message:
"""Represent a single Discovery message."""
uuid = attr.ib(factory=lambda: uuid4().hex, cmp=False, init=False)
addon = attr.ib()
service = attr.ib()
component = attr.ib()
platform = attr.ib()
config = attr.ib(cmp=False)
uuid = attr.ib(factory=lambda: uuid4().hex, cmp=False)

View File

@@ -9,8 +9,7 @@ from .const import (
ATTR_ADDONS_CUSTOM_LIST, ATTR_PASSWORD, ATTR_HOMEASSISTANT, ATTR_HASSIO,
ATTR_BOOT, ATTR_LAST_BOOT, ATTR_SSL, ATTR_PORT, ATTR_WATCHDOG, ATTR_CONFIG,
ATTR_WAIT_BOOT, ATTR_UUID, ATTR_REFRESH_TOKEN, ATTR_HASSOS_CLI,
ATTR_ACCESS_TOKEN, ATTR_DISCOVERY, ATTR_ADDON, ATTR_COMPONENT,
ATTR_PLATFORM, ATTR_SERVICE,
ATTR_ACCESS_TOKEN, ATTR_DISCOVERY, ATTR_ADDON, ATTR_SERVICE,
SERVICE_MQTT,
CHANNEL_STABLE, CHANNEL_BETA, CHANNEL_DEV)
from .utils.validate import schema_or, validate_timezone
@@ -114,8 +113,6 @@ SCHEMA_DISCOVERY = vol.Schema([
vol.Required(ATTR_UUID): UUID_MATCH,
vol.Required(ATTR_ADDON): vol.Coerce(str),
vol.Required(ATTR_SERVICE): SERVICE_ALL,
vol.Required(ATTR_COMPONENT): vol.Coerce(str),
vol.Required(ATTR_PLATFORM): vol.Maybe(vol.Coerce(str)),
vol.Required(ATTR_CONFIG): vol.Maybe(dict),
}, extra=vol.REMOVE_EXTRA)
])