mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-09 10:59:43 +00:00
* Update homeassistant.py * Update validate.py * Update exceptions.py * Update services.py * Update discovery.py * fix gitignore * Fix handling for discovery * use object in ref * lock down discovery API * fix api * Design * Fix API * fix lint * fix * Fix security layer * add provide layer * fix access * change rating * fix rights * Fix API error handling * raise error * fix rights * api * fix handling * fix * debug * debug json * Fix validator * fix error * new url * fix schema
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
"""Provide the MQTT Service."""
|
|
import logging
|
|
|
|
from .interface import ServiceInterface
|
|
from .validate import SCHEMA_SERVICE_MQTT
|
|
from ..const import ATTR_ADDON, SERVICE_MQTT
|
|
from ..exceptions import ServicesError
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
class MQTTService(ServiceInterface):
|
|
"""Provide MQTT services."""
|
|
|
|
@property
|
|
def slug(self):
|
|
"""Return slug of this service."""
|
|
return SERVICE_MQTT
|
|
|
|
@property
|
|
def _data(self):
|
|
"""Return data of this service."""
|
|
return self.sys_services.data.mqtt
|
|
|
|
@property
|
|
def schema(self):
|
|
"""Return data schema of this service."""
|
|
return SCHEMA_SERVICE_MQTT
|
|
|
|
def set_service_data(self, addon, data):
|
|
"""Write the data into service object."""
|
|
if self.enabled:
|
|
_LOGGER.error(
|
|
"It is already a MQTT in use from %s", self._data[ATTR_ADDON])
|
|
raise ServicesError()
|
|
|
|
self._data.update(data)
|
|
self._data[ATTR_ADDON] = addon.slug
|
|
|
|
_LOGGER.info("Set %s as service provider for mqtt", addon.slug)
|
|
self.save()
|
|
|
|
def del_service_data(self, addon):
|
|
"""Remove the data from service object."""
|
|
if not self.enabled:
|
|
_LOGGER.warning("Can't remove not exists services")
|
|
raise ServicesError()
|
|
|
|
self._data.clear()
|
|
self.save()
|