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

Optimistic MQTT light #14401

Merged
merged 10 commits into from
May 15, 2018
Merged

Optimistic MQTT light #14401

merged 10 commits into from
May 15, 2018

Conversation

dgomes
Copy link
Contributor

@dgomes dgomes commented May 11, 2018

Description:

This is a follow-up to #14151

When the light works in optimistic mode, HA is unaware of the current light state and always defaults to OFF on restart.

This pull request restores the state (and attributes) of the light to the last state, which is somehow what is expected from an optimistic light (that it has kept the state since the last restart and not defaulted to OFF)

Related issue (if applicable): fixes #

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>

Example entry for configuration.yaml (if applicable):

light:
  platform: mqtt
  name: "Office Light RGB"
  command_topic: "office/rgb1/light/switch"
  brightness_command_topic: "office/rgb1/brightness/set"
  rgb_command_topic: "office/rgb1/rgb/set"
  qos: 0
  payload_on: "on"
  payload_off: "off"

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

'white_value': 50})
print(fake_state)
with patch('homeassistant.components.light.mqtt.async_get_last_state',
return_value=mock_coro(fake_state)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

'color_temp': 100,
'white_value': 50})
with patch('homeassistant.components.light.mqtt.async_get_last_state',
return_value=mock_coro(fake_state)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

'color_temp': 100,
'white_value': 50})

with patch('homeassistant.components.light.mqtt_json.async_get_last_state',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (83 > 79 characters)

@fabaff fabaff changed the title Optimistic mqtt light Optimistic MQTT light May 12, 2018
self.hass, self._topic[CONF_BRIGHTNESS_STATE_TOPIC],
brightness_received, self._qos)
self._brightness = 255
elif self._optimistic_brightness and last_state\
and last_state.attributes.get('brightness'):
Copy link
Member

@fabaff fabaff May 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ATTR_BRIGHTNESS from light/__init__.py. And on other places where a const which is defined in light/__init__.py make sense.

@fabaff fabaff merged commit d47006c into home-assistant:dev May 15, 2018
@balloob balloob mentioned this pull request May 28, 2018
@dgomes dgomes mentioned this pull request May 28, 2018
3 tasks
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
* Restores light state, case the light is optimistic

* lint

* hound

* hound

* Added mqtt_json

* hound

* added mqtt_template

* lint

* cleanup

* use ATTR
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
@dgomes dgomes deleted the optimistic_mqtt_light branch April 7, 2022 18:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants