Add unique_id to mqtt camera (#16569)
* Add unique_id to mqtt camera * Remove whitespaces * Add test for unique_id * Add blank line
This commit is contained in:
parent
3bfe9e757e
commit
a0a54dfd5b
2 changed files with 33 additions and 1 deletions
|
@ -19,12 +19,14 @@ from homeassistant.helpers import config_validation as cv
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_TOPIC = 'topic'
|
||||
CONF_UNIQUE_ID = 'unique_id'
|
||||
DEFAULT_NAME = 'MQTT Camera'
|
||||
|
||||
DEPENDENCIES = ['mqtt']
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_TOPIC): mqtt.valid_subscribe_topic,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string
|
||||
})
|
||||
|
||||
|
@ -38,6 +40,7 @@ def async_setup_platform(hass, config, async_add_entities,
|
|||
|
||||
async_add_entities([MqttCamera(
|
||||
config.get(CONF_NAME),
|
||||
config.get(CONF_UNIQUE_ID),
|
||||
config.get(CONF_TOPIC)
|
||||
)])
|
||||
|
||||
|
@ -45,11 +48,12 @@ def async_setup_platform(hass, config, async_add_entities,
|
|||
class MqttCamera(Camera):
|
||||
"""representation of a MQTT camera."""
|
||||
|
||||
def __init__(self, name, topic):
|
||||
def __init__(self, name, unique_id, topic):
|
||||
"""Initialize the MQTT Camera."""
|
||||
super().__init__()
|
||||
|
||||
self._name = name
|
||||
self._unique_id = unique_id
|
||||
self._topic = topic
|
||||
self._qos = 0
|
||||
self._last_image = None
|
||||
|
@ -64,6 +68,11 @@ class MqttCamera(Camera):
|
|||
"""Return the name of this camera."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique ID."""
|
||||
return self._unique_id
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
"""Subscribe MQTT events."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue