diff --git a/homeassistant/components/mqtt/abbreviations.py b/homeassistant/components/mqtt/abbreviations.py index 4b310fb19ec..2ec0ea0d203 100644 --- a/homeassistant/components/mqtt/abbreviations.py +++ b/homeassistant/components/mqtt/abbreviations.py @@ -69,6 +69,8 @@ ABBREVIATIONS = { "json_attr": "json_attributes", "json_attr_t": "json_attributes_topic", "json_attr_tpl": "json_attributes_template", + "max_mirs": "max_mireds", + "min_mirs": "min_mireds", "max_temp": "max_temp", "min_temp": "min_temp", "mode_cmd_t": "mode_command_topic", diff --git a/homeassistant/components/mqtt/light/schema_basic.py b/homeassistant/components/mqtt/light/schema_basic.py index e3405a02c6e..375318764d1 100644 --- a/homeassistant/components/mqtt/light/schema_basic.py +++ b/homeassistant/components/mqtt/light/schema_basic.py @@ -71,6 +71,8 @@ CONF_EFFECT_VALUE_TEMPLATE = "effect_value_template" CONF_HS_COMMAND_TOPIC = "hs_command_topic" CONF_HS_STATE_TOPIC = "hs_state_topic" CONF_HS_VALUE_TEMPLATE = "hs_value_template" +CONF_MAX_MIREDS = "max_mireds" +CONF_MIN_MIREDS = "min_mireds" CONF_RGB_COMMAND_TEMPLATE = "rgb_command_template" CONF_RGB_COMMAND_TOPIC = "rgb_command_topic" CONF_RGB_STATE_TOPIC = "rgb_state_topic" @@ -116,6 +118,8 @@ PLATFORM_SCHEMA_BASIC = ( vol.Optional(CONF_HS_COMMAND_TOPIC): mqtt.valid_publish_topic, vol.Optional(CONF_HS_STATE_TOPIC): mqtt.valid_subscribe_topic, vol.Optional(CONF_HS_VALUE_TEMPLATE): cv.template, + vol.Optional(CONF_MAX_MIREDS): cv.positive_int, + vol.Optional(CONF_MIN_MIREDS): cv.positive_int, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_ON_COMMAND_TYPE, default=DEFAULT_ON_COMMAND_TYPE): vol.In( VALUES_ON_COMMAND_TYPE @@ -564,6 +568,16 @@ class MqttLight( """Return the color temperature in mired.""" return self._color_temp + @property + def min_mireds(self): + """Return the coldest color_temp that this light supports.""" + return self._config.get(CONF_MIN_MIREDS, super().min_mireds) + + @property + def max_mireds(self): + """Return the warmest color_temp that this light supports.""" + return self._config.get(CONF_MAX_MIREDS, super().max_mireds) + @property def white_value(self): """Return the white property.""" diff --git a/homeassistant/components/mqtt/light/schema_json.py b/homeassistant/components/mqtt/light/schema_json.py index 69bbab3970d..89ae0601fde 100644 --- a/homeassistant/components/mqtt/light/schema_json.py +++ b/homeassistant/components/mqtt/light/schema_json.py @@ -81,6 +81,9 @@ CONF_FLASH_TIME_LONG = "flash_time_long" CONF_FLASH_TIME_SHORT = "flash_time_short" CONF_HS = "hs" +CONF_MAX_MIREDS = "max_mireds" +CONF_MIN_MIREDS = "min_mireds" + # Stealing some of these from the base MQTT configs. PLATFORM_SCHEMA_JSON = ( mqtt.MQTT_RW_PLATFORM_SCHEMA.extend( @@ -100,6 +103,8 @@ PLATFORM_SCHEMA_JSON = ( CONF_FLASH_TIME_SHORT, default=DEFAULT_FLASH_TIME_SHORT ): cv.positive_int, vol.Optional(CONF_HS, default=DEFAULT_HS): cv.boolean, + vol.Optional(CONF_MAX_MIREDS): cv.positive_int, + vol.Optional(CONF_MIN_MIREDS): cv.positive_int, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_OPTIMISTIC, default=DEFAULT_OPTIMISTIC): cv.boolean, vol.Optional(CONF_QOS, default=mqtt.DEFAULT_QOS): vol.All( @@ -358,6 +363,16 @@ class MqttLightJson( """Return the color temperature in mired.""" return self._color_temp + @property + def min_mireds(self): + """Return the coldest color_temp that this light supports.""" + return self._config.get(CONF_MIN_MIREDS, super().min_mireds) + + @property + def max_mireds(self): + """Return the warmest color_temp that this light supports.""" + return self._config.get(CONF_MAX_MIREDS, super().max_mireds) + @property def effect(self): """Return the current effect.""" diff --git a/homeassistant/components/mqtt/light/schema_template.py b/homeassistant/components/mqtt/light/schema_template.py index fab6db4906f..a9f18e7039b 100644 --- a/homeassistant/components/mqtt/light/schema_template.py +++ b/homeassistant/components/mqtt/light/schema_template.py @@ -63,6 +63,8 @@ CONF_COMMAND_ON_TEMPLATE = "command_on_template" CONF_EFFECT_LIST = "effect_list" CONF_EFFECT_TEMPLATE = "effect_template" CONF_GREEN_TEMPLATE = "green_template" +CONF_MAX_MIREDS = "max_mireds" +CONF_MIN_MIREDS = "min_mireds" CONF_RED_TEMPLATE = "red_template" CONF_STATE_TEMPLATE = "state_template" CONF_WHITE_VALUE_TEMPLATE = "white_value_template" @@ -79,6 +81,8 @@ PLATFORM_SCHEMA_TEMPLATE = ( vol.Optional(CONF_EFFECT_LIST): vol.All(cv.ensure_list, [cv.string]), vol.Optional(CONF_EFFECT_TEMPLATE): cv.template, vol.Optional(CONF_GREEN_TEMPLATE): cv.template, + vol.Optional(CONF_MAX_MIREDS): cv.positive_int, + vol.Optional(CONF_MIN_MIREDS): cv.positive_int, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_OPTIMISTIC, default=DEFAULT_OPTIMISTIC): cv.boolean, vol.Optional(CONF_RED_TEMPLATE): cv.template, @@ -337,6 +341,16 @@ class MqttTemplate( """Return the color temperature in mired.""" return self._color_temp + @property + def min_mireds(self): + """Return the coldest color_temp that this light supports.""" + return self._config.get(CONF_MIN_MIREDS, super().min_mireds) + + @property + def max_mireds(self): + """Return the warmest color_temp that this light supports.""" + return self._config.get(CONF_MAX_MIREDS, super().max_mireds) + @property def hs_color(self): """Return the hs color value [int, int].""" diff --git a/tests/components/mqtt/test_light.py b/tests/components/mqtt/test_light.py index 9f5e65bd987..7cf034ec4e1 100644 --- a/tests/components/mqtt/test_light.py +++ b/tests/components/mqtt/test_light.py @@ -1483,3 +1483,22 @@ async def test_entity_debug_info_message(hass, mqtt_mock): await help_test_entity_debug_info_message( hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG ) + + +async def test_max_mireds(hass, mqtt_mock): + """Test setting min_mireds and max_mireds.""" + config = { + light.DOMAIN: { + "platform": "mqtt", + "name": "test", + "command_topic": "test_max_mireds/set", + "color_temp_command_topic": "test_max_mireds/color_temp/set", + "max_mireds": 370, + } + } + + assert await async_setup_component(hass, light.DOMAIN, config) + + state = hass.states.get("light.test") + assert state.attributes.get("min_mireds") == 153 + assert state.attributes.get("max_mireds") == 370 diff --git a/tests/components/mqtt/test_light_json.py b/tests/components/mqtt/test_light_json.py index 23c83dabde7..b98282b5288 100644 --- a/tests/components/mqtt/test_light_json.py +++ b/tests/components/mqtt/test_light_json.py @@ -1219,3 +1219,23 @@ async def test_entity_debug_info_message(hass, mqtt_mock): await help_test_entity_debug_info_message( hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG, payload='{"state":"ON"}' ) + + +async def test_max_mireds(hass, mqtt_mock): + """Test setting min_mireds and max_mireds.""" + config = { + light.DOMAIN: { + "platform": "mqtt", + "schema": "json", + "name": "test", + "command_topic": "test_max_mireds/set", + "color_temp": True, + "max_mireds": 370, + } + } + + assert await async_setup_component(hass, light.DOMAIN, config) + + state = hass.states.get("light.test") + assert state.attributes.get("min_mireds") == 153 + assert state.attributes.get("max_mireds") == 370 diff --git a/tests/components/mqtt/test_light_template.py b/tests/components/mqtt/test_light_template.py index 611ba07c3d6..edb7900e0da 100644 --- a/tests/components/mqtt/test_light_template.py +++ b/tests/components/mqtt/test_light_template.py @@ -976,3 +976,25 @@ async def test_entity_debug_info_message(hass, mqtt_mock): } } await help_test_entity_debug_info_message(hass, mqtt_mock, light.DOMAIN, config) + + +async def test_max_mireds(hass, mqtt_mock): + """Test setting min_mireds and max_mireds.""" + config = { + light.DOMAIN: { + "platform": "mqtt", + "schema": "template", + "name": "test", + "command_topic": "test_max_mireds/set", + "command_on_template": "on", + "command_off_template": "off", + "color_temp_template": "{{ value }}", + "max_mireds": 370, + } + } + + assert await async_setup_component(hass, light.DOMAIN, config) + + state = hass.states.get("light.test") + assert state.attributes.get("min_mireds") == 153 + assert state.attributes.get("max_mireds") == 370