Add new config variable to MQTT light (#9304)
* Add new config variable to MQTT light * Address reviewer's issues: refactor template render part. * Update mqtt.py
This commit is contained in:
parent
788275da32
commit
9ade8002ac
2 changed files with 58 additions and 2 deletions
|
@ -123,6 +123,20 @@ light:
|
|||
payload_on: "on"
|
||||
payload_off: "off"
|
||||
|
||||
config for RGB Version with RGB command template:
|
||||
|
||||
light:
|
||||
platform: mqtt
|
||||
name: "Office Light RGB"
|
||||
state_topic: "office/rgb1/light/status"
|
||||
command_topic: "office/rgb1/light/switch"
|
||||
rgb_state_topic: "office/rgb1/rgb/status"
|
||||
rgb_command_topic: "office/rgb1/rgb/set"
|
||||
rgb_command_template: "{{ '#%02x%02x%02x' | format(red, green, blue)}}"
|
||||
qos: 0
|
||||
payload_on: "on"
|
||||
payload_off: "off"
|
||||
|
||||
"""
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
@ -512,6 +526,38 @@ class TestLightMQTT(unittest.TestCase):
|
|||
self.assertEqual(80, state.attributes['white_value'])
|
||||
self.assertEqual((0.123, 0.123), state.attributes['xy_color'])
|
||||
|
||||
def test_sending_mqtt_rgb_command_with_template(self):
|
||||
"""Test the sending of RGB command with template."""
|
||||
config = {light.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'command_topic': 'test_light_rgb/set',
|
||||
'rgb_command_topic': 'test_light_rgb/rgb/set',
|
||||
'rgb_command_template': '{{ "#%02x%02x%02x" | '
|
||||
'format(red, green, blue)}}',
|
||||
'payload_on': 'on',
|
||||
'payload_off': 'off',
|
||||
'qos': 0
|
||||
}}
|
||||
|
||||
with assert_setup_component(1, light.DOMAIN):
|
||||
assert setup_component(self.hass, light.DOMAIN, config)
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
||||
light.turn_on(self.hass, 'light.test', rgb_color=[255, 255, 255])
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.mock_publish().async_publish.assert_has_calls([
|
||||
mock.call('test_light_rgb/set', 'on', 0, False),
|
||||
mock.call('test_light_rgb/rgb/set', '#ffffff', 0, False),
|
||||
], any_order=True)
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual((255, 255, 255), state.attributes['rgb_color'])
|
||||
|
||||
def test_show_brightness_if_only_command_topic(self):
|
||||
"""Test the brightness if only a command topic is present."""
|
||||
config = {light.DOMAIN: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue