Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique_id to mqtt_json light #16721

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions homeassistant/components/light/mqtt_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
CONF_FLASH_TIME_LONG = 'flash_time_long'
CONF_FLASH_TIME_SHORT = 'flash_time_short'
CONF_HS = 'hs'
CONF_UNIQUE_ID = 'unique_id'

# Stealing some of these from the base MQTT configs.
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand All @@ -67,6 +68,7 @@
vol.Optional(CONF_FLASH_TIME_LONG, default=DEFAULT_FLASH_TIME_LONG):
cv.positive_int,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_UNIQUE_ID): cv.string,
vol.Optional(CONF_OPTIMISTIC, default=DEFAULT_OPTIMISTIC): cv.boolean,
vol.Optional(CONF_QOS, default=mqtt.DEFAULT_QOS):
vol.All(vol.Coerce(int), vol.In([0, 1, 2])),
Expand All @@ -87,6 +89,7 @@ async def async_setup_platform(hass: HomeAssistantType, config: ConfigType,
config = PLATFORM_SCHEMA(discovery_info)
async_add_entities([MqttJson(
config.get(CONF_NAME),
config.get(CONF_UNIQUE_ID),
config.get(CONF_EFFECT_LIST),
{
key: config.get(key) for key in (
Expand Down Expand Up @@ -120,14 +123,15 @@ async def async_setup_platform(hass: HomeAssistantType, config: ConfigType,
class MqttJson(MqttAvailability, Light):
"""Representation of a MQTT JSON light."""

def __init__(self, name, effect_list, topic, qos, retain, optimistic,
brightness, color_temp, effect, rgb, white_value, xy, hs,
flash_times, availability_topic, payload_available,
def __init__(self, name, unique_id, effect_list, topic, qos, retain,
optimistic, brightness, color_temp, effect, rgb, white_value,
xy, hs, flash_times, availability_topic, payload_available,
payload_not_available, brightness_scale):
"""Initialize MQTT JSON light."""
super().__init__(availability_topic, qos, payload_available,
payload_not_available)
self._name = name
self._unique_id = unique_id
self._effect_list = effect_list
self._topic = topic
self._qos = qos
Expand Down Expand Up @@ -316,6 +320,11 @@ def name(self):
"""Return the name of the device if any."""
return self._name

@property
def unique_id(self):
"""Return a unique ID."""
return self._unique_id

@property
def is_on(self):
"""Return true if device is on."""
Expand Down