-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Optimistic MQTT light #14401
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
Merged
Merged
Optimistic MQTT light #14401
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
14e5535
Restores light state, case the light is optimistic
dgomes bd0a600
lint
dgomes 9ef26d6
hound
dgomes b26406f
hound
dgomes a8a5dfc
Added mqtt_json
dgomes 7d4bfc6
hound
dgomes 1dff4a1
added mqtt_template
dgomes 595944f
lint
dgomes fedf15e
cleanup
dgomes dd2a30d
use ATTR
dgomes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,15 +90,17 @@ | |
|
|
||
| import json | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| from homeassistant.setup import setup_component | ||
| from homeassistant.const import ( | ||
| STATE_ON, STATE_OFF, STATE_UNAVAILABLE, ATTR_ASSUMED_STATE, | ||
| ATTR_SUPPORTED_FEATURES) | ||
| import homeassistant.components.light as light | ||
| import homeassistant.core as ha | ||
| from tests.common import ( | ||
| get_test_home_assistant, mock_mqtt_component, fire_mqtt_message, | ||
| assert_setup_component) | ||
| assert_setup_component, mock_coro) | ||
|
|
||
|
|
||
| class TestLightMQTTJSON(unittest.TestCase): | ||
|
|
@@ -284,22 +286,35 @@ def test_controlling_state_via_topic(self): \ | |
| def test_sending_mqtt_commands_and_optimistic(self): \ | ||
| # pylint: disable=invalid-name | ||
| """Test the sending of command in optimistic mode.""" | ||
| assert setup_component(self.hass, light.DOMAIN, { | ||
| light.DOMAIN: { | ||
| 'platform': 'mqtt_json', | ||
| 'name': 'test', | ||
| 'command_topic': 'test_light_rgb/set', | ||
| 'brightness': True, | ||
| 'color_temp': True, | ||
| 'effect': True, | ||
| 'rgb': True, | ||
| 'white_value': True, | ||
| 'qos': 2 | ||
| } | ||
| }) | ||
| fake_state = ha.State('light.test', 'on', {'brightness': 95, | ||
| 'hs_color': [100, 100], | ||
| 'effect': 'random', | ||
| 'color_temp': 100, | ||
| 'white_value': 50}) | ||
|
|
||
| with patch('homeassistant.components.light.mqtt_json.async_get_last_state', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (83 > 79 characters) |
||
| return_value=mock_coro(fake_state)): | ||
| assert setup_component(self.hass, light.DOMAIN, { | ||
| light.DOMAIN: { | ||
| 'platform': 'mqtt_json', | ||
| 'name': 'test', | ||
| 'command_topic': 'test_light_rgb/set', | ||
| 'brightness': True, | ||
| 'color_temp': True, | ||
| 'effect': True, | ||
| 'rgb': True, | ||
| 'white_value': True, | ||
| 'qos': 2 | ||
| } | ||
| }) | ||
|
|
||
| state = self.hass.states.get('light.test') | ||
| self.assertEqual(STATE_OFF, state.state) | ||
| self.assertEqual(STATE_ON, state.state) | ||
| self.assertEqual(95, state.attributes.get('brightness')) | ||
| self.assertEqual((100, 100), state.attributes.get('hs_color')) | ||
| self.assertEqual('random', state.attributes.get('effect')) | ||
| self.assertEqual(100, state.attributes.get('color_temp')) | ||
| self.assertEqual(50, state.attributes.get('white_value')) | ||
| self.assertEqual(191, state.attributes.get(ATTR_SUPPORTED_FEATURES)) | ||
| self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE)) | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
ATTR_BRIGHTNESSfromlight/__init__.py. And on other places where a const which is defined inlight/__init__.pymake sense.