-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Restores switch state, case the switch is optimistic #14151
Conversation
If this PR gets through I will gladly update the mqtt platforms in the light component. |
self.entity_id) | ||
if last_state: | ||
self._state = last_state.state | ||
self.async_schedule_update_ha_state() |
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.
No need to schedule an update. We write the entity to the state machine right after this method is done.
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.
Ok to merge when a test is added.
self.hass, self._state_topic, state_message_received, | ||
self._qos) | ||
|
||
if self._optimistic: | ||
last_state = await async_get_last_state(self.hass, | ||
self.entity_id) |
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.
continuation line over-indented for visual indent
@@ -39,8 +39,7 @@ | |||
}).extend(mqtt.MQTT_AVAILABILITY_SCHEMA.schema) | |||
|
|||
|
|||
@asyncio.coroutine | |||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): | |||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): |
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.
line too long (85 > 79 characters)
Description:
When the switch works in optimistic mode, HA is unaware of the current switch state and always defaults to False on restart.
This pull request restores the state of the switch to the last state, which is somehow what is expected from an optimistic switch (that he has kept the state since the last restart and not defaulted to False)
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
. Your PR cannot be merged unless tests pass