-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Deduplicate code in MQTT basic light #50530
Deduplicate code in MQTT basic light #50530
Conversation
def restore_state(attribute, condition): | ||
"""Restore a state attribute.""" | ||
if condition and last_state and last_state.attributes.get(attribute): | ||
setattr(self, f"_{attribute}", last_state.attributes.get(attribute)) |
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.
setattr(self, f"_{attribute}", last_state.attributes.get(attribute)) | |
setattr(self, f"_{attribute}", last_state.attributes[attribute]) |
if ( | ||
self._optimistic_rgb | ||
and last_state | ||
and last_state.attributes.get(ATTR_HS_COLOR) | ||
): | ||
self._hs = last_state.attributes.get(ATTR_HS_COLOR) | ||
self._hs_color = last_state.attributes.get(ATTR_HS_COLOR) |
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.
Why can't we use restore_state
helper here?
"qos": self._config[CONF_QOS], | ||
} | ||
add_topic(CONF_XY_STATE_TOPIC, xy_received) | ||
restore_state(ATTR_XY_COLOR, self._optimistic_xy) |
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.
What code did we replace with the restore helper here?
Proposed change
Deduplicate code in MQTT basic light
Replaced with 1 PR for each added helper:
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: